ListUtil { @Pure public static <E> boolean contains(List<E> list, Comparator<? super E> comparator, E data) { assert list != null; assert comparator != null; assert data != null; int first = 0; int last = list.size() - 1; while (last >= first) { final int center = (first + last) / 2; final E dt = list.get(center); final int cmpR = comparator.compare(data, dt); if (cmpR == 0) { return true; } else if (cmpR < 0) { last = center - 1; } else { first = center + 1; } } return false; } private  ListUtil(); static int remove(List<E> list, Comparator<? super E> comparator, E data); @Inline(value = "add($1, $2, $3, false, false)") static int addIfAbsent(List<E> list, Comparator<? super E> comparator, E data); static int add(List<E> list, Comparator<? super E> comparator, E data,
			boolean allowMultipleOccurencesOfSameValue, boolean allowReplacement); @Pure static boolean contains(List<E> list, Comparator<? super E> comparator, E data); @Pure static int indexOf(List<T> list, Comparator<? super T> comparator, T elt); @Pure static int lastIndexOf(List<T> list, Comparator<? super T> comparator, T elt); @Pure static int getInsertionIndex(List<T> list, Comparator<? super T> comparator, T elt); @Pure static int getInsertionIndex(List<T> list, Comparator<? super T> comparator, T elt, boolean allowMultiple); @Pure static int ceilingIndex(List<T> list, Comparator<? super T> comparator, T elt); @Pure static int floorIndex(List<T> list, Comparator<? super T> comparator, T elt); @Pure static int higherIndex(List<T> list, Comparator<? super T> comparator, T elt); @Pure static int lowerIndex(List<T> list, Comparator<? super T> comparator, T elt); static Iterator<T> reverseIterator(final List<T> list);  }
@Test public void containsComparatorTList() { List<Integer> list = new ArrayList<>(); list.addAll(Arrays.asList(1, 4, 6, 12, 30)); assertFalse(ListUtil.contains(list, new NaturalOrderComparator<Integer>(), 0)); assertTrue(ListUtil.contains(list, new NaturalOrderComparator<Integer>(), 1)); assertFalse(ListUtil.contains(list, new NaturalOrderComparator<Integer>(), 2)); assertFalse(ListUtil.contains(list, new NaturalOrderComparator<Integer>(), 3)); assertTrue(ListUtil.contains(list, new NaturalOrderComparator<Integer>(), 4)); assertFalse(ListUtil.contains(list, new NaturalOrderComparator<Integer>(), 5)); assertTrue(ListUtil.contains(list, new NaturalOrderComparator<Integer>(), 6)); }