SortedList extends AbstractList<T> { @Override @SuppressWarnings("unchecked") public int indexOf(Object o) { try { return Collections.binarySearch(elements, (T) o); } catch (NullPointerException | ClassCastException e) { return -1; } } SortedList(int initialCapacity);  SortedList(Collection<? extends T> c);  SortedList(); @Override T get(int index); @Override int size(); @Override boolean add(T e); @Override T remove(int index); @Override @SuppressWarnings("unchecked") int indexOf(Object o);  }
@Test public void testIndexOf() { SortedList<Double> l = new SortedList<>(); l.add(0.0); l.add(0.0); l.add(1.0); assertEquals(1, l.indexOf(0.0)); assertEquals(2, l.indexOf(1.0)); assertEquals(-1, l.indexOf(-1.0)); assertEquals(-1, l.indexOf(null)); assertEquals(-4, l.indexOf(Double.NaN)); }