/** * 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<>(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)); } }
/** * 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<>(comparator, ascending)); }
/** * 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)); }
/** * 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)); } }
@Test(expected = IllegalArgumentException.class) public void shouldNeedComparatorWithAscending() throws Exception { new InvertibleComparator<>(null, true); }
@Test(expected = IllegalArgumentException.class) public void shouldNeedComparator() throws Exception { new InvertibleComparator<>(null); }
@Test public void shouldCompareDescending() throws Exception { InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator, false); assertThat(invertibleComparator.compare(1, 2), is(1)); }
@Test public void shouldCompareAscending() throws Exception { InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator, true); assertThat(invertibleComparator.compare(1, 2), is(-1)); }
@Test public void shouldDefaultToAscending() throws Exception { InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator); assertThat(invertibleComparator.isAscending(), is(true)); assertThat(invertibleComparator.compare(1, 2), is(-1)); }
@Test public void shouldInvert() throws Exception { InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator); assertThat(invertibleComparator.isAscending(), is(true)); assertThat(invertibleComparator.compare(1, 2), is(-1)); invertibleComparator.invertOrder(); assertThat(invertibleComparator.isAscending(), is(false)); assertThat(invertibleComparator.compare(1, 2), is(1)); }
/** * 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) */ public void addComparator(Comparator<T> comparator, boolean ascending) { this.comparators.add(new InvertibleComparator<T>(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 */ public void addComparator(Comparator<T> comparator) { if (comparator instanceof InvertibleComparator) { this.comparators.add((InvertibleComparator<T>) comparator); } else { this.comparators.add(new InvertibleComparator<T>(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 */ public void setComparator(int index, Comparator<T> comparator) { if (comparator instanceof InvertibleComparator) { this.comparators.set(index, (InvertibleComparator<T>) comparator); } else { this.comparators.set(index, new InvertibleComparator<T>(comparator)); } }
/** * 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<>(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 comparator, boolean ascending) { InvertibleComparator invComp = new InvertibleComparator(comparator, ascending); this.comparators.set(index, invComp); }