@Test public void testLastIndexOfWithWeakComparator() { BasicEventList<Comparable> source = new BasicEventList<>(); SortedList<Comparable> sorted = new SortedList<>(source, GlazedLists.comparableComparator()); final Song enterSandman = new Song("Metallica", "Enter Sandman"); final Song masterOfPuppets = new Song("Metallica", "Master of Puppets"); final Song battery = new Song("Metallica", "Battery"); sorted.add(enterSandman); sorted.add(masterOfPuppets); sorted.add(battery); assertEquals(2, sorted.lastIndexOf(battery)); assertEquals(1, sorted.lastIndexOf(masterOfPuppets)); assertEquals(0, sorted.lastIndexOf(enterSandman)); sorted.add(enterSandman); sorted.add(masterOfPuppets); sorted.add(battery); assertEquals(5, sorted.lastIndexOf(battery)); assertEquals(4, sorted.lastIndexOf(masterOfPuppets)); assertEquals(3, sorted.lastIndexOf(enterSandman)); assertEquals(-1, sorted.lastIndexOf(null)); sorted.add(null); assertEquals(0, sorted.lastIndexOf(null)); sorted.add(null); assertEquals(1, sorted.lastIndexOf(null)); }
@Override public int lastIndexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.lastIndexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, false, false, ALL_COLORS); if (index == -1) return -1; for(; index > -1; 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 lastIndexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.lastIndexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, false, false, ALL_COLORS); if (index == -1) return -1; for(; index > -1; 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 lastIndexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.lastIndexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, false, false, ALL_COLORS); if (index == -1) return -1; for(; index > -1; 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 lastIndexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.lastIndexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, false, false, ALL_COLORS); if (index == -1) return -1; for(; index > -1; 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 lastIndexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.lastIndexOf(object); int index = ((SimpleTree)sorted).indexOfValue(object, false, false, ALL_COLORS); if (index == -1) return -1; for(; index > -1; 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; }