Package org.assertj.core.internal
Class StandardComparisonStrategy
- java.lang.Object
-
- org.assertj.core.internal.AbstractComparisonStrategy
-
- org.assertj.core.internal.StandardComparisonStrategy
-
- All Implemented Interfaces:
ComparisonStrategy
- Direct Known Subclasses:
AtomicReferenceArrayElementComparisonStrategy
,IterableElementComparisonStrategy
,ObjectArrayElementComparisonStrategy
public class StandardComparisonStrategy extends AbstractComparisonStrategy
ImplementsComparisonStrategy
contract with a comparison strategy based onObjects.deepEquals(Object, Object)
method, it is also based onComparable.compareTo(Object)
when Object areComparable
method.
-
-
Field Summary
Fields Modifier and Type Field Description private static StandardComparisonStrategy
INSTANCE
-
Constructor Summary
Constructors Modifier Constructor Description protected
StandardComparisonStrategy()
Creates a new
, comparison strategy being based onStandardComparisonStrategy
Objects.deepEquals(Object, Object)
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
areEqual(java.lang.Object actual, java.lang.Object other)
Returnstrue
if the arguments are deeply equal to each other,false
otherwise.private void
checkArgumentIsComparable(java.lang.Object actual)
java.lang.Iterable<?>
duplicatesFrom(java.lang.Iterable<?> iterable)
Returns any duplicate elements from the given collection according toObjects.deepEquals(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 otherwiseboolean
iterableContains(java.lang.Iterable<?> iterable, java.lang.Object value)
Returns true if givenIterable
contains given value based onObjects.deepEquals(Object, Object)
, false otherwise.
If givenIterable
is null, return false.void
iterableRemoves(java.lang.Iterable<?> iterable, java.lang.Object value)
Look for given value in givenIterable
according to the implemented comparison strategy, if value is found it is removed from it.
If givenIterable
is null, does nothing.void
iterablesRemoveFirst(java.lang.Iterable<?> iterable, java.lang.Object value)
Removes the first value initerable
that matches thevalue
according to the implemented comparison strategy.protected java.util.Set<java.lang.Object>
newSetUsingComparisonStrategy()
Returns aSet
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.-
Methods inherited from class org.assertj.core.internal.AbstractComparisonStrategy
arrayContains, isGreaterThanOrEqualTo, isLessThanOrEqualTo
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.assertj.core.internal.ComparisonStrategy
asText
-
-
-
-
Field Detail
-
INSTANCE
private static final StandardComparisonStrategy INSTANCE
-
-
Constructor Detail
-
StandardComparisonStrategy
protected StandardComparisonStrategy()
Creates a new
, comparison strategy being based onStandardComparisonStrategy
Objects.deepEquals(Object, Object)
.
-
-
Method Detail
-
instance
public static StandardComparisonStrategy instance()
Returns the singleton instance of this class.- Returns:
- the singleton instance of this class.
-
newSetUsingComparisonStrategy
protected java.util.Set<java.lang.Object> newSetUsingComparisonStrategy()
Description copied from class:AbstractComparisonStrategy
Returns aSet
honoring the comparison strategy used.- Specified by:
newSetUsingComparisonStrategy
in classAbstractComparisonStrategy
- Returns:
- a
Set
honoring the comparison strategy used.
-
areEqual
public boolean areEqual(java.lang.Object actual, java.lang.Object other)
Returnstrue
if the arguments are deeply equal to each other,false
otherwise.It mimics the behavior of
Objects.deepEquals(Object, Object)
, but without performing a reference check between the two arguments. According todeepEquals
javadoc, the reference check should be delegated to theequals
method of the first argument, but this is not happening. Bug JDK-8196069 also mentions this gap.- Parameters:
actual
- the object to compare toother
other
- the object to compare toactual
- Returns:
true
if the arguments are deeply equal to each other,false
otherwise- See Also:
- JDK-8196069
-
iterableContains
public boolean iterableContains(java.lang.Iterable<?> iterable, java.lang.Object value)
Returns true if givenIterable
contains given value based onObjects.deepEquals(Object, Object)
, false otherwise.
If givenIterable
is null, return false.- Parameters:
iterable
- theIterable
to search value invalue
- the object to look for in givenIterable
- Returns:
- true if given
Iterable
contains given value based onObjects.deepEquals(Object, Object)
, false otherwise.
-
iterableRemoves
public void iterableRemoves(java.lang.Iterable<?> iterable, java.lang.Object value)
Look for given value in givenIterable
according to the implemented comparison strategy, if value is found it is removed from it.
If givenIterable
is null, does nothing.- Parameters:
iterable
- theIterable
we want remove value fromvalue
- object to remove from givenIterable
-
iterablesRemoveFirst
public void iterablesRemoveFirst(java.lang.Iterable<?> iterable, java.lang.Object value)
Removes the first value initerable
that matches thevalue
according to the implemented comparison strategy. If givenIterable
is null, does nothing.- Parameters:
iterable
- theIterable
we want remove value fromvalue
- object to remove from givenIterable
-
duplicatesFrom
public java.lang.Iterable<?> duplicatesFrom(java.lang.Iterable<?> iterable)
Returns any duplicate elements from the given collection according toObjects.deepEquals(Object, Object)
comparison strategy.- Specified by:
duplicatesFrom
in interfaceComparisonStrategy
- Overrides:
duplicatesFrom
in classAbstractComparisonStrategy
- Parameters:
iterable
- the givenIterable
we want to extract duplicate elements.- Returns:
- an
Iterable
containing the duplicate elements of the given one. If no duplicates are found, an emptyIterable
is returned.
-
stringStartsWith
public boolean stringStartsWith(java.lang.String string, java.lang.String prefix)
Description copied from interface:ComparisonStrategy
Returns true if string starts with prefix according to the implemented comparison strategy, false otherwise.- Parameters:
string
- the String we want to look starting prefixprefix
- the prefix String to look for at string's start- Returns:
- true if string starts with prefix according to the implemented comparison strategy, false otherwise.
-
stringEndsWith
public boolean stringEndsWith(java.lang.String string, java.lang.String suffix)
Description copied from interface:ComparisonStrategy
Returns true if string ends with suffix according to the implemented comparison strategy, false otherwise.- Parameters:
string
- the String we want to look starting suffixsuffix
- the suffix String to look for at string's end- Returns:
- true if string ends with suffix according to the implemented comparison strategy, false otherwise.
-
stringContains
public boolean stringContains(java.lang.String string, java.lang.String sequence)
Description copied from interface:ComparisonStrategy
Returns true if given string contains given sequence according to the implemented comparison strategy, false otherwise.- Parameters:
string
- the string to search sequence in (must not be null)sequence
- the String to look for in given string- Returns:
- true if given string contains given sequence according to the implemented comparison strategy, false otherwise.
-
isGreaterThan
public boolean isGreaterThan(java.lang.Object actual, java.lang.Object other)
Description copied from interface:ComparisonStrategy
Returns true if actual is greater than other, false otherwise.- Parameters:
actual
- the object to compare to otherother
- the object to compare to actual- Returns:
- true if actual is greater than other, false otherwise.
-
isLessThan
public boolean isLessThan(java.lang.Object actual, java.lang.Object other)
Description copied from interface:ComparisonStrategy
Returns true if actual is less than other, false otherwise.- Specified by:
isLessThan
in interfaceComparisonStrategy
- Overrides:
isLessThan
in classAbstractComparisonStrategy
- Parameters:
actual
- the object to compare to otherother
- the object to compare to actual- Returns:
- true if actual is less than other, false otherwise.
-
checkArgumentIsComparable
private void checkArgumentIsComparable(java.lang.Object actual)
-
isStandard
public boolean isStandard()
Description copied from interface:ComparisonStrategy
Return true if comparison strategy is default/standard, false otherwise- Specified by:
isStandard
in interfaceComparisonStrategy
- Overrides:
isStandard
in classAbstractComparisonStrategy
- Returns:
- true if comparison strategy is default/standard, false otherwise
-
-