List of usage examples for java.util Collection containsAll
boolean containsAll(Collection<?> c);
From source file:Main.java
/** Test for same elements, regardless of cardinality */ public static <T> boolean sameElts(Collection<T> left, Collection<T> right) { return right.containsAll(left) && left.containsAll(right); }
From source file:Main.java
public static <T> boolean isSubsetOf(Collection<T> a, Collection<T> b) { return (a.size() <= b.size()) && (b.containsAll(a)); }
From source file:Main.java
/** * Checks if the collection contains exactly the given <tt>mustHaveItems</tt>. * //from ww w.j av a2s .c om * <p><b>Examples:</b><br> * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), Arrays.asList(new Integer[] { })) --> false</tt><br> * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), Arrays.asList(new Integer[] { 1, 99 })) --> false</tt><br> * <tt>containsOnly(Arrays.asList(new Integer[] { 1, 2, 3 }), Arrays.asList(new Integer[] { 1, 2, 3 })) --> true</tt> */ public static <T> boolean containsExactly(Collection<T> list, Collection<T> mustHaveItems) { return list.containsAll(mustHaveItems) && mustHaveItems.containsAll(list); }
From source file:Main.java
/** * Return true if <tt>a</tt> contains at least one element * which is not contained in <COCE>b</tt> * * @param a <tt>Collection</tt> to be examined. * @param b <tt>Collection</tt> to be refered to * * @return true if <tt>s</tt> contains at least one elment which is * not contained in <tt>b</tt> *//*from ww w . ja v a 2s.c o m*/ public static boolean hasOtherThan(Collection<?> a, Collection<?> b) { if (a.size() > b.size()) return true; return !b.containsAll(a); }
From source file:com.talis.entity.TestUtils.java
public static void assertQuadCollectionsEqual(Collection<Quad> first, Collection<Quad> second) { assertEquals(first.size(), second.size()); assertTrue(first.containsAll(second)); }
From source file:Main.java
public static boolean equalsIgnoreOrder(Collection<?> c1, Collection<?> c2) { if (c1 == c2) { return true; }//from w w w. jav a2 s.c o m if (c1.size() != c2.size()) { return false; } return c1.containsAll(c2) && c2.containsAll(c1); }
From source file:de.dhke.projects.cutil.collections.MultiMapUtil.java
public static <K, V> boolean deepEquals(MultiMap<K, V> m1, MultiMap<? extends K, ? extends V> m2) { for (Map.Entry<K, Collection<V>> entry1 : m1.entrySet()) { if (!m2.containsKey(entry1.getKey())) return false; else {// ww w.jav a 2 s .com final Collection<? extends V> values2 = m2.get(entry1.getKey()); if ((!entry1.getValue().containsAll(values2)) || (!values2.containsAll(entry1.getValue()))) return false; } } return m1.keySet().containsAll(m2.keySet()); }
From source file:Main.java
/** * Performs a "brute force" comparison of collections by testing whether the collections contain * each other. This circumvents any particular uniqueness or ordering constraints on the * collections (for instance, lists that are unordered but contain the same elements, where a * hashset would not suffice for comparison purposes because it enforces element uniqueness) *///w ww.j a va 2 s . co m public static boolean collectionsEquivalent(Collection<?> a, Collection<?> b) { if (a == null && b == null) { return true; } if (a == null ^ b == null) { return false; } return a.containsAll(b) && b.containsAll(a); }
From source file:Main.java
public static boolean isSameCollection(Collection<?> newCollection, Collection<?> oldCollection) { if (newCollection == null || newCollection.isEmpty()) { return true; } else if (oldCollection != null) { if (newCollection.containsAll(oldCollection) && oldCollection.containsAll(newCollection)) { return true; } else {/*from w w w . j a v a 2 s. c om*/ return false; } } return false; }
From source file:org.openmrs.test.TestUtil.java
License:asdf
/** * Additional assert method for testing that will test that two Collections have equal contents * The Collections must be of equal size, and each object from one Collection must equal an * object in the other Collection Order is not considered. * // w ww. jav a 2 s . c om * @param expected * @param actual */ @SuppressWarnings("unchecked") public static void assertCollectionContentsEquals(Collection expected, Collection actual) throws AssertionError { try { if (!expected.containsAll(actual) || !actual.containsAll(expected)) { throw new AssertionError("Expected " + expected + " but found " + actual); } } catch (Exception e) { throw new AssertionError(e); } }