public class ComparatorBasedComparisonStrategy extends AbstractComparisonStrategy
ComparisonStrategy
contract with a comparison strategy based on a Comparator
.Modifier and Type | Field and Description |
---|---|
private java.util.Comparator |
comparator |
private static StandardRepresentation |
STANDARD_REPRESENTATION |
Constructor and Description |
---|
ComparatorBasedComparisonStrategy(java.util.Comparator comparator)
Creates a new
ComparatorBasedComparisonStrategy specifying the comparison strategy with given
comparator. |
Modifier and Type | Method and Description |
---|---|
boolean |
areEqual(java.lang.Object actual,
java.lang.Object other)
Returns true if actual and other are equal according to
comparator , false otherwise.Handles the cases where one of the parameter is null so that internal comparator does not have too. |
java.lang.String |
asText() |
java.lang.Iterable<?> |
duplicatesFrom(java.lang.Iterable<?> iterable)
Returns any duplicate elements from the given
Iterable according to comparator . |
java.util.Comparator<?> |
getComparator() |
boolean |
isGreaterThan(java.lang.Object actual,
java.lang.Object other)
Returns true if actual is greater than other, false otherwise.
|
boolean |
isStandard()
Return true if comparison strategy is default/standard, false otherwise
|
boolean |
iterableContains(java.lang.Iterable<?> iterable,
java.lang.Object value)
Returns true if given
Iterable contains given value according to comparator , false otherwise.If given Iterable is null or empty, return false. |
void |
iterableRemoves(java.lang.Iterable<?> iterable,
java.lang.Object value)
Look for given value in given
Iterable according to the Comparator , if value is found it is removed
from it.Does nothing if given Iterable is null (meaning no exception thrown). |
protected java.util.Set<java.lang.Object> |
newSetUsingComparisonStrategy()
Returns a
Set honoring the comparison strategy used. |
boolean |
stringContains(java.lang.String string,
java.lang.String sequence)
Returns true if given string contains given sequence according to the implemented comparison strategy, false otherwise.
|
boolean |
stringEndsWith(java.lang.String string,
java.lang.String suffix)
Returns true if sstring ends with suffix according to the implemented comparison strategy, false otherwise.
|
boolean |
stringStartsWith(java.lang.String string,
java.lang.String prefix)
Returns true if string starts with prefix according to the implemented comparison strategy, false otherwise.
|
java.lang.String |
toString() |
arrayContains, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo
private static final StandardRepresentation STANDARD_REPRESENTATION
private final java.util.Comparator comparator
public ComparatorBasedComparisonStrategy(java.util.Comparator comparator)
ComparatorBasedComparisonStrategy
specifying the comparison strategy with given
comparator.comparator
- the comparison strategy to use.public boolean iterableContains(java.lang.Iterable<?> iterable, java.lang.Object value)
Iterable
contains given value according to comparator
, false otherwise.Iterable
is null or empty, return false.iterable
- the Iterable
to search value invalue
- the object to look for in given Iterable
Iterable
contains given value according to comparator
, false otherwise.public void iterableRemoves(java.lang.Iterable<?> iterable, java.lang.Object value)
Iterable
according to the Comparator
, if value is found it is removed
from it.Iterable
is null (meaning no exception thrown).iterable
- the Iterable
we want remove value fromvalue
- object to remove from given Iterable
public boolean areEqual(java.lang.Object actual, java.lang.Object other)
comparator
, false otherwise.comparator
does not have too.actual
- the object to compare to otherother
- the object to compare to actualcomparator
, false otherwise.public java.lang.Iterable<?> duplicatesFrom(java.lang.Iterable<?> iterable)
Iterable
according to comparator
.duplicatesFrom
in interface ComparisonStrategy
duplicatesFrom
in class AbstractComparisonStrategy
iterable
- the given Iterable
we want to extract duplicate elements.Iterable
containing the duplicate elements of the given one. If no duplicates are found, an
empty Iterable
is returned.protected java.util.Set<java.lang.Object> newSetUsingComparisonStrategy()
AbstractComparisonStrategy
Set
honoring the comparison strategy used.newSetUsingComparisonStrategy
in class AbstractComparisonStrategy
Set
honoring the comparison strategy used.public java.lang.String asText()
asText
in class AbstractComparisonStrategy
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Comparator<?> getComparator()
public boolean stringStartsWith(java.lang.String string, java.lang.String prefix)
ComparisonStrategy
string
- the String we want to look starting prefixprefix
- the prefix String to look for at string's startpublic boolean stringEndsWith(java.lang.String string, java.lang.String suffix)
ComparisonStrategy
string
- the String we want to look starting suffixsuffix
- the suffix String to look for at string's endpublic boolean stringContains(java.lang.String string, java.lang.String sequence)
ComparisonStrategy
string
- the string to search sequence in (must not be null)sequence
- the String to look for in given stringpublic boolean isGreaterThan(java.lang.Object actual, java.lang.Object other)
ComparisonStrategy
actual
- the object to compare to otherother
- the object to compare to actualpublic boolean isStandard()
ComparisonStrategy
isStandard
in interface ComparisonStrategy
isStandard
in class AbstractComparisonStrategy