public class StandardComparisonStrategy extends AbstractComparisonStrategy
ComparisonStrategy
contract with a comparison strategy based on
Objects.areEqual(Object, Object)
method, it is also based on Comparable.compareTo(Object)
when Object
are Comparable
method.Modifier and Type | Field and Description |
---|---|
private static StandardComparisonStrategy |
INSTANCE |
Modifier | Constructor and Description |
---|---|
protected |
StandardComparisonStrategy()
Creates a new
StandardComparisonStrategy , comparison strategy being based on
Objects.areEqual(Object, Object) . |
Modifier and Type | Method and Description |
---|---|
boolean |
areEqual(java.lang.Object actual,
java.lang.Object other)
Returns true if actual and other are equal based on
Objects.areEqual(Object, Object) , false otherwise. |
java.lang.String |
asText() |
private void |
checkArgumentIsComparable(java.lang.Object actual) |
java.lang.Iterable<?> |
duplicatesFrom(java.lang.Iterable<?> iterable)
Returns any duplicate elements from the given collection according to
Objects.areEqual(Object, Object)
comparison strategy. |
static StandardComparisonStrategy |
instance()
Returns the singleton instance of this class.
|
boolean |
isGreaterThan(java.lang.Object actual,
java.lang.Object other)
Returns true if actual is greater than other, false otherwise.
|
boolean |
isLessThan(java.lang.Object actual,
java.lang.Object other)
Returns true if actual is less 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 based on Objects.areEqual(Object, Object) ,
false otherwise.If given Iterable is null, return false. |
void |
iterableRemoves(java.lang.Iterable<?> iterable,
java.lang.Object value)
Look for given value in given
Iterable according to the implemented comparison strategy, if value is found it is
removed from it.If given Iterable is null, does nothing. |
void |
iterablesRemoveFirst(java.lang.Iterable<?> iterable,
java.lang.Object value)
Removes the first value in
iterable that matches the value according to the implemented comparison
strategy. |
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 string 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.
|
arrayContains, isGreaterThanOrEqualTo, isLessThanOrEqualTo
private static final StandardComparisonStrategy INSTANCE
protected StandardComparisonStrategy()
StandardComparisonStrategy
, comparison strategy being based on
Objects.areEqual(Object, Object)
.public static StandardComparisonStrategy instance()
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 boolean areEqual(java.lang.Object actual, java.lang.Object other)
Objects.areEqual(Object, Object)
, false otherwise.actual
- the object to compare to otherother
- the object to compare to actualObjects.areEqual(Object, Object)
, false otherwise.public boolean iterableContains(java.lang.Iterable<?> iterable, java.lang.Object value)
Iterable
contains given value based on Objects.areEqual(Object, Object)
,
false otherwise.Iterable
is null, return false.iterable
- the Iterable
to search value invalue
- the object to look for in given Iterable
Iterable
contains given value based on Objects.areEqual(Object, Object)
,
false otherwise.public void iterableRemoves(java.lang.Iterable<?> iterable, java.lang.Object value)
Iterable
according to the implemented comparison strategy, if value is found it is
removed from it.Iterable
is null, does nothing.iterable
- the Iterable
we want remove value fromvalue
- object to remove from given Iterable
public void iterablesRemoveFirst(java.lang.Iterable<?> iterable, java.lang.Object value)
iterable
that matches the value
according to the implemented comparison
strategy. If given Iterable
is null, does nothing.iterable
- the Iterable
we want remove value fromvalue
- object to remove from given Iterable
public java.lang.Iterable<?> duplicatesFrom(java.lang.Iterable<?> iterable)
Objects.areEqual(Object, Object)
comparison strategy.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.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 isLessThan(java.lang.Object actual, java.lang.Object other)
ComparisonStrategy
isLessThan
in interface ComparisonStrategy
isLessThan
in class AbstractComparisonStrategy
actual
- the object to compare to otherother
- the object to compare to actualprivate void checkArgumentIsComparable(java.lang.Object actual)
public boolean isStandard()
ComparisonStrategy
isStandard
in interface ComparisonStrategy
isStandard
in class AbstractComparisonStrategy