ListUtil { public static <E> int remove(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) { list.remove(center); return center; } else if (cmpR < 0) { last = center - 1; } else { first = center + 1; } } return -1; } 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 removeComparatorTList() { List<Integer> list = new ArrayList<>(); list.addAll(Arrays.asList(1, 4, 6, 12, 30)); assertEquals(-1, ListUtil.remove(list, new NaturalOrderComparator<Integer>(), -2)); assertEquals(-1, ListUtil.remove(list, new NaturalOrderComparator<Integer>(), 34)); assertEquals(2, ListUtil.remove(list, new NaturalOrderComparator<Integer>(), 6)); assertEquals(1, ListUtil.remove(list, new NaturalOrderComparator<Integer>(), 4)); Iterator<Integer> iterator = list.iterator(); assertEquals(Integer.valueOf(1), iterator.next()); assertEquals(Integer.valueOf(12), iterator.next()); assertEquals(Integer.valueOf(30), iterator.next()); assertFalse(iterator.hasNext()); }