List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:Main.java
public static <T1> List<T1> allOverlaps(Collection<T1> lst, Collection<T1> lst_) { List<T1> overlaps = new ArrayList<>(); for (T1 elem : lst) { if (lst_.contains(elem)) overlaps.add(elem);//from w ww . j a v a2 s. c o m } return overlaps; }
From source file:Main.java
/** * Checks if the collection contains only the given allowed items. <tt>list</tt> * may contain zero to max(allowedItems) items from allowedItems. * /*from ww w . ja v a2s. c o m*/ * <p><b>Examples:</b><br> * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), Arrays.asList(new Integer[] { })) --> true</tt><br> * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), Arrays.asList(new Integer[] { 1, 2 })) --> false, 3 missing</tt><br> * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), Arrays.asList(new Integer[] { 1, 99 })) --> false, 3 missing</tt> */ public static <T> boolean containsOnly(Collection<T> list, Collection<T> allowedItems) { for (T item : list) { if (!allowedItems.contains(item)) { return false; } } return true; }
From source file:Main.java
/** * Returns all objects in list1 that are not in list2 * * @param <T> Type of items in the collection * @param list1 First collection/*from ww w.j a va 2 s . c o m*/ * @param list2 Second collection * @return The collection difference list1 - list2 */ public static <T> Set<T> diffAsSet(Collection<T> list1, Collection<T> list2) { Set<T> diff = new HashSet<T>(); for (T t : list1) { if (!list2.contains(t)) { diff.add(t); } } return diff; }
From source file:com.creditcloud.common.taglib.Functions.java
/** * ??????./*from w ww. j av a 2 s . c o m*/ * * ???? * * @param all * @param items * @return */ public static boolean containsAny(Collection all, Collection items) { for (Object item : items) { if (all.contains(item)) { return true; } } return false; }
From source file:Main.java
public static void checkCollectionDoesNotContainNull(final Collection<?> collection) { boolean containsNull = false; try {/*ww w.j av a 2s . c o m*/ containsNull = collection.contains(null); } catch (NullPointerException ex) { // Not a problem. } if (containsNull) { throw new NullPointerException(); } }
From source file:Main.java
public static <A> boolean containsAny(Collection<A> as, Collection<A> bs) { boolean result = false; for (A b : bs) if (as.contains(b)) { result = true;//from w w w . j ava 2s .c om break; } return result; }
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);//from ww w. ja v a 2 s . c om } } return result; }
From source file:Main.java
public static <T> Set<T> intersect(Collection<T> set1, Collection<T> set2) { HashSet<T> set = new HashSet<T>(); for (T object : set1) { if (set2.contains(object)) { set.add(object);/*from ww w .j av a 2 s . co m*/ } } return set; }
From source file:Main.java
private static <T> boolean removeAllFromArrayList(ArrayList<T> collection, Collection<?> toRemove) { boolean result = false; for (int i = collection.size(); --i >= 0;) if (toRemove.contains(collection.get(i))) { collection.remove(i);/*from ww w.j a v a 2 s.c o m*/ result = true; } return result; }
From source file:com.netflix.spinnaker.gate.retrofit.UpstreamBadRequest.java
public static Exception classifyError(RetrofitError error, Collection<Integer> supportedHttpStatuses) { if (error.getKind() == HTTP && supportedHttpStatuses.contains(error.getResponse().getStatus())) { return new UpstreamBadRequest(error); } else {/*from ww w . j a v a 2 s . c om*/ return error; } }