List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:apm.common.utils.Collections3.java
/** * abList.//from w w w.j av a 2 s. c o m */ public static <T> List<T> intersection(Collection<T> a, Collection<T> b) { List<T> list = new ArrayList<T>(); for (T element : a) { if (b.contains(element)) { list.add(element); } } return list; }
From source file:com.logsniffer.web.tags.JstlFunctionsLibrary.java
/** * Returns true if value is contained in given collection. * //w ww .j a v a 2s . co m * @param collection * @param value * @return true if value is contained in given collection */ public static boolean contains(final Collection<Object> list, final Object value) { return list != null && value != null && list.contains(value); }
From source file:Main.java
/** * Returns <code>true</code> iff some element of <i>a</i> is also an element * of <i>b</i> (or, equivalently, if some element of <i>b</i> is also an * element of <i>a</i>). In other words, this method returns * <code>true</code> iff the {@link #intersection} of <i>a</i> and <i>b</i> * is not empty./*w ww . j av a2s. c om*/ * * @since 2.1 * @param a * a non-<code>null</code> Collection * @param b * a non-<code>null</code> Collection * @return <code>true</code> iff the intersection of <i>a</i> and <i>b</i> * is non-empty * @see #intersection */ public static boolean containsAny(final Collection a, final Collection b) { // TO DO: we may be able to optimize this by ensuring either a or b // is the larger of the two Collections, but I'm not sure which. for (Iterator iter = a.iterator(); iter.hasNext();) { if (b.contains(iter.next())) { return true; } } return false; }
From source file:Main.java
/** * Return {@code true} if any element in '{@code candidates}' is contained in * '{@code source}', otherwise returns {@code false}. * // ww w .j a va 2 s . c om * @param source * the source Collection. * @param candidates * the candidates to search for. * @return whether any of the candidates has been found. */ public static boolean containsAny(Collection<?> source, Object... candidates) { if (source == null || source.isEmpty() || candidates == null || candidates.length == 0) { return false; } for (Object candidate : candidates) { if (source.contains(candidate)) { return true; } } return false; }
From source file:byps.http.HActiveMessage.java
private static ArrayList<Long> evalM1AndM2(Collection<Long> m1, Collection<Long> m2) { ArrayList<Long> arr = new ArrayList<Long>(); for (Long streamId : m1) { if (m2.contains(streamId)) arr.add(streamId);//from w w w. j ava2 s. c om } return arr; }
From source file:com.parse.ParseJSONUtils.java
/** * Creates a copy of {@code copyFrom}, excluding the keys from {@code excludes}. *//*from w w w . j av a2s.c o m*/ public static JSONObject create(JSONObject copyFrom, Collection<String> excludes) { JSONObject json = new JSONObject(); Iterator<String> iterator = copyFrom.keys(); while (iterator.hasNext()) { String name = iterator.next(); if (excludes.contains(name)) { continue; } try { json.put(name, copyFrom.opt(name)); } catch (JSONException e) { // This shouldn't ever happen since it'll only throw if `name` is null throw new RuntimeException(e); } } return json; }
From source file:Main.java
/** * Return the first element in '{@code candidates}' that is contained in * '{@code source}'. If no element in '{@code candidates}' is present in * '{@code source}' returns {@code null}. Iteration order is * {@link Collection} implementation specific. * * @param source the source Collection * @param candidates the candidates to search for * @return the first present object, or {@code null} if not found *//*w w w. j a va 2 s .c o m*/ @SuppressWarnings("unchecked") public static <E> E findFirstMatch(Collection<?> source, Collection<E> candidates) { if (isEmpty(source) || isEmpty(candidates)) { return null; } for (Object candidate : candidates) { if (source.contains(candidate)) { return (E) candidate; } } return null; }
From source file:$.Collections3.java
/** * abList.//from ww w .ja v a2s . co m */ public static <T> List<T> intersection(Collection<T> a, Collection<T> b) { List<T> list = new ArrayList<T>(); for (T element : a) { if (b.contains(element)) { list.add(element); } } return list; }
From source file:Main.java
/** * Return {@code true} if any element in '{@code candidates}' is * contained in '{@code source}'; otherwise returns {@code false}. * * @param source the source Collection * @param candidates the candidates to search for * @return whether any of the candidates has been found *//* w w w. j a va 2 s.c o m*/ public static boolean containsAny(Collection<?> source, Collection<?> candidates) { if (isEmpty(source) || isEmpty(candidates)) { return false; } for (Object candidate : candidates) { if (source.contains(candidate)) { return true; } } return false; }
From source file:org.hdiv.web.servlet.tags.form.SelectedValueComparatorHDIV.java
private static boolean collectionCompare(Collection boundCollection, Object candidateValue, BindStatus bindStatus) {// w w w. jav a 2 s. c o m try { if (boundCollection.contains(candidateValue)) { return true; } } catch (ClassCastException ex) { // Probably from a TreeSet - ignore. } return exhaustiveCollectionCompare(boundCollection, candidateValue, bindStatus); }