/** {@inheritDoc} */ @Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.indexOf(object); // use the fact that we have sorted data to quickly locate a position // at which we can begin a linear search for an object that .equals(object) int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); // if we couldn't use the comparator to find the index, return -1 if (index == -1) return -1; // otherwise, we must now begin a linear search for the index of an element // that .equals() the given object for (; index < size(); index++) { E objectAtIndex = get(index); // if the objectAtIndex no longer compares equally with the given object, stop the linear search if (comparator.compare((E)object, objectAtIndex) != 0) return -1; // if the objectAtIndex and object are equal, return the index if (GlazedListsImpl.equal(object, objectAtIndex)) return index; } // if we fall out of the loop we could not locate the object return -1; }
/** {@inheritDoc} */ @Override public int indexOf(Object object) { if(mode != STRICT_SORT_ORDER || comparator == null) return super.indexOf(object); // use the fact that we have sorted data to quickly locate a position // at which we can begin a linear search for an object that .equals(object) int index = ((SimpleTree)sorted).indexOfValue(object, true, false, ALL_COLORS); // if we couldn't use the comparator to find the index, return -1 if (index == -1) return -1; // otherwise, we must now begin a linear search for the index of an element // that .equals() the given object for (; index < size(); index++) { E objectAtIndex = get(index); // if the objectAtIndex no longer compares equally with the given object, stop the linear search if (comparator.compare((E)object, objectAtIndex) != 0) return -1; // if the objectAtIndex and object are equal, return the index if (GlazedListsImpl.equal(object, objectAtIndex)) return index; } // if we fall out of the loop we could not locate the object return -1; }