@Test public void testIndexOf() { BasicEventList<Integer> source = new BasicEventList<>(); SortedList sorted= SortedList.create(source); Integer ten = new Integer(10); int emptyTest = sorted.indexOf(ten); assertEquals(-1, emptyTest); Integer one = new Integer(1); for(int i = 0; i < 12; i++) { source.add(one); } Integer five = new Integer(5); for(int i = 0; i < 13; i++) { source.add(five); } Integer nine = new Integer(9); for(int i = 0; i < 10; i++) { source.add(nine); } int firstTestIndex = sorted.indexOf(one); assertEquals(0, firstTestIndex); int secondTestIndex = sorted.indexOf(five); assertEquals(12, secondTestIndex); int thirdTestIndex = sorted.indexOf(nine); assertEquals(25, thirdTestIndex); int fourthTest = sorted.indexOf(ten); assertEquals(-1, fourthTest); }
@Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.indexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); if (index == -1) return -1; for (; index < size(); index++) { E objectAtIndex = get(index); if (comparator.compare((E)object, objectAtIndex) != 0) return -1; if (Objects.equals(object, objectAtIndex)) return index; } return -1; }
SortedList extends TransformedList<E,E> { @Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.indexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); if (index == -1) return -1; for (; index < size(); index++) { E objectAtIndex = get(index); if (comparator.compare((E)object, objectAtIndex) != 0) return -1; if (Objects.equals(object, objectAtIndex)) return index; } return -1; } }
SortedList extends TransformedList<E,E> { @Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.indexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); if (index == -1) return -1; for (; index < size(); index++) { E objectAtIndex = get(index); if (comparator.compare((E)object, objectAtIndex) != 0) return -1; if (Objects.equals(object, objectAtIndex)) return index; } return -1; } SortedList(EventList<E> source);  SortedList(EventList<E> source, Comparator<? super E> comparator); }
SortedList extends TransformedList<E,E> { @Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.indexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); if (index == -1) return -1; for (; index < size(); index++) { E objectAtIndex = get(index); if (comparator.compare((E)object, objectAtIndex) != 0) return -1; if (Objects.equals(object, objectAtIndex)) return index; } return -1; } SortedList(EventList<E> source);  SortedList(EventList<E> source, Comparator<? super E> comparator); static SortedList<E> create(EventList<E> source); void setMode(int mode); int getMode(); @Override void listChanged(ListEvent<E> listChanges); Comparator<? super E> getComparator(); void setComparator(Comparator<? super E> comparator); @Override int indexOf(Object object); @Override int lastIndexOf(Object object); int sortIndex(Object object); int lastSortIndex(Object object); @Deprecated int indexOfSimulated(Object object); @Override boolean contains(Object object); @Override Iterator<E> iterator(); }
SortedList extends TransformedList<E,E> { @Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.indexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); if (index == -1) return -1; for (; index < size(); index++) { E objectAtIndex = get(index); if (comparator.compare((E)object, objectAtIndex) != 0) return -1; if (Objects.equals(object, objectAtIndex)) return index; } return -1; } SortedList(EventList<E> source);  SortedList(EventList<E> source, Comparator<? super E> comparator); static SortedList<E> create(EventList<E> source); void setMode(int mode); int getMode(); @Override void listChanged(ListEvent<E> listChanges); Comparator<? super E> getComparator(); void setComparator(Comparator<? super E> comparator); @Override int indexOf(Object object); @Override int lastIndexOf(Object object); int sortIndex(Object object); int lastSortIndex(Object object); @Deprecated int indexOfSimulated(Object object); @Override boolean contains(Object object); @Override Iterator<E> iterator(); static final int STRICT_SORT_ORDER; static final int AVOID_MOVING_ELEMENTS; }