CollectionUtil { public static <T> int indexOfInstance(final Collection<? extends T> collection, final T instance) { if (collection != null && !collection.isEmpty()) { int index = 0; for (final T collectionElement : collection) { if (collectionElement == instance) { return index; } index++; } } return -1; }  static boolean containsInstance(final Collection<? extends T> collection, final T instance); static int indexOfInstance(final Collection<? extends T> collection, final T instance); static Map<T, AtomicInteger> countOccurrences(final Collection<T> collection); static void moveEntryInInsertSortedMap(final Map<K, V> insertSortedMap, final K entryKey, final boolean increaseIndexByOne); static String toString(final Collection<?> collection, final String separator);  }
@Test public void testIndexOfInstance_1() { final String instance = "ab"; Assert.assertEquals(1, CollectionUtil.indexOfInstance(Arrays.asList("a", instance, "b"), instance)); }
@Test public void testIndexOfInstance_2() { final String instance = "ab"; Assert.assertEquals(1, CollectionUtil.indexOfInstance(Arrays.asList("a", instance, "b", instance), instance)); }
@Test public void testIndexOfInstance_3() { Assert.assertEquals(-1, CollectionUtil.indexOfInstance(Arrays.asList("a", "b"), "ab")); }
@Test public void testIndexOfInstance_4() { final String instance = "ab"; Assert.assertEquals(3, CollectionUtil.indexOfInstance(Arrays.asList("a", new String(instance), "b", instance), instance)); }