List of usage examples for java.util Collection add
boolean add(E e);
From source file:com.clicktravel.cheddar.system.event.runtime.config.SystemEventHandlerConfiguration.java
/** * Cast Collection<? extends SystemEventHandler> to Collection<EventHandler<SystemEvent>> * @param systemEventHandlers as Collection<? extends SystemEventHandler> * @return systemEventHandlers as Collection<EventHandler<SystemEvent>> *//* www .j av a 2 s. c o m*/ public static Collection<EventHandler<SystemEvent>> castSystemEventHandlers( final Collection<? extends SystemEventHandler> systemEventHandlers) { final Collection<EventHandler<SystemEvent>> handlers = new ArrayList<>(); if (systemEventHandlers != null) { for (final SystemEventHandler systemEventHandler : systemEventHandlers) { handlers.add(systemEventHandler); } } return handlers; }
From source file:com.cloudera.oryx.app.serving.als.model.LoadTestALSModelFactory.java
public static ALSServingModel buildTestModel() { log.info("Building load test model..."); System.gc();//from w w w. ja v a2s. co m long startMemory = JVMUtils.getUsedMemory(); ALSServingModel model = new ALSServingModel(FEATURES, true, LSH_SAMPLE_RATE, new TestALSRescorerProvider()); AtomicLong totalEntries = new AtomicLong(); int numCores = Runtime.getRuntime().availableProcessors(); log.info("Adding {} users", USERS); AtomicInteger userCount = new AtomicInteger(); ExecUtils.doInParallel(numCores, i -> { RandomGenerator random = RandomManager.getRandom(((long) i << 32) ^ System.nanoTime()); PoissonDistribution itemPerUserDist = new PoissonDistribution(random, AVG_ITEMS_PER_USER, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS); for (int user = userCount.getAndIncrement(); user < USERS; user = userCount.getAndIncrement()) { String userID = "U" + user; model.setUserVector(userID, VectorMath.randomVectorF(FEATURES, random)); int itemsPerUser = itemPerUserDist.sample(); totalEntries.addAndGet(itemsPerUser); Collection<String> knownIDs = new ArrayList<>(itemsPerUser); for (int item = 0; item < itemsPerUser; item++) { knownIDs.add("I" + random.nextInt(ITEMS)); } model.addKnownItems(userID, knownIDs); } }); log.info("Adding {} items", ITEMS); AtomicInteger itemCount = new AtomicInteger(); ExecUtils.doInParallel(numCores, i -> { RandomGenerator random = RandomManager.getRandom(((long) i << 32) ^ System.nanoTime()); for (int item = itemCount.getAndIncrement(); item < ITEMS; item = itemCount.getAndIncrement()) { model.setItemVector("I" + item, VectorMath.randomVectorF(FEATURES, random)); } }); System.gc(); long endMemory = JVMUtils.getUsedMemory(); log.info("Built model over {} users, {} items, {} features, {} entries, using {}MB", USERS, ITEMS, FEATURES, totalEntries, (endMemory - startMemory) / 1_000_000); log.info("Model: {}", model); return model; }
From source file:Main.java
/** * Adds all objects into the specified list. * * @param collection list to fill// ww w . j a v a 2s . c o m * @param objects objects * @param <T> objects type * @return true if list changed as the result of this operation, false otherwise */ public static <T> boolean addAll(final Collection<T> collection, final T... objects) { boolean result = false; for (final T object : objects) { if (!collection.contains(object)) { result |= collection.add(object); } } return result; }
From source file:com.comcast.video.dawg.controller.house.StbModelController.java
private static Collection<Capability> enumerate(Collection<String> caps) { Collection<Capability> rv = new ArrayList<Capability>(); for (String cap : caps) { rv.add(Capability.valueOf(cap)); }// w w w.j ava 2 s.c o m return rv; }
From source file:Main.java
private static Class<?>[] convertToPrimitiveClasses(Class<?>... classes) { Collection<Class<?>> convertedClasses = new HashSet<Class<?>>(); for (Class<?> classObject : classes) { if (classObject.getName().equalsIgnoreCase(Integer.class.getName())) { convertedClasses.add(int.class); } else if (classObject.getName().equalsIgnoreCase(Long.class.getName())) { convertedClasses.add(long.class); } else if (classObject.getName().equalsIgnoreCase(Float.class.getName())) { convertedClasses.add(float.class); } else if (classObject.getName().equalsIgnoreCase(Double.class.getName())) { convertedClasses.add(double.class); } else if (classObject.getName().equalsIgnoreCase(Boolean.class.getName())) { convertedClasses.add(boolean.class); } else if (classObject.getName().equalsIgnoreCase(Blob.class.getName())) { convertedClasses.add(byte.class); } else {//from w ww. jav a 2 s . c o m convertedClasses.add(classObject); } } Class<?>[] convertedArrayClasses = new Class<?>[convertedClasses.size()]; Iterator<Class<?>> convertedClassesItr = convertedClasses.iterator(); int count = 0; while (convertedClassesItr.hasNext()) { convertedArrayClasses[count++] = convertedClassesItr.next(); } return convertedArrayClasses; }
From source file:de.undercouch.citeproc.helper.Levenshtein.java
/** * Searches the given collection of strings and returns a collection of * strings similar to a given string <code>t</code>. Uses reasonable default * values for human-readable strings. The returned collection will be * sorted according to their similarity with the string with the best * match at the first position./*w w w .j a v a 2s.c om*/ * @param <T> the type of the strings in the given collection * @param ss the collection to search * @param t the string to compare to * @return a collection with similar strings */ public static <T extends CharSequence> Collection<T> findSimilar(Collection<T> ss, CharSequence t) { //look for strings prefixed by 't' Collection<T> result = new LinkedHashSet<T>(); for (T s : ss) { if (StringUtils.startsWithIgnoreCase(s, t)) { result.add(s); } } //find strings according to their levenshtein distance Collection<T> mins = findMinimum(ss, t, 5, Math.min(t.length() - 1, 7)); result.addAll(mins); return result; }
From source file:com.bluexml.side.util.dependencies.ModuleConstraint.java
public static Collection<ModuleVersion> getAllMin(Collection<ModuleConstraint> col) { Collection<ModuleVersion> ext = new ArrayList<ModuleVersion>(); for (ModuleConstraint mc : col) { ext.add(mc.versionMin); }/*from ww w .j a v a 2 s . co m*/ return ext; }
From source file:com.bluexml.side.util.dependencies.ModuleConstraint.java
public static Collection<ModuleVersion> getAllMax(Collection<ModuleConstraint> col) { Collection<ModuleVersion> ext = new ArrayList<ModuleVersion>(); for (ModuleConstraint mc : col) { ext.add(mc.versionMax); }/*w w w. j a va2 s .c o m*/ return ext; }
From source file:Main.java
/** * Merge the given array into the given Collection. * * @param array the array to merge (may be {@code null}) * @param collection the target Collection to merge the array into *//*w w w .j a v a 2s . com*/ @SuppressWarnings("unchecked") public static <E> void mergeArrayIntoCollection(Object array, Collection<E> collection) { if (collection == null) { throw new IllegalArgumentException("Collection must not be null"); } Object[] arr = ObjectUtils.toObjectArray(array); for (Object elem : arr) { collection.add((E) elem); } }
From source file:org.calrissian.restdoclet.writer.swagger.SwaggerWriter.java
private static Map<String, Collection<Endpoint>> groupPaths(Collection<Endpoint> endpoints) { Map<String, Collection<Endpoint>> paths = new LinkedHashMap<String, Collection<Endpoint>>(); for (Endpoint endpoint : endpoints) { if (paths.containsKey(endpoint.getPath())) { paths.get(endpoint.getPath()).add(endpoint); } else {/*from www.ja v a 2 s .c o m*/ Collection<Endpoint> tmp = new ArrayList<Endpoint>(); tmp.add(endpoint); paths.put(endpoint.getPath(), tmp); } } return paths; }