List of usage examples for java.util Collection addAll
boolean addAll(Collection<? extends E> c);
From source file:de.dfki.km.perspecting.obie.corpus.LabeledTextCorpus.java
public static Collection<String> scanWordContent(double probUseType, Set<String> matchPos, String[] wordFeatureVector, boolean useRegex) { Collection<String> returnValues = new HashSet<String>(); if (wordFeatureVector.length == 4) { if (wordFeatureVector[LABEL].equals(OUTSIDE_ANY_LABEL)) { if (wordFeatureVector[POS].length() > 1 && matchPos.contains(wordFeatureVector[POS].substring(0, 2))) { returnValues.addAll(scanWordSyntax(wordFeatureVector, useRegex, false)); } else { if (wordFeatureVector[LABEL].length() > 1) { returnValues.addAll(scanWordSyntax(wordFeatureVector, useRegex, false)); }//from w w w.j a va 2 s. c om } } else { double d = new Random().nextDouble(); if (d <= probUseType) { returnValues.add(wordFeatureVector[LABEL]); } else { if (wordFeatureVector[LABEL].length() > 1) { returnValues.addAll(scanWordSyntax(wordFeatureVector, useRegex, false)); } } } } return returnValues; }
From source file:com.sun.socialsite.business.impl.JPAListenerManagerImpl.java
/** * Returns all listeners which have registered to receive lifecycle * events for a class to which the specified entity belongs. * @param entity the entity for which listeners are sought. *//*w w w .j a va 2 s. c o m*/ private static Collection<Object> getListeners(Object entity) { Collection<Object> results = new ArrayList<Object>(); Set<Class> classes = new HashSet<Class>(); for (Class clazz = entity.getClass(); clazz != null; clazz = clazz.getSuperclass()) { classes.add(clazz); Class[] declaredClasses = entity.getClass().getDeclaredClasses(); for (int i = 0; i < declaredClasses.length; i++) { classes.add(declaredClasses[i]); } } for (Class clazz : classes) { Collection<Object> listenersForClass = listenersMap.get(clazz); if (listenersForClass != null) { results.addAll(listenersForClass); } } //log.debug(String.format("getListeners(%s): entityClass=%s results.size=%d", entity, entity.getClass().getCanonicalName(), results.size())); return results; }
From source file:com.opengamma.engine.view.compilation.CompiledViewCalculationConfigurationImpl.java
private static Map<ValueSpecification, Collection<ValueSpecification>> processMarketDataRequirements( final DependencyGraph dependencyGraph) { ArgumentChecker.notNull(dependencyGraph, "dependencyGraph"); final Collection<ValueSpecification> marketDataEntries = dependencyGraph.getAllRequiredMarketData(); final Map<ValueSpecification, Collection<ValueSpecification>> result = Maps .newHashMapWithExpectedSize(marketDataEntries.size()); final Set<ValueSpecification> terminalOutputs = dependencyGraph.getTerminalOutputSpecifications(); for (ValueSpecification marketData : marketDataEntries) { final DependencyNode marketDataNode = dependencyGraph.getNodeProducing(marketData); Collection<ValueSpecification> aliases = null; Collection<DependencyNode> aliasNodes = marketDataNode.getDependentNodes(); boolean usedDirectly = terminalOutputs.contains(marketData); for (DependencyNode aliasNode : aliasNodes) { if (aliasNode.getFunction().getFunction() instanceof MarketDataAliasingFunction) { if (aliases == null) { aliases = new ArrayList<>(aliasNodes.size()); result.put(marketData, Collections.unmodifiableCollection(aliases)); }//from w w w .j a va2s . co m aliases.addAll(aliasNode.getOutputValues()); } else { usedDirectly = true; } } if (usedDirectly) { if (aliases != null) { aliases.add(marketData); } else { result.put(marketData, Collections.singleton(marketData)); } } } return Collections.unmodifiableMap(result); }
From source file:br.msf.commons.util.CollectionUtils.java
public static <T extends Object> Collection<T> getCopy(final Collection<T> collection) { Collection<T> clone = null; if (collection != null) { clone = getCompatibleInstance(collection); clone.addAll(collection); }//from w w w . ja va 2s . c o m return clone; }
From source file:br.msf.commons.util.CollectionUtils.java
public static <T extends Object> Collection<T> merge(final Collection<T>... collections) { final int size = size(collections); if (size <= 0) { return EMPTY_LIST; }/* w ww . ja v a 2 s .c o m*/ final Collection<T> all = new ArrayList<>(size); for (final Collection<T> c : collections) { if (isNotEmpty(c)) { all.addAll(c); } } return all; }
From source file:br.ojimarcius.commons.util.CollectionUtils.java
public static <T extends Object> Collection<T> merge(final Collection<T>... collections) { final int size = size(collections); if (size <= 0) { return EMPTY_LIST; }/* ww w . ja v a 2 s . c om*/ final Collection<T> all = new ArrayList<T>(size); for (final Collection<T> c : collections) { if (isNotEmpty(c)) { all.addAll(c); } } return all; }
From source file:net.mojodna.searchable.util.SearchableUtils.java
/** * Generate a list of field names for a given property. * //from w w w.j a va2s. c o m * @param descriptor Property descriptor. * @return Collection of field names. */ public static final Collection<String> getFieldnames(final PropertyDescriptor descriptor) { final Collection<String> fieldnames = new LinkedList<String>(); String fieldname = descriptor.getName(); for (final Class<? extends Annotation> annotationClass : Searchable.INDEXING_ANNOTATIONS) { final Annotation annotation = AnnotationUtils.getAnnotation(descriptor.getReadMethod(), annotationClass); if (annotation instanceof Searchable.Indexed) { final Searchable.Indexed i = (Searchable.Indexed) annotation; if (StringUtils.isNotBlank(i.name())) fieldname = i.name(); // add any aliases fieldnames.addAll(Arrays.asList(i.aliases())); } else if (annotation instanceof Searchable.Stored) { final Searchable.Stored s = (Searchable.Stored) annotation; if (StringUtils.isNotBlank(s.name())) fieldname = s.name(); // add any aliases fieldnames.addAll(Arrays.asList(s.aliases())); } else if (annotation instanceof Searchable.Sortable) { final Searchable.Sortable s = (Sortable) annotation; if (StringUtils.isNotBlank(s.name())) fieldname = s.name(); } } // add the default field name fieldnames.add(fieldname); return fieldnames; }
From source file:demo.config.PropertyConverter.java
/** * Flattens the given iterator. For each element in the iteration * {@code flatten()} will be called recursively. * /*from w w w .j a v a 2s . c o m*/ * @param target * the target collection * @param it * the iterator to process * @param delimiter * the delimiter for String values */ private static void flattenIterator(Collection<Object> target, Iterator<?> it, char delimiter) { while (it.hasNext()) { target.addAll(flatten(it.next(), delimiter)); } }
From source file:com.ironiacorp.persistence.datasource.HibernateConfigurationUtil.java
/** * Retrieve the data sources registered at JNDI in the given context. * /* w w w. ja v a2 s. c o m*/ * @param namingContext * Start point context. * * @return A collection of the data sources found within the context. */ private static Collection<String> getAvailableDataSources(Context namingContext) { Collection<String> datasources = new ArrayList<String>(); Class<?> type = null; // Acquire global JNDI resources if available try { type = Class.forName("xyz"); } catch (ClassNotFoundException e) { } try { NamingEnumeration<Binding> items = namingContext.listBindings(""); while (items.hasMore()) { Binding item = (Binding) items.next(); if (item.getObject() instanceof Context) { datasources.addAll(getAvailableDataSources((Context) item.getObject())); } else { if (type.isInstance(item.getObject())) { datasources.add(item.getName()); } } } } catch (Throwable t) { } return datasources; }
From source file:com.google.zxing.web.DecodeServlet.java
private static void processImage(BufferedImage image, ServletRequest request, HttpServletResponse response) throws IOException, ServletException { LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source)); Collection<Result> results = Lists.newArrayListWithCapacity(1); try {/* w w w. j a v a 2s . co m*/ Reader reader = new MultiFormatReader(); ReaderException savedException = null; try { // Look for multiple barcodes MultipleBarcodeReader multiReader = new GenericMultipleBarcodeReader(reader); Result[] theResults = multiReader.decodeMultiple(bitmap, HINTS); if (theResults != null) { results.addAll(Arrays.asList(theResults)); } } catch (ReaderException re) { savedException = re; } if (results.isEmpty()) { try { // Look for pure barcode Result theResult = reader.decode(bitmap, HINTS_PURE); if (theResult != null) { results.add(theResult); } } catch (ReaderException re) { savedException = re; } } if (results.isEmpty()) { try { // Look for normal barcode in photo Result theResult = reader.decode(bitmap, HINTS); if (theResult != null) { results.add(theResult); } } catch (ReaderException re) { savedException = re; } } if (results.isEmpty()) { try { // Try again with other binarizer BinaryBitmap hybridBitmap = new BinaryBitmap(new HybridBinarizer(source)); Result theResult = reader.decode(hybridBitmap, HINTS); if (theResult != null) { results.add(theResult); } } catch (ReaderException re) { savedException = re; } } if (results.isEmpty()) { handleException(savedException, response); return; } } catch (RuntimeException re) { // Call out unexpected errors in the log clearly log.log(Level.WARNING, "Unexpected exception from library", re); throw new ServletException(re); } String fullParameter = request.getParameter("full"); boolean minimalOutput = fullParameter != null && !Boolean.parseBoolean(fullParameter); if (minimalOutput) { response.setContentType(MediaType.PLAIN_TEXT_UTF_8.toString()); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); try (Writer out = new OutputStreamWriter(response.getOutputStream(), StandardCharsets.UTF_8)) { for (Result result : results) { out.write(result.getText()); out.write('\n'); } } } else { request.setAttribute("results", results); request.getRequestDispatcher("decoderesult.jspx").forward(request, response); } }