List of usage examples for java.util Collection contains
boolean contains(Object o);
From source file:com.igitras.codegen.common.utils.Utils.java
public static <T> boolean checkCollectionEqual(Collection<T> from, Collection<T> to) { if (from == null) { from = Collections.emptySet(); }/* w ww . j a v a 2s .c o m*/ if (to == null) { to = Collections.emptySet(); } for (T t : from) { if (!to.contains(t)) { return false; } } for (T t : to) { if (!from.contains(t)) { return false; } } return true; }
From source file:CollectionUtils.java
/** * Return the first element in '<code>candidates</code>' that is contained in * '<code>source</code>'. If no element in '<code>candidates</code>' is present in * '<code>source</code>' returns <code>null</code>. Iteration order is * {@link Collection} implementation specific. * @param source the source Collection/* w ww. j a v a 2 s .c o m*/ * @param candidates the candidates to search for * @return the first present object, or <code>null</code> if not found */ public static Object findFirstMatch(Collection source, Collection candidates) { if (isEmpty(source) || isEmpty(candidates)) { return null; } for (Iterator it = candidates.iterator(); it.hasNext();) { Object candidate = it.next(); if (source.contains(candidate)) { return candidate; } } return null; }
From source file:Main.java
/** * /* www . j a va 2 s. c o m*/ * @param c1 * @param s1 * @return c1 - s1 * */ public static <T> List<T> minius(Collection<T> c1, Collection<T> s1) { if (c1 == null) { return Collections.emptyList(); } if (s1 == null || s1.size() == 0) { return new ArrayList<T>(c1); } List<T> list = new ArrayList<T>(); for (T t : c1) { if (!s1.contains(t)) { list.add(t); } } return list; }
From source file:com.screenslicer.core.nlp.NlpUtil.java
public static boolean hasStem(String query, String target) { if (hasStemCache.size() > MAX_CACHE) { hasStemCache.clear();//from w ww . j a v a2 s .c o m } String cacheKey = query + "<<>>" + target; if (hasStemCache.containsKey(cacheKey)) { return hasStemCache.get(cacheKey); } Collection<String> queryStems = stems(query, false, false); Collection<String> targetStems = stems(target, !stems(query, true, false).isEmpty(), false); for (String cur : queryStems) { if (targetStems.contains(cur)) { hasStemCache.put(cacheKey, true); return true; } } hasStemCache.put(cacheKey, false); return false; }
From source file:Main.java
public static <T extends Object> int countIntersection(Collection<? extends T> s1, Collection<? extends T> s2) { if (s1 == null || s2 == null) return 0; int n1 = s1.size(); int n2 = s2.size(); if (n2 < n1) { Collection<? extends T> t = s1; s1 = s2;/*from ww w . j a va2 s .co m*/ s2 = t; } int n = 0; for (T e : s1) { if (s2.contains(e)) n++; } return n; }
From source file:com.abiquo.server.core.util.network.IPAddress.java
public static boolean isIntoRange(Collection<IPAddress> range, String address) { IPAddress ip = newIPAddress(address); return range.contains(ip); }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil.java
public static <T> boolean disjoint(Collection<T> c1, Collection<T> c2) { for (T m : c1) { if (c2.contains(m)) { return false; }// w w w .j av a2 s .co m } return true; }
From source file:com.yunmel.syncretic.utils.commons.CollectionsUtils.java
/** * abList./*w w w . j a va 2 s. c o m*/ */ public static <T> List<T> intersection(Collection<T> a, Collection<T> b) { List<T> list = Lists.newArrayList(); for (T element : a) { if (b.contains(element)) { list.add(element); } } return list; }
From source file:annis.gui.flatquerybuilder.SpanBox.java
public static void buildBoxValues(ComboBox cb, String level, FlatQueryBuilder sq) { String value = (cb.getValue() != null) ? cb.getValue().toString() : ""; Collection<String> annovals = sq.getAnnotationValues(level); cb.removeAllItems();/*from w w w. ja va 2 s. c o m*/ for (String s : annovals) { cb.addItem(s); } if (annovals.contains(value)) { cb.setValue(value); } else { cb.setValue(null); } }
From source file:com.insightml.utils.Collections.java
public static <I> Set<I> matches(final Collection<I> col1, final Collection<I> col2) { final Set<I> builder = new HashSet<>(); for (final I item : col1) { if (col2.contains(item)) { builder.add(item);//from ww w. j ava 2s.c o m } } return builder; }