List of usage examples for java.util Collection add
boolean add(E e);
From source file:Main.java
public static <T> List<Collection<T>> splitCollection(Collection<T> col, int numLists) throws InstantiationException, IllegalAccessException { List<Collection<T>> lstReturn = new ArrayList<Collection<T>>(); Iterator<T> iter = col.iterator(); for (int c = 0; c < numLists; c++) { Collection<T> temp = col.getClass().newInstance(); lstReturn.add(temp);/*from w w w .j a va 2 s .c o m*/ } while (iter.hasNext()) { for (int collectionIndex = 0; collectionIndex < numLists; collectionIndex++) { if (iter.hasNext()) { Collection<T> current = lstReturn.get(collectionIndex); T value = iter.next(); current.add(value); } } } return lstReturn; }
From source file:Main.java
/** * This function filters the input collection and returns a collection of elements starting with specified input. * @param coll//from w w w .j av a2s . c om * @param str * @return Filtered Collection<String> */ public static Collection<String> startsWithString(Collection<String> coll, final String str) { Collection<String> list = new ArrayList<String>(); for (String item : coll) { if (item.startsWith(str)) { list.add(item); } } return list; }
From source file:Main.java
public static <T> void addAllInReverseOrder(Collection<T> destination, List<T> source) { for (int i = source.size() - 1; i >= 0; i--) { T object = source.get(i);//from ww w . j a va2 s . c o m destination.add(object); } }
From source file:Main.java
public static <T> void addAll(Collection<T> col, T[] arr) { if (isEmpty(arr)) { return;/*ww w .ja va 2 s.c om*/ } for (T val : arr) { col.add(val); } }
From source file:Main.java
static Collection<URL> allSdks() throws MalformedURLException { URL androidSDKs = new File(System.getProperty("test.all.android.sdks.home")).toURI().toURL(); Collection<URL> sdks = new ArrayList<URL>(); // sdks.add(new URL(androidSDKs, "platforms/android-1.5/")); sdks.add(new URL(androidSDKs, "add-ons/addon_google_apis_google_inc_3/")); // sdks.add(new URL(androidSDKs, "platforms/android-1.6/")); sdks.add(new URL(androidSDKs, "add-ons/addon_google_apis_google_inc_4/")); sdks.add(new URL(androidSDKs, "platforms/android-7/")); sdks.add(new URL(androidSDKs, "add-ons/addon_google_apis_google_inc_7/")); sdks.add(new URL(androidSDKs, "platforms/android-8/")); sdks.add(new URL(androidSDKs, "add-ons/addon_google_apis_google_inc_8/")); return sdks;//from w ww . j ava2 s. com }
From source file:com.github.persapiens.jsfboot.security.AuthenticationFactory.java
private static Collection<? extends GrantedAuthority> grantedAuthorities(String... authorities) { Collection<SimpleGrantedAuthority> result = new HashSet<>(); for (String authority : authorities) { result.add(new SimpleGrantedAuthority(authority)); }//from w w w. ja v a 2 s.c om return result; }
From source file:Main.java
/** * Utility for adding an iterable to a collection. * * @param t1 The collection to add to// w w w . j av a2 s .c o m * @param t2 The iterable to add each item of to the collection * @param <T> The element type of t1 * @return t1 */ public static <T> Collection<T> addAll(Collection<T> t1, Iterable<? extends T> t2) { for (T t : t2) { t1.add(t); } return t1; }
From source file:Main.java
public static <S, T> Collection<T> filter(Class<T> target, S... sourceCollection) { Collection<T> filtered = new ArrayList<T>(); for (S source : sourceCollection) if (source.getClass() == target) filtered.add((T) source); return filtered; }
From source file:com.talis.entity.TestUtils.java
public static void assertQuadIterablesEqual(Iterable<Quad> first, Iterable<Quad> second) { Collection<Quad> a = new HashSet<Quad>(); for (Quad q : first) { a.add(q); }// w w w . j a v a 2 s . c o m Collection<Quad> b = new HashSet<Quad>(); for (Quad q : second) { b.add(q); } assertQuadCollectionsEqual(a, b); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <S, T> Collection<T> filter(Class<T> target, Collection<S> sourceCollection) { Collection<T> filtered = new ArrayList<T>(); for (S source : sourceCollection) if (source.getClass() == target) filtered.add((T) source); return filtered; }