List of usage examples for org.springframework.util CollectionUtils arrayToList
@SuppressWarnings("rawtypes") public static List arrayToList(@Nullable Object source)
From source file:com.bstek.dorado.view.config.xml.ItemsParser.java
@Override protected Object internalParse(Node node, DataParseContext context) throws Exception { Object value = super.internalParse(node, context); if (value instanceof String) { String[] items = StringUtils.split((String) value, ','); return (items != null) ? CollectionUtils.arrayToList(items) : null; } else {/*from w ww . j a v a 2s . co m*/ return value; } }
From source file:io.twipple.springframework.data.clusterpoint.convert.support.ConversionUtils.java
/** * Returns a collection from the given source object. * * @param source the source object./*from w w w . j ava 2 s . c om*/ * @return the target collection. */ @NotNull public static Collection<?> asCollection(@NotNull Object source) { Assert.notNull(source); if (source instanceof Collection) { return (Collection<?>) source; } if (source.getClass().isArray()) { return CollectionUtils.arrayToList(source); } return Collections.singleton(source); }
From source file:org.agatom.springatom.data.constraints.impl.BrandOrModelValidator.java
/** {@inheritDoc} */ @Override/* w w w .j ava2 s . c o m*/ public boolean isValid(final String[] value, final ConstraintValidatorContext context) { final List<?> list = CollectionUtils.arrayToList(value); for (Object str : list) { final boolean valid = this.isValid((String) str); if (!valid) { return false; } } return true; }
From source file:com.apress.prospringintegration.security.SecurityMain.java
@SuppressWarnings("unchecked") public static SecurityContext createContext(String username, String password, String... roles) { SecurityContextImpl ctxImpl = new SecurityContextImpl(); UsernamePasswordAuthenticationToken authToken; if (roles != null && roles.length > 0) { GrantedAuthority[] authorities = new GrantedAuthority[roles.length]; for (int i = 0; i < roles.length; i++) { authorities[i] = new GrantedAuthorityImpl(roles[i]); }/*w w w . j a va2s .co m*/ authToken = new UsernamePasswordAuthenticationToken(username, password, CollectionUtils.arrayToList(authorities)); } else { authToken = new UsernamePasswordAuthenticationToken(username, password); } ctxImpl.setAuthentication(authToken); return ctxImpl; }
From source file:de.tudarmstadt.ukp.similarity.experiments.coling2012.util.WordIdfValuesGenerator.java
@SuppressWarnings("unchecked") public static void computeIdfScores(Dataset dataset) throws Exception { File outputFile = new File(UTILS_DIR + "/word-idf/" + dataset.toString() + ".txt"); System.out.println("Computing word idf values"); if (outputFile.exists()) { System.out.println(" - skipping, already exists"); } else {//w ww . j a v a 2s . c o m System.out.println(" - this may take a while..."); CollectionReader reader = ColingUtils.getCollectionReader(dataset); // Tokenization AnalysisEngineDescription seg = createPrimitiveDescription(BreakIteratorSegmenter.class); AggregateBuilder builder = new AggregateBuilder(); builder.add(seg, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_1); builder.add(seg, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_2); AnalysisEngine aggr_seg = builder.createAggregate(); // POS Tagging AnalysisEngineDescription pos = createPrimitiveDescription(OpenNlpPosTagger.class, OpenNlpPosTagger.PARAM_LANGUAGE, "en"); builder = new AggregateBuilder(); builder.add(pos, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_1); builder.add(pos, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_2); AnalysisEngine aggr_pos = builder.createAggregate(); // Lemmatization AnalysisEngineDescription lem = createPrimitiveDescription(StanfordLemmatizer.class); builder = new AggregateBuilder(); builder.add(lem, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_1); builder.add(lem, CombinationReader.INITIAL_VIEW, CombinationReader.VIEW_2); AnalysisEngine aggr_lem = builder.createAggregate(); // Output Writer AnalysisEngine writer = createPrimitive(WordIdfValuesGeneratorWriter.class, WordIdfValuesGeneratorWriter.PARAM_OUTPUT_FILE, outputFile.getAbsolutePath()); SimplePipeline.runPipeline(reader, aggr_seg, aggr_pos, aggr_lem, writer); // Now we have the text format lemma1###lemma2###...###lemman List<String> lines = FileUtils.readLines(outputFile); Map<String, Double> idfValues = new HashMap<String, Double>(); // Build up token representations of texts Set<List<String>> docs = new HashSet<List<String>>(); for (String line : lines) { List<String> doc = CollectionUtils.arrayToList(line.split("###")); docs.add(doc); } // Get the shared token list Set<String> tokens = new HashSet<String>(); for (List<String> doc : docs) tokens.addAll(doc); // Get the idf numbers for (String token : tokens) { double count = 0; for (List<String> doc : docs) { if (doc.contains(token)) count++; } idfValues.put(token, count); } // Compute the idf for (String lemma : idfValues.keySet()) { double idf = Math.log10(lines.size() / idfValues.get(lemma)); idfValues.put(lemma, idf); } // Store persistently StringBuilder sb = new StringBuilder(); for (String key : idfValues.keySet()) { sb.append(key + "\t" + idfValues.get(key) + LF); } FileUtils.writeStringToFile(outputFile, sb.toString()); System.out.println(" - done"); } }
From source file:com.consol.citrus.mvn.plugin.CreateHtmlDocMojo.java
@Override public void execute() throws MojoExecutionException { try {// ww w . jav a 2 s. c o m if (interactiveMode) { overviewTitle = prompter.prompt("Enter overview title:", overviewTitle); columns = prompter.prompt("Enter number of columns in overview:", columns); pageTitle = prompter.prompt("Enter page title:", pageTitle); outputFile = prompter.prompt("Enter output file name:", outputFile); logo = prompter.prompt("Enter file path to logo:", logo); String confirm = prompter.prompt( "Confirm HTML documentation: outputFile='target/" + outputFile + ".html'\n", CollectionUtils.arrayToList(new String[] { "y", "n" }), "y"); if (confirm.equalsIgnoreCase("n")) { return; } } HtmlTestDocGenerator creator = HtmlTestDocGenerator.build().withOutputFile(outputFile + ".html") .withPageTitle(pageTitle).withOverviewTitle(overviewTitle).withColumns(columns) .useSrcDirectory(srcDirectory).withLogo(logo); creator.generateDoc(); getLog().info("Successfully created HTML documentation: outputFile='target/" + outputFile + ".html'"); } catch (PrompterException e) { getLog().info(e); } }
From source file:org.hdiv.web.servlet.tags.form.SelectedValueComparatorHDIV.java
/** * Returns <code>true</code> if the supplied candidate value is equal to the value bound to * the supplied {@link BindStatus}. Equality in this case differs from standard Java equality and * is described in more detail <a href="#equality-contract">here</a>. *//*from w w w . jav a 2 s . c om*/ public static boolean isSelected(BindStatus bindStatus, Object candidateValue) { if (bindStatus == null) { return (candidateValue == null); } // Check obvious equality matches with the candidate first, // both with the rendered value and with the original value. Object boundValue = bindStatus.getValue(); if (ObjectUtils.nullSafeEquals(boundValue, candidateValue)) { return true; } Object actualValue = bindStatus.getActualValue(); if (actualValue != null && actualValue != boundValue && ObjectUtils.nullSafeEquals(actualValue, candidateValue)) { return true; } if (actualValue != null) { boundValue = actualValue; } else if (boundValue == null) { return false; } // Non-null value but no obvious equality with the candidate value: // go into more exhaustive comparisons. boolean selected = false; if (boundValue.getClass().isArray()) { selected = collectionCompare(CollectionUtils.arrayToList(boundValue), candidateValue, bindStatus); } else if (boundValue instanceof Collection) { selected = collectionCompare((Collection) boundValue, candidateValue, bindStatus); } else if (boundValue instanceof Map) { selected = mapCompare((Map) boundValue, candidateValue, bindStatus); } if (!selected) { selected = exhaustiveCompare(boundValue, candidateValue, bindStatus.getEditor(), null); } return selected; }
From source file:com.consol.citrus.mvn.plugin.CreateExcelDocMojo.java
@Override public void execute() throws MojoExecutionException { try {/* www . jav a 2s . c o m*/ if (interactiveMode) { company = prompter.prompt("Enter company:", company); author = prompter.prompt("Enter author:", author); pageTitle = prompter.prompt("Enter page title:", pageTitle); outputFile = prompter.prompt("Enter output file name:", outputFile); customHeaders = prompter.prompt("Enter custom headers:", customHeaders); String confirm = prompter.prompt( "Confirm Excel documentation: outputFile='target/" + outputFile + ".xls'\n", CollectionUtils.arrayToList(new String[] { "y", "n" }), "y"); if (confirm.equalsIgnoreCase("n")) { return; } } ExcelTestDocGenerator creator = ExcelTestDocGenerator.build().withOutputFile(outputFile + ".xls") .withPageTitle(pageTitle).withAuthor(author).withCompany(company).useSrcDirectory(srcDirectory) .withCustomHeaders(customHeaders); creator.generateDoc(); getLog().info("Successfully created Excel documentation: outputFile='target/" + outputFile + ".xls'"); } catch (PrompterException e) { getLog().info(e); } }
From source file:egovframework.rte.itl.integration.message.typed.TypedList.java
/** * Argument <code>type</code>? TypedList * Instance ?. Argument <code>array</code>? * ? .//from w w w . j a v a 2 s .co m * @param type * type * @param array * array * @throws IllegalArgumentException * 1. Argument <code>type</code> ? * <code>null</code>? 2. Argument * <code>array</code> ? <code>null</code> * ? array */ @SuppressWarnings("unchecked") public TypedList(final ListType type, final Object array) { this(type); if (array == null || array.getClass().isArray() == false) { throw new IllegalArgumentException(); } addAll(CollectionUtils.arrayToList(array)); }
From source file:org.paxml.tag.sql.DdlTag.java
private void clean(Context context) { if (cleanSchemaSql == null) { throw new PaxmlRuntimeException("No clean schema sql given."); }// w ww . ja v a2 s . c o m List sql = null; Iterator it = null; if (cleanSchemaSql instanceof Iterable) { it = ((Iterable) cleanSchemaSql).iterator(); } else if (cleanSchemaSql instanceof Array) { sql = CollectionUtils.arrayToList(cleanSchemaSql); } else if (cleanSchemaSql instanceof Iterator) { it = (Iterator) cleanSchemaSql; } else { sql = Arrays.asList(cleanSchemaSql.toString()); } if (sql == null) { sql = new ArrayList<String>(); while (it.hasNext()) { sql.add(it.next()); } } for (Object s : sql) { if (s != null) { executeSql(s.toString(), context); } } }