@Test public void testAllEqual() { Collection coll1 = Arrays.asList(item1, item2); Collection coll2 = Arrays.asList(equalItem1, equalItem2); assertTrue("Comparing equal collections should be return true", CollectionUtils.compareCollectionContents(coll1, coll2)); Collection coll3 = Arrays.asList(item1, item2); Collection coll4 = Arrays.asList(equalItem1, equalItem2); assertTrue("Comparing equal but differently ordered collections should be return true", CollectionUtils.compareCollectionContents(coll3, coll4)); List<Object> coll5 = new ArrayList<>(); coll5.add(item1); coll5.add(item2); Set<Object> coll6 = new HashSet<>(); coll6.add(equalItem1); coll6.add(equalItem2); assertTrue("Comparing differently typed collections with same elements should be return true", CollectionUtils.compareCollectionContents(coll5, coll6)); }
public static <C extends Collection> boolean compareCollectionContents(C c1, C c2) { if (c1.size() != c2.size()) { return false; } else { boolean allMatched = true; for (Object o : c1) { if (!c2.contains(o)) { allMatched = false; break; } } for (Object o : c2) { if (!c1.contains(o)) { allMatched = false; break; } } return allMatched; } }
CollectionUtils { public static <C extends Collection> boolean compareCollectionContents(C c1, C c2) { if (c1.size() != c2.size()) { return false; } else { boolean allMatched = true; for (Object o : c1) { if (!c2.contains(o)) { allMatched = false; break; } } for (Object o : c2) { if (!c1.contains(o)) { allMatched = false; break; } } return allMatched; } } }
CollectionUtils { public static <C extends Collection> boolean compareCollectionContents(C c1, C c2) { if (c1.size() != c2.size()) { return false; } else { boolean allMatched = true; for (Object o : c1) { if (!c2.contains(o)) { allMatched = false; break; } } for (Object o : c2) { if (!c1.contains(o)) { allMatched = false; break; } } return allMatched; } }  }
CollectionUtils { public static <C extends Collection> boolean compareCollectionContents(C c1, C c2) { if (c1.size() != c2.size()) { return false; } else { boolean allMatched = true; for (Object o : c1) { if (!c2.contains(o)) { allMatched = false; break; } } for (Object o : c2) { if (!c1.contains(o)) { allMatched = false; break; } } return allMatched; } }  static boolean compareCollectionContents(C c1, C c2); }
CollectionUtils { public static <C extends Collection> boolean compareCollectionContents(C c1, C c2) { if (c1.size() != c2.size()) { return false; } else { boolean allMatched = true; for (Object o : c1) { if (!c2.contains(o)) { allMatched = false; break; } } for (Object o : c2) { if (!c1.contains(o)) { allMatched = false; break; } } return allMatched; } }  static boolean compareCollectionContents(C c1, C c2);  }