List of usage examples for java.util Collection add
boolean add(E e);
From source file:Main.java
private static <T> void permutationsImpl(List<Collection<T>> ori, Collection<List<T>> res, int d, List<T> current) {/* www . ja v a2 s.c o m*/ // if depth equals number of original collections, final reached, add and return if (d == ori.size()) { res.add(current); return; } // iterate from current collection and copy 'current' element N times, one for each element Collection<T> currentCollection = ori.get(d); for (T element : currentCollection) { List<T> copy = Lists.newLinkedList(current); copy.add(element); permutationsImpl(ori, res, d + 1, copy); } }
From source file:Main.java
/** * Adds all elements in the iteration to the given collection. * /*from w w w . ja va 2s . co m*/ * @param collection * the collection to add to, must not be null * @param iterator * the iterator of elements to add, must not be null * @throws NullPointerException * if the collection or iterator is null */ public static <E> void addAll(Collection<E> collection, Iterator<E> iterator) { if (collection == null || iterator == null) { return; } while (iterator.hasNext()) { collection.add(iterator.next()); } }
From source file:Main.java
/** * Adds all elements in the array to the given collection. * /*from ww w .j a va 2 s. c o m*/ * @param collection * the collection to add to * @param elements * the array of elements to add, may be null * @throws NullPointerException * if the collection or array is null */ public static void addAll(Collection collection, Object[] elements) { for (int i = 0, size = elements.length; i < size; i++) { collection.add(elements[i]); } }
From source file:Main.java
/** * Samples without replacement from a collection, using your own * {@link Random} number generator.//from ww w .ja v a 2s . c o m * * @param c * The collection to be sampled from * @param n * The number of samples to take * @param r * the random number generator * @return a new collection with the sample */ public static <E> Collection<E> sampleWithoutReplacement(Collection<E> c, int n, Random r) { if (n < 0) throw new IllegalArgumentException("n < 0: " + n); if (n > c.size()) throw new IllegalArgumentException("n > size of collection: " + n + ", " + c.size()); List<E> copy = new ArrayList<E>(c.size()); copy.addAll(c); Collection<E> result = new ArrayList<E>(n); for (int k = 0; k < n; k++) { double d = r.nextDouble(); int x = (int) (d * copy.size()); result.add(copy.remove(x)); } return result; }
From source file:org.openmrs.module.webservices.rest.resource.BaseRestDataResource.java
/** * Syncs the base collection with the items in the sync collection. This will add any missing items, updating existing * items, and delete any items not found in the sync collection. * @param base The collection to update. * @param sync The collection used to update the base. * @param <E> The {@link OpenmrsObject} stored in the collection. *///from www .ja v a 2 s . c o m public static <E extends OpenmrsObject> void syncCollection(Collection<E> base, Collection<E> sync) { syncCollection(base, sync, new Action2<Collection<E>, E>() { @Override public void apply(Collection<E> collection, E entity) { collection.add(entity); } }, new Action2<Collection<E>, E>() { @Override public void apply(Collection<E> collection, E entity) { collection.remove(entity); } }); }
From source file:Main.java
public static void addPluginIfMatches(File folderOrJar, String bundleName, Collection<File> result) { String name = folderOrJar.getName(); if (folderOrJar.isFile()) { if (name.equals(bundleName + ".jar") || name.startsWith(bundleName + "_") && name.endsWith(".jar")) result.add(folderOrJar); } else {/*from w w w . j a va 2 s .c o m*/ if (name.equals(bundleName) || name.startsWith(bundleName + "_")) result.add(folderOrJar); } }
From source file:com.glaf.core.util.AnnotationUtils.java
public static Collection<String> findClasses(String name) { AnnotationDB db = getAnnotationDB(); Map<String, Set<String>> annotationIndex = db.getAnnotationIndex(); Set<String> entities = annotationIndex.get(name); Collection<String> sortSet = new TreeSet<String>(); if (entities != null && !entities.isEmpty()) { for (String str : entities) { sortSet.add(str); }// w ww. ja v a 2 s. c o m } return sortSet; }
From source file:de.codesourcery.eve.skills.util.Misc.java
public static Collection<String> wrap(String s, int maxLength) { if (StringUtils.isBlank(s)) { return Collections.emptyList(); }// w w w .j a va 2 s.co m if (s.length() <= maxLength) { final Collection<String> res = new ArrayList<String>(); res.add(s); return res; } final List<String> lines = new ArrayList<String>(); int i0 = 0; int i1 = 0; int lastSplit = -1; for (; i1 < s.length(); i1++) { final char c = s.charAt(i1); if (c == ' ' || c == '.' || c == ',') { lastSplit = i1; } final int count = i1 - i0; if (count > maxLength) { if (lastSplit != -1) { lines.add(s.substring(i0, lastSplit)); i0 = lastSplit + 1; } else { lines.add(s.substring(i0, i1)); i0 = i1; } i1 = i0; lastSplit = -1; } } if (i1 - i0 > 0 && i0 < s.length()) { lines.add(s.substring(i0, i1)); } return lines; }
From source file:Main.java
/** * //from ww w. j av a 2 s . com * @param stringArray * @return double[] */ public static double[] toDoubleArray(final String[] stringArray) { final Collection<Double> doubleCollection = new ArrayList<>(); for (String value : stringArray) { doubleCollection.add(Double.valueOf(value)); } return toDoubleArray(doubleCollection); }
From source file:net.maritimecloud.identityregistry.controllers.TokenGenerator.java
public static Collection<GrantedAuthority> generateGrantedAuthority(String roles) { Collection<GrantedAuthority> authorities = new ArrayList<>(); String[] roleArr = roles.split(","); for (String role : roleArr) { authorities.add(new SimpleGrantedAuthority(role.trim())); }/*from w w w.ja va 2 s. c om*/ return authorities; }