List of usage examples for java.util Collection add
boolean add(E e);
From source file:Main.java
public static <T> void move(Collection<T> fromCollection, Collection<T> toCollection) { for (Iterator<T> i = fromCollection.iterator(); i.hasNext();) { T element = i.next();//from w ww . ja v a 2s . c o m i.remove(); toCollection.add(element); } }
From source file:Main.java
private static void extractAddedEntries(final Collection<String> oldCollection, final Collection<String> updatedCollection, final Collection<String> addedEntriesCollection) { for (final String entry : updatedCollection) { if (!oldCollection.contains(entry)) { addedEntriesCollection.add(entry); }//from www . j ava 2 s.c om } }
From source file:com.enonic.cms.core.content.ContentKey.java
public static Collection<ContentKey> convertToList(int key) { Collection<ContentKey> list = new ArrayList<ContentKey>(1); list.add(new ContentKey(key)); return list;/*from w w w .j a v a2 s.co m*/ }
From source file:com.enonic.cms.core.log.LogEntryKey.java
public static Collection<LogEntryKey> convertToList(String[] array) { if (array == null || array.length == 0) { return null; }//from ww w . jav a 2 s . c o m Collection<LogEntryKey> list = new ArrayList<LogEntryKey>(array.length); for (String value : array) { list.add(new LogEntryKey(value)); } return list; }
From source file:com.swtxml.util.lang.CollectionUtils.java
/** * Returns a new collection containing the result from * function.apply(element) for all elements from collection. *///from ww w .ja v a 2 s . co m @SuppressWarnings("unchecked") public static <FROM, TO> Collection<TO> collect(Collection<? extends FROM> collection, IFunction<FROM, TO> function) { Collection<TO> resultList = createCollection(collection); for (FROM a : collection) { resultList.add(function.apply(a)); } return resultList; }
From source file:Main.java
public static <T> int addAllThatDontExist(final Collection<T> source, final Collection<T> destination) { int count = 0; for (final T sourceItem : source) { if (!destination.contains(sourceItem)) { destination.add(sourceItem); ++count;//w ww . j av a2 s. c o m } } return count; }
From source file:Main.java
/** * Transfer up to 'maxElems' elements from the source to the destination. *///from w w w .j av a 2s . co m public static void transfer(Collection source, Collection dest, int maxElems) { int j = 0; for (Iterator i = source.iterator(); i.hasNext() && j < maxElems; j++) { dest.add(i.next()); i.remove(); } }
From source file:Main.java
private final static void extractAddedEntries(final Collection<String> oldCollection, final Collection<String> updatedCollection, final Collection<String> addedEntriesCollection) { for (final String entry : updatedCollection) { if (!oldCollection.contains(entry)) { addedEntriesCollection.add(entry); }//from ww w.ja v a 2s . c om } }
From source file:Main.java
private static void extractRemovedEntries(final Collection<String> oldCollection, final Collection<String> updatedCollection, final Collection<String> removedEntriesCollection) { for (final String string : oldCollection) { if (!updatedCollection.contains(string)) { removedEntriesCollection.add(string); }/*from w w w .ja v a 2s . c o m*/ } }
From source file:Main.java
/** * Adds all elements to the {@link Collection}. * @param <T> The type of the {@link Collection}s elements. * @param collection The {@link Collection} to add to. * @param elementsToAdd The elements to add. *///from ww w . java2 s . com public static <T> void addAll(Collection<T> collection, T... elementsToAdd) { if (collection != null && elementsToAdd != null) { for (T toAdd : elementsToAdd) { collection.add(toAdd); } } }