/** * Sorts this sequence according to the natural order of the elements. * * @param start the start index where to start sorting (inclusively) * @param end the end index where to stop sorting (exclusively) * @throws ClassCastException if the sequence contains elements that are not * <i>mutually comparable</i> using the specified comparator * @return {@code this} sequence */ public default MSeq<T> sort(final int start, final int end) { return sort(start, end, null); }
/** * Sorts this sequence according to the natural order of the elements. * * @throws ClassCastException if the sequence contains elements that are not * <i>mutually comparable</i> using the specified comparator * @return {@code this} sequence */ public default MSeq<T> sort() { return sort(0, length(), null); }
/** * Sorts this sequence according to the natural order of the elements. * * @param start the start index where to start sorting (inclusively) * @throws ClassCastException if the sequence contains elements that are not * <i>mutually comparable</i> using the specified comparator * @return {@code this} sequence */ public default MSeq<T> sort(final int start) { return sort(start, length(), null); }
/** * Sorts this sequence according to the order induced by the specified * {@link Comparator}. * * <p>All elements in this sequence must be <i>mutually comparable</i> using * the specified comparator (that is, {@code c.compare(e1, e2)} must not * throw a {@code ClassCastException} for any elements {@code e1} and * {@code e2} in the sequence). * * <p>If the specified comparator is {@code null} then all elements in this * list must implement the {@link Comparable} interface and the elements' * Comparable natural ordering should be used. * * @param comparator the {@code Comparator} used to compare sequence elements. * A {@code null} value indicates that the elements' Comparable * natural ordering should be used * @throws ClassCastException if the sequence contains elements that are not * <i>mutually comparable</i> using the specified comparator * @return {@code this} sequence */ public default MSeq<T> sort(final Comparator<? super T> comparator) { return sort(0, length(), comparator); }
/** * Sorts this sequence according to the order induced by the specified * {@link Comparator}. * * <p>All elements in this sequence must be <i>mutually comparable</i> using * the specified comparator (that is, {@code c.compare(e1, e2)} must not * throw a {@code ClassCastException} for any elements {@code e1} and * {@code e2} in the sequence). * * <p>If the specified comparator is {@code null} then all elements in this * list must implement the {@link Comparable} interface and the elements' * Comparable natural ordering should be used. * * @param start the start index where to start sorting (inclusively) * @param comparator the {@code Comparator} used to compare sequence elements. * A {@code null} value indicates that the elements' Comparable * natural ordering should be used * @throws ClassCastException if the sequence contains elements that are not * <i>mutually comparable</i> using the specified comparator * @return {@code this} sequence */ public default MSeq<T> sort( final int start, final Comparator<? super T> comparator ) { return sort(start, length(), comparator); }
@Test(dataProvider = "sequences") public void sort(final MSeq<Integer> seq) { seq.shuffle(new Random(23)); Assert.assertFalse(seq.isSorted()); seq.sort(); Assert.assertTrue(seq.isSorted()); }
@Test(dataProvider = "sequences") public void sortWithComparator(final MSeq<Integer> seq) { seq.shuffle(new Random(23)); Assert.assertFalse(seq.isSorted()); seq.sort((a, b) -> b.compareTo(a)); Assert.assertTrue(seq.isSorted((a, b) -> b.compareTo(a))); Assert.assertTrue(seq.reverse().isSorted()); }
@Test(dataProvider = "sequences") public void sortWithStart(final MSeq<Integer> seq) { seq.shuffle(new Random(23)); Assert.assertFalse(seq.isSorted()); seq.sort(2); Assert.assertTrue(seq.subSeq(2).isSorted()); Assert.assertFalse(seq.isSorted()); }
@Test(dataProvider = "sequences") public void sortWithEnd(final MSeq<Integer> seq) { seq.shuffle(new Random(23)); Assert.assertFalse(seq.isSorted()); seq.sort(0, seq.length() - 2); Assert.assertTrue(seq.subSeq(0, seq.length() - 2).isSorted()); Assert.assertFalse(seq.isSorted()); }
copy.sort((a, b) -> opt.<C>descending().compare(a.getFitness(), b.getFitness()));
? population.asISeq().copy().sort(POPULATION_COMPARATOR) : population;
? population.asISeq().copy().sort(POPULATION_COMPARATOR) : population;