From a5707737afbb3b3b7acd572c3921df5452f444f9 Mon Sep 17 00:00:00 2001 From: navyacodes Date: Tue, 4 Aug 2026 02:21:54 -0700 Subject: [PATCH 1/8] added asCollection and collectionFraction to util --- src/arcade/core/util/Utilities.java | 46 +++++ test/arcade/core/util/UtilitiesTest.java | 214 +++++++++++++++++++++++ 2 files changed, 260 insertions(+) diff --git a/src/arcade/core/util/Utilities.java b/src/arcade/core/util/Utilities.java index c4c6c0355..768ef8bab 100644 --- a/src/arcade/core/util/Utilities.java +++ b/src/arcade/core/util/Utilities.java @@ -1,7 +1,10 @@ package arcade.core.util; import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.ListIterator; +import sim.util.Bag; import ec.util.MersenneTwisterFast; /** Container class for utility methods. */ @@ -65,4 +68,47 @@ static void swap(Object[] arr, int i, int j) { arr[i] = arr[j]; arr[j] = temp; } + + /** + * Calculates the fraction of elements in one collection that are also present in another + * collection. Returns 0 if either list is empty. + * + * @param collection1 the collection whose fraction is being calculated (denominator) + * @param collection2 the collection to check membership against, items be the same type as + * collection1 + * @return fraction of elements in collection1 that are also found in collection2 + */ + public static double collectionFraction( + Collection collection1, Collection collection2) { + if (collection1.isEmpty() || collection2.isEmpty()) { + return 0; + } + double elementCount = 0; + for (T item : collection1) { + for (Object obj : collection2) { + if (item.equals(obj)) { + elementCount++; + break; + } + } + } + return elementCount / collection1.size(); + } + + /** + * Converts the given Bag into a typed Collection, with each element being cast to the given + * type. Insertion order is preserved. + * + * @param bag the bag to convert + * @param type the class object representing the target element type + * @return a new Collection containing the bag's elements, cast to provided type + * @param the target element type + */ + public static Collection asCollection(Bag bag, Class type) { + List list = new ArrayList<>(bag.numObjs); + for (int i = 0; i < bag.numObjs; i++) { + list.add(type.cast(bag.objs[i])); + } + return list; + } } diff --git a/test/arcade/core/util/UtilitiesTest.java b/test/arcade/core/util/UtilitiesTest.java index 2773043d5..fc702b2be 100644 --- a/test/arcade/core/util/UtilitiesTest.java +++ b/test/arcade/core/util/UtilitiesTest.java @@ -1,8 +1,11 @@ package arcade.core.util; import java.util.ArrayList; +import java.util.Collection; import java.util.Comparator; +import java.util.List; import org.junit.jupiter.api.Test; +import sim.util.Bag; import ec.util.MersenneTwisterFast; import static org.junit.jupiter.api.Assertions.*; import static arcade.core.ARCADETestUtilities.*; @@ -94,4 +97,215 @@ public void shuffleList_givenSameSeed_shufflesSame() { // Check that both shuffled lists are the same. assertEquals(list1, list2); } + + @Test + public void collectionFraction_emptyLists_returnsZero() { + List list1 = new ArrayList<>(); + List list2 = new ArrayList<>(); + + double fraction = collectionFraction(list1, list2); + + assertEquals(0, fraction); + } + + @Test + public void collectionFraction_noOverlapWithList2_returnsZero() { + List items = new ArrayList<>(); + items.add(1); + items.add(2); + + ArrayList otherItems = new ArrayList<>(List.of(3)); + + double fraction = collectionFraction(items, otherItems); + + assertEquals(0, fraction); + } + + @Test + public void collectionFraction_allElementsInList2_returnsOne() { + List items = new ArrayList<>(); + String a = "a"; + String b = "b"; + items.add(a); + items.add(b); + + ArrayList otherItems = new ArrayList<>(List.of(a, b)); + + double fraction = collectionFraction(items, otherItems); + + assertEquals(1, fraction); + } + + @Test + public void collectionFraction_someElementsInList2_returnsPartialFraction() { + List items = new ArrayList<>(); + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + items.add(a); + items.add(b); + items.add(c); + items.add(d); + + ArrayList otherItems = new ArrayList<>(List.of(a, c)); + + double fraction = collectionFraction(items, otherItems); + + assertEquals(0.5, fraction); + } + + @Test + public void collectionFraction_emptyEitherList_returnsZero() { + List items = new ArrayList<>(); + items.add("a"); + items.add("b"); + + double fraction = collectionFraction(items, new ArrayList()); + + assertEquals(0, fraction); + assertEquals(0, collectionFraction(new ArrayList(), items)); + } + + @Test + public void collectionFraction_differentEqualObjects_countsAsMatch() { + List items = new ArrayList<>(); + String a = "a"; + String b = "b"; + String c = "c"; + String d = "d"; + items.add(a); + items.add(b); + items.add(c); + items.add(d); + ArrayList otherItems = new ArrayList<>(List.of(new String("a"))); + + double fraction = collectionFraction(items, otherItems); + + assertEquals(0.25, fraction); + } + + @Test + public void collectionFraction_oneOfSevenMatch_returnsPreciseFraction() { + List items = new ArrayList<>(); + Integer a = 0; + for (int i = 1; i <= 6; i++) { + items.add(i); + } + items.add(a); + + ArrayList otherItems = new ArrayList<>(List.of(a)); + + double fraction = collectionFraction(items, otherItems); + + assertEquals(1.0 / 7.0, fraction, EPSILON); + } + + @Test + public void collectionFraction_sameCollectionPassed_returnsOne() { + List items = new ArrayList<>(); + for (int i = 1; i <= 6; i++) { + items.add(i); + } + + double fraction = collectionFraction(items, items); + + assertEquals(1, fraction, EPSILON); + } + + @Test + public void asCollection_emptyBag_returnsEmptyCollection() { + Bag bag = new Bag(); + + Collection result = asCollection(bag, String.class); + + assertTrue(result.isEmpty()); + } + + @Test + public void asCollection_populatedBag_returnsAllElementsInOrder() { + Bag bag = new Bag(); + String a = "a"; + String b = "b"; + String c = "c"; + bag.add(a); + bag.add(b); + bag.add(c); + + Collection result = asCollection(bag, String.class); + + assertEquals(3, result.size()); + java.util.Iterator it = result.iterator(); + assertEquals(a, it.next()); + assertEquals(b, it.next()); + assertEquals(c, it.next()); + } + + @Test + public void asCollection_bagWithExcessCapacity_onlyIncludesNumObjsElements() { + Bag bag = new Bag(10); + String a = "a"; + bag.add(a); + + Collection result = asCollection(bag, String.class); + + assertEquals(1, result.size()); + assertEquals(a, result.iterator().next()); + } + + @Test + public void asCollection_wrongElementType_throwsClassCastException() { + Bag bag = new Bag(); + bag.add(1); + + assertThrows(ClassCastException.class, () -> asCollection(bag, String.class)); + } + + @Test + public void asCollection_mixedElementTypes_throwsOnFirstMismatch() { + Bag bag = new Bag(); + bag.add("a"); + bag.add(1); + + assertThrows(ClassCastException.class, () -> asCollection(bag, String.class)); + } + + @Test + public void asCollection_duplicateElements_preservesDuplicates() { + Bag bag = new Bag(); + String a = "a"; + bag.add(a); + bag.add(a); + + Collection result = asCollection(bag, String.class); + + assertEquals(2, result.size()); + } + + @Test + public void asCollection_bagWithNullElement_includesNull() { + Bag bag = new Bag(); + bag.add(null); + + Collection result = asCollection(bag, String.class); + + assertEquals(1, result.size()); + assertNull(result.iterator().next()); + } + + @Test + public void asCollection_resultUsableWithCollectionFraction_computesCorrectFraction() { + Bag itemBag = new Bag(); + String a = "a"; + String b = "b"; + itemBag.add(a); + itemBag.add(b); + + List otherItems = new ArrayList<>(List.of(a)); + + Collection items = asCollection(itemBag, String.class); + double fraction = collectionFraction(new ArrayList<>(items), otherItems); + + assertEquals(0.5, fraction); + } } From 536c7027f3b18a14d4931e16d00ca5bdf8ee50cb Mon Sep 17 00:00:00 2001 From: navyacodes Date: Tue, 4 Aug 2026 02:26:50 -0700 Subject: [PATCH 2/8] fixed a comment --- src/arcade/core/util/Utilities.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arcade/core/util/Utilities.java b/src/arcade/core/util/Utilities.java index 768ef8bab..ea08e2706 100644 --- a/src/arcade/core/util/Utilities.java +++ b/src/arcade/core/util/Utilities.java @@ -77,6 +77,7 @@ static void swap(Object[] arr, int i, int j) { * @param collection2 the collection to check membership against, items be the same type as * collection1 * @return fraction of elements in collection1 that are also found in collection2 + * @param the element type present in the two collections */ public static double collectionFraction( Collection collection1, Collection collection2) { From 0fce1178f010d5573773b02fefdb3eca9d649ec6 Mon Sep 17 00:00:00 2001 From: Navya Jain <96959259+navyacodes@users.noreply.github.com> Date: Sun, 9 Aug 2026 23:43:00 -0700 Subject: [PATCH 3/8] moved Java generic param tag up to appropriate location --- src/arcade/core/util/Utilities.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arcade/core/util/Utilities.java b/src/arcade/core/util/Utilities.java index ea08e2706..f424e76af 100644 --- a/src/arcade/core/util/Utilities.java +++ b/src/arcade/core/util/Utilities.java @@ -73,11 +73,11 @@ static void swap(Object[] arr, int i, int j) { * Calculates the fraction of elements in one collection that are also present in another * collection. Returns 0 if either list is empty. * + * @param the element type present in the two collections * @param collection1 the collection whose fraction is being calculated (denominator) * @param collection2 the collection to check membership against, items be the same type as * collection1 * @return fraction of elements in collection1 that are also found in collection2 - * @param the element type present in the two collections */ public static double collectionFraction( Collection collection1, Collection collection2) { @@ -100,10 +100,10 @@ public static double collectionFraction( * Converts the given Bag into a typed Collection, with each element being cast to the given * type. Insertion order is preserved. * + * @param the target element type * @param bag the bag to convert * @param type the class object representing the target element type * @return a new Collection containing the bag's elements, cast to provided type - * @param the target element type */ public static Collection asCollection(Bag bag, Class type) { List list = new ArrayList<>(bag.numObjs); From 920362f3bc147fdadda52ae2c0141fe43fb96ce7 Mon Sep 17 00:00:00 2001 From: navyacodes Date: Tue, 25 Aug 2026 00:20:27 -0700 Subject: [PATCH 4/8] changed method and parameter names to be more descriptive; changed parameter names to be in logical order (numerator, then denominator) --- src/arcade/core/util/Utilities.java | 25 ++++----- test/arcade/core/util/UtilitiesTest.java | 69 ++++++++++++------------ 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/arcade/core/util/Utilities.java b/src/arcade/core/util/Utilities.java index f424e76af..14559aecc 100644 --- a/src/arcade/core/util/Utilities.java +++ b/src/arcade/core/util/Utilities.java @@ -74,38 +74,39 @@ static void swap(Object[] arr, int i, int j) { * collection. Returns 0 if either list is empty. * * @param the element type present in the two collections - * @param collection1 the collection whose fraction is being calculated (denominator) - * @param collection2 the collection to check membership against, items be the same type as - * collection1 - * @return fraction of elements in collection1 that are also found in collection2 + * @param numeratorCollection the collection to check membership against, items be the same type + * as denominatorCollection + * @param denominatorCollection the collection whose fraction is being calculated (denominator) + * @return fraction of elements in denominatorCollection that are also found in + * numeratorCollection */ - public static double collectionFraction( - Collection collection1, Collection collection2) { - if (collection1.isEmpty() || collection2.isEmpty()) { + public static double getCollectionFraction( + Collection numeratorCollection, Collection denominatorCollection) { + if (denominatorCollection.isEmpty() || numeratorCollection.isEmpty()) { return 0; } double elementCount = 0; - for (T item : collection1) { - for (Object obj : collection2) { + for (T item : denominatorCollection) { + for (Object obj : numeratorCollection) { if (item.equals(obj)) { elementCount++; break; } } } - return elementCount / collection1.size(); + return elementCount / denominatorCollection.size(); } /** * Converts the given Bag into a typed Collection, with each element being cast to the given - * type. Insertion order is preserved. + * type. * * @param the target element type * @param bag the bag to convert * @param type the class object representing the target element type * @return a new Collection containing the bag's elements, cast to provided type */ - public static Collection asCollection(Bag bag, Class type) { + public static Collection convertToCollection(Bag bag, Class type) { List list = new ArrayList<>(bag.numObjs); for (int i = 0; i < bag.numObjs; i++) { list.add(type.cast(bag.objs[i])); diff --git a/test/arcade/core/util/UtilitiesTest.java b/test/arcade/core/util/UtilitiesTest.java index fc702b2be..7e06d159f 100644 --- a/test/arcade/core/util/UtilitiesTest.java +++ b/test/arcade/core/util/UtilitiesTest.java @@ -99,30 +99,30 @@ public void shuffleList_givenSameSeed_shufflesSame() { } @Test - public void collectionFraction_emptyLists_returnsZero() { + public void getCollectionFraction_emptyLists_returnsZero() { List list1 = new ArrayList<>(); List list2 = new ArrayList<>(); - double fraction = collectionFraction(list1, list2); + double fraction = getCollectionFraction(list1, list2); assertEquals(0, fraction); } @Test - public void collectionFraction_noOverlapWithList2_returnsZero() { + public void getCollectionFraction_noOverlapWithList2_returnsZero() { List items = new ArrayList<>(); items.add(1); items.add(2); ArrayList otherItems = new ArrayList<>(List.of(3)); - double fraction = collectionFraction(items, otherItems); + double fraction = getCollectionFraction(otherItems, items); assertEquals(0, fraction); } @Test - public void collectionFraction_allElementsInList2_returnsOne() { + public void getCollectionFraction_allElementsInList2_returnsOne() { List items = new ArrayList<>(); String a = "a"; String b = "b"; @@ -131,13 +131,13 @@ public void collectionFraction_allElementsInList2_returnsOne() { ArrayList otherItems = new ArrayList<>(List.of(a, b)); - double fraction = collectionFraction(items, otherItems); + double fraction = getCollectionFraction(otherItems, items); assertEquals(1, fraction); } @Test - public void collectionFraction_someElementsInList2_returnsPartialFraction() { + public void getCollectionFraction_someElementsInList2_returnsPartialFraction() { List items = new ArrayList<>(); String a = "a"; String b = "b"; @@ -150,25 +150,25 @@ public void collectionFraction_someElementsInList2_returnsPartialFraction() { ArrayList otherItems = new ArrayList<>(List.of(a, c)); - double fraction = collectionFraction(items, otherItems); + double fraction = getCollectionFraction(otherItems, items); assertEquals(0.5, fraction); } @Test - public void collectionFraction_emptyEitherList_returnsZero() { + public void getCollectionFraction_emptyEitherList_returnsZero() { List items = new ArrayList<>(); items.add("a"); items.add("b"); - double fraction = collectionFraction(items, new ArrayList()); + double fraction = getCollectionFraction(new ArrayList(), items); assertEquals(0, fraction); - assertEquals(0, collectionFraction(new ArrayList(), items)); + assertEquals(0, getCollectionFraction(items, new ArrayList())); } @Test - public void collectionFraction_differentEqualObjects_countsAsMatch() { + public void getCollectionFraction_differentEqualObjects_countsAsMatch() { List items = new ArrayList<>(); String a = "a"; String b = "b"; @@ -180,13 +180,13 @@ public void collectionFraction_differentEqualObjects_countsAsMatch() { items.add(d); ArrayList otherItems = new ArrayList<>(List.of(new String("a"))); - double fraction = collectionFraction(items, otherItems); + double fraction = getCollectionFraction(otherItems, items); assertEquals(0.25, fraction); } @Test - public void collectionFraction_oneOfSevenMatch_returnsPreciseFraction() { + public void getCollectionFraction_oneOfSevenMatch_returnsPreciseFraction() { List items = new ArrayList<>(); Integer a = 0; for (int i = 1; i <= 6; i++) { @@ -196,34 +196,34 @@ public void collectionFraction_oneOfSevenMatch_returnsPreciseFraction() { ArrayList otherItems = new ArrayList<>(List.of(a)); - double fraction = collectionFraction(items, otherItems); + double fraction = getCollectionFraction(otherItems, items); assertEquals(1.0 / 7.0, fraction, EPSILON); } @Test - public void collectionFraction_sameCollectionPassed_returnsOne() { + public void getCollectionFraction_sameCollectionPassed_returnsOne() { List items = new ArrayList<>(); for (int i = 1; i <= 6; i++) { items.add(i); } - double fraction = collectionFraction(items, items); + double fraction = getCollectionFraction(items, items); assertEquals(1, fraction, EPSILON); } @Test - public void asCollection_emptyBag_returnsEmptyCollection() { + public void convertToCollection_emptyBag_returnsEmptyCollection() { Bag bag = new Bag(); - Collection result = asCollection(bag, String.class); + Collection result = convertToCollection(bag, String.class); assertTrue(result.isEmpty()); } @Test - public void asCollection_populatedBag_returnsAllElementsInOrder() { + public void convertToCollection_populatedBag_returnsAllElementsInOrder() { Bag bag = new Bag(); String a = "a"; String b = "b"; @@ -232,7 +232,7 @@ public void asCollection_populatedBag_returnsAllElementsInOrder() { bag.add(b); bag.add(c); - Collection result = asCollection(bag, String.class); + Collection result = convertToCollection(bag, String.class); assertEquals(3, result.size()); java.util.Iterator it = result.iterator(); @@ -242,59 +242,60 @@ public void asCollection_populatedBag_returnsAllElementsInOrder() { } @Test - public void asCollection_bagWithExcessCapacity_onlyIncludesNumObjsElements() { + public void convertToCollection_bagWithExcessCapacity_onlyIncludesNumObjsElements() { Bag bag = new Bag(10); String a = "a"; bag.add(a); - Collection result = asCollection(bag, String.class); + Collection result = convertToCollection(bag, String.class); assertEquals(1, result.size()); assertEquals(a, result.iterator().next()); } @Test - public void asCollection_wrongElementType_throwsClassCastException() { + public void convertToCollection_wrongElementType_throwsClassCastException() { Bag bag = new Bag(); bag.add(1); - assertThrows(ClassCastException.class, () -> asCollection(bag, String.class)); + assertThrows(ClassCastException.class, () -> convertToCollection(bag, String.class)); } @Test - public void asCollection_mixedElementTypes_throwsOnFirstMismatch() { + public void convertToCollection_mixedElementTypes_throwsOnFirstMismatch() { Bag bag = new Bag(); bag.add("a"); bag.add(1); - assertThrows(ClassCastException.class, () -> asCollection(bag, String.class)); + assertThrows(ClassCastException.class, () -> convertToCollection(bag, String.class)); } @Test - public void asCollection_duplicateElements_preservesDuplicates() { + public void convertToCollection_duplicateElements_preservesDuplicates() { Bag bag = new Bag(); String a = "a"; bag.add(a); bag.add(a); - Collection result = asCollection(bag, String.class); + Collection result = convertToCollection(bag, String.class); assertEquals(2, result.size()); } @Test - public void asCollection_bagWithNullElement_includesNull() { + public void convertToCollection_bagWithNullElement_includesNull() { Bag bag = new Bag(); bag.add(null); - Collection result = asCollection(bag, String.class); + Collection result = convertToCollection(bag, String.class); assertEquals(1, result.size()); assertNull(result.iterator().next()); } @Test - public void asCollection_resultUsableWithCollectionFraction_computesCorrectFraction() { + public void + convertToCollection_resultUsableWithGetCollectionFraction_computesCorrectFraction() { Bag itemBag = new Bag(); String a = "a"; String b = "b"; @@ -303,8 +304,8 @@ public void asCollection_resultUsableWithCollectionFraction_computesCorrectFract List otherItems = new ArrayList<>(List.of(a)); - Collection items = asCollection(itemBag, String.class); - double fraction = collectionFraction(new ArrayList<>(items), otherItems); + Collection items = convertToCollection(itemBag, String.class); + double fraction = getCollectionFraction(otherItems, new ArrayList<>(items)); assertEquals(0.5, fraction); } From db4d34f4c54ceee2c20535890e2e9cf959167a5b Mon Sep 17 00:00:00 2001 From: navyacodes Date: Tue, 25 Aug 2026 00:22:40 -0700 Subject: [PATCH 5/8] changed variable name for clarity --- src/arcade/core/util/Utilities.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arcade/core/util/Utilities.java b/src/arcade/core/util/Utilities.java index 14559aecc..fd7071bf7 100644 --- a/src/arcade/core/util/Utilities.java +++ b/src/arcade/core/util/Utilities.java @@ -85,16 +85,16 @@ public static double getCollectionFraction( if (denominatorCollection.isEmpty() || numeratorCollection.isEmpty()) { return 0; } - double elementCount = 0; + double overlap = 0; for (T item : denominatorCollection) { for (Object obj : numeratorCollection) { if (item.equals(obj)) { - elementCount++; + overlap++; break; } } } - return elementCount / denominatorCollection.size(); + return overlap / denominatorCollection.size(); } /** From 4b92aaa2bc4ee4a1520c569601cebcdb440adfd5 Mon Sep 17 00:00:00 2001 From: navyacodes Date: Tue, 25 Aug 2026 11:00:22 -0700 Subject: [PATCH 6/8] reduced O of getCollectionFraction --- src/arcade/core/util/Utilities.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/arcade/core/util/Utilities.java b/src/arcade/core/util/Utilities.java index fd7071bf7..9dd76823c 100644 --- a/src/arcade/core/util/Utilities.java +++ b/src/arcade/core/util/Utilities.java @@ -1,9 +1,6 @@ package arcade.core.util; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.ListIterator; +import java.util.*; import sim.util.Bag; import ec.util.MersenneTwisterFast; @@ -86,12 +83,10 @@ public static double getCollectionFraction( return 0; } double overlap = 0; + Set numeratorSet = new HashSet<>(numeratorCollection); for (T item : denominatorCollection) { - for (Object obj : numeratorCollection) { - if (item.equals(obj)) { - overlap++; - break; - } + if (numeratorSet.contains(item)) { + overlap++; } } return overlap / denominatorCollection.size(); From 9d1d3d140321306099a49d9d1c7bc64fbcee5d66 Mon Sep 17 00:00:00 2001 From: navyacodes Date: Tue, 25 Aug 2026 11:10:41 -0700 Subject: [PATCH 7/8] fixed import statement --- src/arcade/core/util/Utilities.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/arcade/core/util/Utilities.java b/src/arcade/core/util/Utilities.java index 9dd76823c..f55f6ea29 100644 --- a/src/arcade/core/util/Utilities.java +++ b/src/arcade/core/util/Utilities.java @@ -1,6 +1,11 @@ package arcade.core.util; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.ListIterator; +import java.util.Set; import sim.util.Bag; import ec.util.MersenneTwisterFast; From 77cba4459b9bc424804fdb6717c533542baf1365 Mon Sep 17 00:00:00 2001 From: navyacodes Date: Tue, 25 Aug 2026 13:57:10 -0700 Subject: [PATCH 8/8] Added comment about how duplicates are handled --- src/arcade/core/util/Utilities.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/arcade/core/util/Utilities.java b/src/arcade/core/util/Utilities.java index f55f6ea29..990a16f15 100644 --- a/src/arcade/core/util/Utilities.java +++ b/src/arcade/core/util/Utilities.java @@ -73,7 +73,9 @@ static void swap(Object[] arr, int i, int j) { /** * Calculates the fraction of elements in one collection that are also present in another - * collection. Returns 0 if either list is empty. + * collection. Duplicate elements in the numeratorCollection are treated as one occurrence, + * while duplicates in denominatorCollection are counted individually in both total number of + * matches and size. Returns 0 if either list is empty. * * @param the element type present in the two collections * @param numeratorCollection the collection to check membership against, items be the same type