List of usage examples for org.springframework.util CollectionUtils arrayToList
@SuppressWarnings("rawtypes") public static List arrayToList(@Nullable Object source)
From source file:com.frank.search.solr.core.mapping.SimpleSolrPersistentProperty.java
@SuppressWarnings("unchecked") @Override//from w w w . j a v a2 s.c o m public Collection<String> getCopyFields() { Indexed indexedAnnotation = getIndexAnnotation(); if (indexedAnnotation != null) { if (indexedAnnotation.copyTo().length > 0) { return CollectionUtils.arrayToList(indexedAnnotation.copyTo()); } } return Collections.emptyList(); }
From source file:uk.gov.nationalarchives.discovery.taxonomy.common.service.impl.EvaluationServiceImpl.java
@Override public EvaluationReport getEvaluationReport(String comments) { logger.info(".getEvaluationReport > START"); Map<String, Integer> mapOfTruePositivesPerCat = new HashMap<String, Integer>(); Map<String, Integer> mapOfFalsePositivesPerCat = new HashMap<String, Integer>(); Map<String, Integer> mapOfFalseNegativesPerCat = new HashMap<String, Integer>(); long numberOfDocuments = testDocumentRepository.count(); for (TestDocument testDocument : testDocumentRepository.findAll()) { List<String> categories = CollectionUtils.arrayToList(testDocument.getCategories()); List<String> legacyCategories = CollectionUtils.arrayToList(testDocument.getLegacyCategories()); for (String category : categories) { if (legacyCategories.contains(category)) { incrementMapValueForCategory(mapOfTruePositivesPerCat, category); } else { incrementMapValueForCategory(mapOfFalsePositivesPerCat, category); }/*from w w w. j a va2 s . com*/ } for (String legacyCategory : legacyCategories) { if (!categories.contains(legacyCategory)) { incrementMapValueForCategory(mapOfFalseNegativesPerCat, legacyCategory); } } } Set<String> setOfCategories = new HashSet<String>(); setOfCategories.addAll(mapOfTruePositivesPerCat.keySet()); setOfCategories.addAll(mapOfFalsePositivesPerCat.keySet()); setOfCategories.addAll(mapOfFalseNegativesPerCat.keySet()); List<CategoryEvaluationResult> listOfEvaluationResults = new ArrayList<CategoryEvaluationResult>(); for (String category : setOfCategories) { Integer tp = mapOfTruePositivesPerCat.get(category); Integer fp = mapOfFalsePositivesPerCat.get(category); Integer fn = mapOfFalseNegativesPerCat.get(category); listOfEvaluationResults .add(new CategoryEvaluationResult(category, tp != null ? tp : 0, fp != null ? fp : 0, fn != null ? fn : 0, categoryRepository.findByTtl(category) != null ? true : false)); } for (Category category : categoryRepository.findAll()) { String categoryName = category.getTtl(); if (!setOfCategories.contains(categoryName)) { listOfEvaluationResults.add(new CategoryEvaluationResult(categoryName, true, false, false)); } } EvaluationReport report = new EvaluationReport(comments, listOfEvaluationResults, (int) numberOfDocuments); evaluationReportRepository.save(report); logger.info(".getEvaluationReport < END"); return report; }
From source file:de.eimb.testlink.synchronize.citrus.mvn.plugin.CreateTestCasesFromTestLink.java
/** * DOCUMENT ME!//from w w w. j a v a 2s .co m * * @param bean * DOCUMENT ME! * * @throws PrompterException * DOCUMENT ME! */ private void promptForVariables(final CitrusBean bean) throws PrompterException { final StringBuilder promptFirst = new StringBuilder("\n\nEdit variables for test: "); promptFirst.append(bean.getName()); promptFirst.append("\nEnter success text:"); final String notesSuccess = this.prompter.prompt(promptFirst.toString(), bean.getVariables().get(CitrusTestLinkEnum.NotesSuccess.getKey())); final String notesFailure = this.prompter.prompt("Enter failure text:", bean.getVariables().get(CitrusTestLinkEnum.NotesFailure.getKey())); final String platform = this.prompter.prompt("Choose platform", bean.getTestLink().getPlatformList(), bean.getVariables().get(CitrusTestLinkEnum.TestCasePlatform.getKey())); // ask for confirmation StringBuilder builder = new StringBuilder("\nVariables:"); builder.append("\nSuccess notes: "); builder.append(notesSuccess); builder.append("\nFailure notes: "); builder.append(notesFailure); builder.append("\nPlatform: "); builder.append(platform); builder.append("\n\nConfirm variables: "); final String confirm = this.prompter.prompt(builder.toString(), CollectionUtils.arrayToList(new String[] { "y", "n" }), "y"); // check for confirmation if ("y".equalsIgnoreCase(confirm)) { // replace values with new values bean.getVariables().put(CitrusTestLinkEnum.NotesSuccess.getKey(), notesSuccess); bean.getVariables().put(CitrusTestLinkEnum.NotesFailure.getKey(), notesFailure); bean.getVariables().put(CitrusTestLinkEnum.TestCasePlatform.getKey(), platform); } }
From source file:com.consol.citrus.mvn.plugin.CreateTestMojo.java
/** * Creates test case with request and response messages from XML schema. * @param creator//from w w w .j a va2 s . c o m * @throws MojoExecutionException */ public void createWithXsd(TestCaseCreator creator) throws MojoExecutionException { try { String xsd = this.xsd; while (interactiveMode && !StringUtils.hasText(xsd)) { xsd = prompter.prompt("Enter path to XSD", this.xsd); } // compile xsd already here, otherwise later input is useless: SchemaTypeSystem sts = compileXsd(xsd); SchemaType[] globalElems = sts.documentTypes(); SchemaType requestElem = null; SchemaType responseElem = null; String xsdRequestMessage = this.xsdRequestMessage; String xsdResponseMessage = this.xsdResponseMessage; if (interactiveMode) { xsdRequestMessage = prompter.prompt("Enter request element name", this.xsdRequestMessage); // try to guess the response-element and the testname from the request: String xsdResponseMessageSuggestion = xsdResponseMessage; if (xsdRequestMessage.endsWith("Req")) { xsdResponseMessageSuggestion = xsdRequestMessage.substring(0, xsdRequestMessage.indexOf("Req")) + "Res"; creator.withName(xsdRequestMessage.substring(0, xsdRequestMessage.indexOf("Req")) + "Test"); } else if (xsdRequestMessage.endsWith("Request")) { xsdResponseMessageSuggestion = xsdRequestMessage.substring(0, xsdRequestMessage.indexOf("Request")) + "Response"; creator.withName(xsdRequestMessage.substring(0, xsdRequestMessage.indexOf("Request")) + "Test"); } else if (xsdRequestMessage.endsWith("RequestMessage")) { xsdResponseMessageSuggestion = xsdRequestMessage.substring(0, xsdRequestMessage.indexOf("RequestMessage")) + "ResponseMessage"; creator.withName( xsdRequestMessage.substring(0, xsdRequestMessage.indexOf("RequestMessage")) + "Test"); } xsdResponseMessage = prompter.prompt("Enter response element name", xsdResponseMessageSuggestion); } if (interactiveMode) { String confirm = prompter.prompt( "Confirm test creation:\n" + "framework: " + creator.getFramework() + "\n" + "name: " + creator.getName() + "\n" + "author: " + creator.getAuthor() + "\n" + "description: " + creator.getDescription() + "\n" + "package: " + creator.getTargetPackage() + "\n", CollectionUtils.arrayToList(new String[] { "y", "n" }), "y"); if (confirm.equalsIgnoreCase("n")) { return; } } for (SchemaType elem : globalElems) { if (elem.getContentModel().getName().getLocalPart().equals(xsdRequestMessage)) { requestElem = elem; break; } } for (SchemaType elem : globalElems) { if (elem.getContentModel().getName().getLocalPart().equals(xsdResponseMessage)) { responseElem = elem; break; } } // Now generate it creator.withXmlRequest(SampleXmlUtil.createSampleForType(requestElem)) .withXmlResponse(SampleXmlUtil.createSampleForType(responseElem)); creator.createTestCase(); getLog().info( "Successfully created new test case " + creator.getTargetPackage() + "." + creator.getName()); } catch (ArrayIndexOutOfBoundsException e) { getLog().info( "Wrong parameter usage! See citrus:help for usage details (mvn citrus:help -Ddetail=true -Dgoal=create-test-from-xsd)."); } catch (PrompterException e) { getLog().info(e); getLog().info( "Failed to create test! See citrus:help for usage details (mvn citrus:help -Ddetail=true -Dgoal=create-test-from-xsd)."); } catch (IOException e) { getLog().info(e); } }
From source file:com.fortify.processrunner.cli.CLIOptionDefinition.java
public String getValue(Context context) { String result = getValueFromContext(context); if (StringUtils.isBlank(result)) { result = getDefaultValue();//from ww w . j a va 2s . com context.put(getName(), result); } if (StringUtils.isBlank(result) && isRequiredAndNotIgnored(context)) { // TODO Clean this up @SuppressWarnings("unchecked") List<String> optionNames = new ArrayList<String>( CollectionUtils.arrayToList(getIsAlternativeForOptions())); optionNames.add(getName()); throw new IllegalArgumentException( "Required CLI option " + StringUtils.join(optionNames, " or ") + " not defined"); } if (StringUtils.isNotBlank(result) && allowedValues != null && !allowedValues.containsKey(result)) { throw new IllegalArgumentException( "CLI option value " + result + " not allowed for option " + getName()); } return result; }
From source file:com.bstek.dorado.data.entity.EntityUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> T toEntity(Object object, DataType dataType) throws Exception { if (isSimpleValue(object)) { return (T) object; }/*w w w. j a v a 2 s . co m*/ // Expression if (object instanceof Expression) { object = ((Expression) object).evaluate(); } Class<?> cl = object.getClass(); if (object instanceof Collection) { Collection<?> entities = (Collection<?>) object; if (entities instanceof EntityCollection<?>) { DataType currentDataType = getDataType(entities); if (currentDataType != dataType && dataType != null) { ((EntityCollection<?>) entities).setDataType((AggregationDataType) dataType); } return (T) object; } } else { EntityEnhancer entityEnhancer = getEntityEnhancer(object); if (entityEnhancer != null) { DataType currentDataType = entityEnhancer.getDataType(); if (currentDataType != dataType && dataType != null) { entityEnhancer.setDataType((EntityDataType) dataType); } return (T) object; } } boolean useProxy = true; if (dataType == null) { dataType = getDataType(cl); } if (dataType != null) { Class<?> matchType = dataType.getMatchType(); if (matchType != null) { boolean matching = false; if (matchType.isPrimitive()) { matching = ClassUtils.primitiveToWrapper(matchType).equals(cl); } else { matching = matchType.isAssignableFrom(cl); } if (!matching) { if (dataType instanceof EntityDataType) { DataType realDataType = getDataType(cl); if (realDataType instanceof EntityDataType) { matching = true; useProxy = false; } } else if (dataType instanceof AggregationDataType) { DataType realDataType = getDataType(cl); if (realDataType instanceof AggregationDataType) { matching = true; } } if (!matching) { throw new IllegalArgumentException( "Result type mismatch. expect [" + matchType + "] but [" + cl + "]."); } } } } if (object instanceof Collection) { // Collection??? AggregationDataType AggregationDataType = (AggregationDataType) dataType; if (object instanceof List) { object = new EntityList((List) object, AggregationDataType); } else if (object instanceof Set) { object = new EntitySet((Set) object, AggregationDataType); } else { throw new IllegalArgumentException("Unsupported result type [" + cl.getName() + "]."); } } else if (object.getClass().isArray()) { Class type = object.getClass(); if (isSimpleType(type.getComponentType())) { return (T) object; } else { // ??java.util.List logger.warn("Dorado converted a " + object.getClass() + " to " + List.class + " automatically."); List list = CollectionUtils.arrayToList(object); object = new EntityList(list, (AggregationDataType) dataType); } } else { // TODO Entity???? // Entity??? EntityDataType entityDataType = (EntityDataType) dataType; if (!(entityDataType instanceof CustomEntityDataType)) { if (useProxy) { // ???? if (object instanceof EnhanceableEntity) { EnhanceableEntity enhanceableEntity = (EnhanceableEntity) object; if (enhanceableEntity.getEntityEnhancer() == null) { EntityEnhancer entityEnhancer; if (object instanceof Map) { entityEnhancer = new EnhanceableMapEntityEnhancer(entityDataType); } else { entityEnhancer = new EnhanceableBeanEntityEnhancer(entityDataType, object.getClass()); } enhanceableEntity.setEntityEnhancer(entityEnhancer); } return (T) object; } else { MethodInterceptor[] mis = getMethodInterceptorFactory().createInterceptors(entityDataType, object.getClass(), object); object = ProxyBeanUtils.proxyBean(object, mis); } } else { // ???? Class<?> creationType = entityDataType.getCreationType(); if (creationType == null) { creationType = entityDataType.getMatchType(); } Map map; if (object instanceof Map) { map = (Map) object; } else { map = BeanMap.create(object); } if (creationType == null) { Record record = new Record(map); record.setEntityEnhancer(new EnhanceableMapEntityEnhancer(entityDataType)); object = record; } else { MethodInterceptor[] mis = getMethodInterceptorFactory().createInterceptors(entityDataType, creationType, null); object = ProxyBeanUtils.createBean(creationType, mis); setValues(object, map); } } } else { object = ((CustomEntityDataType) entityDataType).toMap(object); } } return (T) object; }
From source file:com.frank.search.solr.core.convert.MappingSolrConverter.java
private static Collection<?> asCollection(Object source) { if (source instanceof Collection) { return (Collection<?>) source; }/*from ww w . jav a2 s . c om*/ return source.getClass().isArray() ? CollectionUtils.arrayToList(source) : Collections.singleton(source); }
From source file:org.dkpro.similarity.experiments.rte.util.Evaluator.java
@SuppressWarnings("unchecked") public static void runEvaluationMetric(EvaluationMetric metric, Dataset dataset) throws IOException { // Get all subdirectories (i.e. all classifiers) File outputDir = new File(OUTPUT_DIR + "/" + dataset.toString() + "/"); File[] dirsArray = outputDir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); List<File> dirs = CollectionUtils.arrayToList(dirsArray); // Don't list hidden dirs (such as .svn) for (int i = dirs.size() - 1; i >= 0; i--) if (dirs.get(i).getName().startsWith(".")) dirs.remove(i);/*from w w w.ja va2 s. c o m*/ // Iteratively evaluate all classifiers' results for (File dir : dirs) runEvaluationMetric(WekaClassifier.valueOf(dir.getName()), metric, dataset); }
From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java
@SuppressWarnings("unchecked") private List<String> getAnnotationValuesAsStringList(Annotation annotation, String attribute) { String[] values = (String[]) AnnotationUtils.getValue(annotation, attribute); if (values.length > 1 || (values.length == 1 && StringUtils.hasText(values[0]))) { return CollectionUtils.arrayToList(values); }//from w w w. j a va2 s . c om return Collections.emptyList(); }
From source file:com.consol.citrus.mvn.plugin.CreateTestMojo.java
/** * Creates test case with request and response messages from XML schema. * @param creator/*from ww w . j a v a2 s .c om*/ * @throws MojoExecutionException */ public void createWithWsdl(TestCaseCreator creator) throws MojoExecutionException { String separator = "+++++++++++++++++++++++++++++++++++"; try { String wsdl = this.wsdl; while (interactiveMode && !StringUtils.hasText(wsdl)) { wsdl = prompter.prompt("Enter path to WSDL", this.wsdl); } if (!StringUtils.hasText(wsdl)) { throw new MojoExecutionException("Please provide proper path to WSDL file"); } String wsdlNsDelaration = "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/' "; // compile wsdl and xsds right now, otherwise later input is useless: XmlObject wsdlObject = compileWsdl(wsdl); SchemaTypeSystem schemaTypeSystem = compileXsd(wsdlObject); getLog().info(separator); getLog().info("WSDL compilation successful"); String serviceName = evaluateAsString(wsdlObject, wsdlNsDelaration + ".//wsdl:portType/@name"); getLog().info("Found service: " + serviceName); getLog().info(separator); getLog().info("Found service operations:"); XmlObject[] messages = wsdlObject.selectPath(wsdlNsDelaration + ".//wsdl:message"); XmlObject[] operations = wsdlObject.selectPath(wsdlNsDelaration + ".//wsdl:portType/wsdl:operation"); for (XmlObject operation : operations) { getLog().info(evaluateAsString(operation, wsdlNsDelaration + "./@name")); } getLog().info(separator); getLog().info("Generating test cases for service operations ..."); String nameSuffix = this.nameSuffix; if (interactiveMode) { nameSuffix = prompter.prompt("Enter test name suffix", this.nameSuffix); } if (interactiveMode) { String confirm = prompter.prompt( "Confirm test creation:\n" + "framework: " + creator.getFramework() + "\n" + "name: " + creator.getName() + "\n" + "author: " + creator.getAuthor() + "\n" + "description: " + creator.getDescription() + "\n" + "package: " + creator.getTargetPackage() + "\n", CollectionUtils.arrayToList(new String[] { "y", "n" }), "y"); if (confirm.equalsIgnoreCase("n")) { return; } } for (XmlObject operation : operations) { String operationName = evaluateAsString(operation, wsdlNsDelaration + "./@name"); String inputMessage = removeNsPrefix( evaluateAsString(operation, wsdlNsDelaration + "./wsdl:input/@message")); String outputMessage = removeNsPrefix( evaluateAsString(operation, wsdlNsDelaration + "./wsdl:output/@message")); String inputElement = null; String outputElement = null; for (XmlObject message : messages) { String messageName = evaluateAsString(message, wsdlNsDelaration + "./@name"); if (messageName.equals(inputMessage)) { inputElement = removeNsPrefix( evaluateAsString(message, wsdlNsDelaration + "./wsdl:part/@element")); } if (messageName.equals(outputMessage)) { outputElement = removeNsPrefix( evaluateAsString(message, wsdlNsDelaration + "./wsdl:part/@element")); } } SchemaType requestElem = getSchemaType(schemaTypeSystem, operationName, inputElement); SchemaType responseElem = getSchemaType(schemaTypeSystem, operationName, outputElement); String testName = creator.getName() + operationName + nameSuffix; // Now generate it creator.withName(testName).withXmlRequest(SampleXmlUtil.createSampleForType(requestElem)) .withXmlResponse(SampleXmlUtil.createSampleForType(responseElem)); creator.createTestCase(); getLog().info("Successfully created new test case " + creator.getTargetPackage() + "." + testName); } } catch (ArrayIndexOutOfBoundsException e) { getLog().info(e); getLog().info( "Wrong parameter usage! See citrus:help for usage details (mvn citrus:help -Ddetail=true -Dgoal=create-suite-from-wsdl)."); } catch (PrompterException e) { getLog().info(e); getLog().info( "Failed to create suite! See citrus:help for usage details (mvn citrus:help -Ddetail=true -Dgoal=create-suite-from-wsdl)."); } catch (IOException e) { getLog().info(e); } }