/** * Add a Comparator to the end of the chain using the provided sort order. * * @param comparator the Comparator to add to the end of the chain * @param ascending the sort order: ascending (true) or descending (false) */ @SuppressWarnings("unchecked") public void addComparator(Comparator<? extends T> comparator, boolean ascending) { this.comparators.add(new InvertibleComparator(comparator, ascending)); }
/** * Replace the Comparator at the given index using the given sort order. * * @param index the index of the Comparator to replace * @param comparator the Comparator to place at the given index * @param ascending the sort order: ascending (true) or descending (false) */ public void setComparator(int index, Comparator<T> comparator, boolean ascending) { this.comparators.set(index, new InvertibleComparator<T>(comparator, ascending)); }
/** * Add a Comparator to the end of the chain. * <p>The Comparator will default to ascending sort order, * unless it is a InvertibleComparator. * * @param comparator the Comparator to add to the end of the chain * @see InvertibleComparator */ @SuppressWarnings("unchecked") public void addComparator(Comparator<? extends T> comparator) { if (comparator instanceof InvertibleComparator) { this.comparators.add((InvertibleComparator) comparator); } else { this.comparators.add(new InvertibleComparator(comparator)); } }
/** * Replace the Comparator at the given index. * <p>The Comparator will default to ascending sort order, * unless it is a InvertibleComparator. * * @param index the index of the Comparator to replace * @param comparator the Comparator to place at the given index * @see InvertibleComparator */ @SuppressWarnings("unchecked") public void setComparator(int index, Comparator<? extends T> comparator) { if (comparator instanceof InvertibleComparator) { this.comparators.set(index, (InvertibleComparator) comparator); } else { this.comparators.set(index, new InvertibleComparator(comparator)); } }