List of usage examples for java.util Collection add
boolean add(E e);
From source file:Main.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static boolean addAll(Collection c, Object... objs) { boolean result = false; for (Object obj : objs) { result |= c.add(obj); }//from w ww. ja v a2s.com return result; }
From source file:net.seedboxer.web.security.SeedBoxerUserDetails.java
private static Collection<? extends GrantedAuthority> createAuthorities(net.seedboxer.core.domain.User user) { Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(new SeedBoxerGrantedAuthority(SeedBoxerAuthority.LEECHER)); if (user.isAdmin()) { authorities.add(new SeedBoxerGrantedAuthority(SeedBoxerAuthority.ADMIN)); }/*from w ww. j a va 2 s . c o m*/ return authorities; }
From source file:Main.java
/** * Adds the given value to the collection if the value satisfies the given predicate. * * @param <E>/*from ww w . jav a 2s .c o m*/ * the collection element type * @param collection * the collection to add the value to * @param value * the value to add * @param predicate * the predicate to test againts the given value * @return <code>true</code>, if the collection has been modified by the operation and <code>false</code> if the * value was <code>null</code> or the collection already contained the value */ public static <E> boolean addIf(Collection<E> collection, E value, Predicate<E> predicate) { if (predicate.test(value)) { return collection.add(value); } return false; }
From source file:Main.java
public static <T> T copyT(Collection<? super T> dest, Collection<T> src) { T last = null;/* w ww . ja va 2s . co m*/ for (T t : src) { last = t; dest.add(t); } return last; }
From source file:Main.java
public static <T> Collection<T> exclude(Collection<T> from, Collection<T> objects) { Collection<T> result = new ArrayList<T>(); for (T t : from) { if (!objects.contains(t)) { result.add(t); }/* w w w . ja v a 2s .c o m*/ } return result; }
From source file:Main.java
/** * Adds the first {@code count} elements of an {@link Iterable} to a {@link Collection}, or all of the elements if * there are fewer than {@code count}.// w w w. jav a 2 s . co m * * @param count * the maximum number of elements to take. * @param i * the {@link Iterable} to take elements from. * @param collection * the {@link Collection} to add the taken elements to. */ public static <T> void take(int count, Iterable<? extends T> i, Collection<T> collection) { for (T t : i) { if (count-- > 0) { collection.add(t); } else { break; } } }
From source file:Main.java
/** * Adds all elements in the array to the given collection. * /* ww w. j a va 2 s . com*/ * @param collection the collection to add to, must not be null * @param elements the array of elements to add, must not be null * @throws NullPointerException if the collection or array is null */ public static <T> void addAll(Collection<T> collection, T[] elements) { for (int i = 0, size = elements.length; i < size; i++) { collection.add(elements[i]); } }
From source file:Main.java
public static Collection toCollection(Iterator iter, Collection c) { if (c == null) c = new ArrayList(); while (iter.hasNext()) c.add(iter.next()); return c;//from w w w.j a va 2 s.co m }
From source file:com.enonic.cms.core.log.LogEntryKey.java
public static Collection<LogEntryKey> convertToList(String key) { Collection<LogEntryKey> list = new ArrayList<LogEntryKey>(1); list.add(new LogEntryKey(key)); return list;//from w w w . j a v a2 s .co m }
From source file:Main.java
final static public Collection createCollection(Object[] objects) { Collection result = createCollection(); for (int i = 0; i < objects.length; i++) { result.add(objects[i]); }// w w w . j a v a 2 s. c o m return result; }