cardinalityB;
+
+ /**
+ * Create a new CardinalityHelper for two collections.
+ *
+ * @param a the first collection
+ * @param b the second collection
+ */
+ public CardinalityHelper(final Iterable extends O> a, final Iterable extends O> b) {
+ cardinalityA = CollectionUtils.getCardinalityMap(a);
+ cardinalityB = CollectionUtils.getCardinalityMap(b);
+ }
+
+ /**
+ * Returns the frequency of this object in collection A.
+ *
+ * @param obj the object
+ * @return the frequency of the object in collection A
+ */
+ public int freqA(final Object obj) {
+ return getFreq(obj, cardinalityA);
+ }
+
+ /**
+ * Returns the frequency of this object in collection B.
+ *
+ * @param obj the object
+ * @return the frequency of the object in collection B
+ */
+ public int freqB(final Object obj) {
+ return getFreq(obj, cardinalityB);
+ }
+
+ private int getFreq(final Object obj, final Map, Integer> freqMap) {
+ final Integer count = freqMap.get(obj);
+ if (count != null) {
+ return count;
+ }
+ return 0;
+ }
+ }
+
+ /**
+ * returns {@code true} iff the given {@link Collection}s contain
+ * exactly the same elements with exactly the same cardinalities.
+ *
+ * @param a the first collection
+ * @param b the second collection
+ * @return Returns true iff the given Collections contain exactly the same elements with exactly the same cardinalities.
+ * That is, iff the cardinality of e in a is equal to the cardinality of e in b, for each element e in a or b.
+ */
+ public static boolean equalLists(Collection> a, Collection> b) {
+ if (a == null && b == null) {
+ return true;
+ }
+
+ if (a == null || b == null) {
+ return false;
+ }
+
+ return isEqualCollection(a, b);
+ }
+
+ /**
+ * Returns {@code true} iff the given {@link Collection}s contain
+ * exactly the same elements with exactly the same cardinalities.
+ *
+ * That is, iff the cardinality of e in a is
+ * equal to the cardinality of e in b,
+ * for each element e in a or b.
+ *
+ * @param a the first collection, must not be null
+ * @param b the second collection, must not be null
+ * @return true
iff the collections contain the same elements with the same cardinalities.
+ */
+ public static boolean isEqualCollection(final Collection> a, final Collection> b) {
+ if (a.size() != b.size()) {
+ return false;
+ }
+ final CardinalityHelper