-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e153735
commit 0f19ea2
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
approvaltests-util-tests/src/test/java/com/spun/util/ComparableUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.spun.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.spun.util.ComparableUtils.wrap; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class ComparableUtilsTest | ||
{ | ||
@Test | ||
void testWrapper() | ||
{ | ||
Integer one = 1; | ||
Integer two = 2; | ||
assertTrue(wrap(one).isLessThan(two)); | ||
assertTrue(wrap(one).isLessThanOrEqual(two)); | ||
assertTrue(wrap(one).isEqualTo(one)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
approvaltests-util/src/main/java/com/spun/util/ComparableUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.spun.util; | ||
|
||
public class ComparableUtils | ||
{ | ||
public static <T extends Comparable<T>> boolean isAEqualToB(T a, T b) | ||
{ | ||
return a.compareTo(b) == 0; | ||
} | ||
public static <T extends Comparable<T>> boolean isALessThanOrEqualToB(T a, T b) | ||
{ | ||
return a.compareTo(b) <= 0; | ||
} | ||
public static <T extends Comparable<T>> boolean isALessThanB(T a, T b) | ||
{ | ||
return a.compareTo(b) < 0; | ||
} | ||
public static <T extends Comparable<T>> ComparableWrapper<T> wrap(T object) | ||
{ | ||
return new ComparableWrapper<>(object); | ||
} | ||
public static class ComparableWrapper<T extends Comparable<T>> | ||
{ | ||
private final T object; | ||
public ComparableWrapper(T object) | ||
{ | ||
this.object = object; | ||
} | ||
public boolean isLessThan(T other) | ||
{ | ||
return isALessThanB(object, other); | ||
} | ||
public boolean isEqualTo(T other) | ||
{ | ||
return isAEqualToB(object, other); | ||
} | ||
public boolean isLessThanOrEqual(T other) | ||
{ | ||
return isALessThanOrEqualToB(object, other); | ||
} | ||
} | ||
} |