Skip to content

Commit

Permalink
(yegor256#1169) Use PECS in `set.Sorted'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Oct 21, 2020
1 parent 5a691d5 commit ce9cadc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/cactoos/set/Sorted.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class Sorted<T> extends SortedSetEnvelope<T> {
* @param array An array of some elements
*/
@SafeVarargs
public Sorted(final Comparator<T> cmp, final T... array) {
public Sorted(final Comparator<? super T> cmp, final T... array) {
this(cmp, new IterableOf<>(array));
}

Expand All @@ -55,7 +55,7 @@ public Sorted(final Comparator<T> cmp, final T... array) {
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
public Sorted(
final Comparator<T> cmp,
final Comparator<? super T> cmp,
final Iterable<? extends T> src
) {
super(new TreeSet<>(cmp));
Expand Down
29 changes: 27 additions & 2 deletions src/test/java/org/cactoos/set/SortedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@
* @checkstyle JavadocMethodCheck (500 lines)
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
@SuppressWarnings(
{
"PMD.AvoidDuplicateLiterals",
"PMD.TooManyMethods"
}
)
final class SortedTest {

@Test
Expand Down Expand Up @@ -122,7 +127,8 @@ void mustNotBeEqualToSortedSet() {
new IsEqual<>(3),
new IsEqual<>(2)
)
))
)
)
).affirm();
}

Expand Down Expand Up @@ -196,4 +202,23 @@ void returnsLast() {
new IsEqual<>(9)
).affirm();
}

@Test
void mustSortIntegersByNumberComparator() {
new Assertion<>(
"Must keep unique integer numbers sorted",
new Sorted<Number>(
Comparator.comparing(Number::intValue),
2, 1, 3, 2, 1
),
new IsIterableContainingInOrder<>(
new ListOf<Matcher<? super Number>>(
new IsEqual<>(1),
new IsEqual<>(2),
new IsEqual<>(3)
)
)
).affirm();
}

}

0 comments on commit ce9cadc

Please sign in to comment.