Package org.assertj.core.internal
Interface ComparisonStrategy
- All Known Implementing Classes:
AbstractComparisonStrategy,AtomicReferenceArrayElementComparisonStrategy,ComparatorBasedComparisonStrategy,IterableElementComparisonStrategy,ObjectArrayElementComparisonStrategy,StandardComparisonStrategy
public interface ComparisonStrategy
Describes the contract to implement a consistent comparison strategy that covers :
- comparing two objects for equality and order
- knowing if an object belongs to a group of objects (collection/array)
- determining duplicates in a group of objects (collection/array)
- string specific comparison
- comparing two objects for equality and order
- knowing if an object belongs to a group of objects (collection/array)
- determining duplicates in a group of objects (collection/array)
- string specific comparison
- Author:
- Joel Costigliola
-
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if actual and other are equal according to the implemented comparison strategy.booleanarrayContains(Object array, Object value) Returns true if given array contains given value according to the implemented comparison strategy, false otherwise.default StringasText()Used in error messages when a custom comparison strategy was used to compare values.Iterable<?> duplicatesFrom(Iterable<?> iterable) Returns any duplicate elements from the givenIterableaccording to the implemented comparison strategy.booleanisGreaterThan(Object actual, Object other) Returns true if actual is greater than other, false otherwise.booleanisGreaterThanOrEqualTo(Object actual, Object other) Returns true if actual is greater than or equal to other, false otherwise.booleanisLessThan(Object actual, Object other) Returns true if actual is less than other, false otherwise.booleanisLessThanOrEqualTo(Object actual, Object other) Returns true if actual is less than or equal to other, false otherwise.booleanReturn true if comparison strategy is default/standard, false otherwisebooleaniterableContains(Iterable<?> collection, Object value) voiditerableRemoves(Iterable<?> iterable, Object value) voiditerablesRemoveFirst(Iterable<?> iterable, Object value) Removes the first value initerablethat matches thevalueaccording to the implemented comparison strategy.booleanstringContains(String string, String sequence) Returns true if given string contains given sequence according to the implemented comparison strategy, false otherwise.booleanstringEndsWith(String string, String suffix) Returns true if string ends with suffix according to the implemented comparison strategy, false otherwise.booleanstringStartsWith(String string, String prefix) Returns true if string starts with prefix according to the implemented comparison strategy, false otherwise.
-
Method Details
-
areEqual
Returns true if actual and other are equal according to the implemented comparison strategy.- Parameters:
actual- the object to compare to otherother- the object to compare to actual- Returns:
- true if actual and other are equal according to the underlying comparison strategy.
-
isGreaterThan
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.
- Throws:
UnsupportedOperationException- if operation is not supported by a concrete implementation.
-
isGreaterThanOrEqualTo
Returns true if actual is greater than or equal to other, false otherwise.- Parameters:
actual- the object to compare to otherother- the object to compare to actual- Returns:
- true if actual is greater than or equal to other, false otherwise.
- Throws:
UnsupportedOperationException- if operation is not supported by a concrete implementation.
-
isLessThan
Returns true if actual is less than other, false otherwise.- Parameters:
actual- the object to compare to otherother- the object to compare to actual- Returns:
- true if actual is less than other, false otherwise.
- Throws:
UnsupportedOperationException- if operation is not supported by a concrete implementation.
-
isLessThanOrEqualTo
Returns true if actual is less than or equal to other, false otherwise.- Parameters:
actual- the object to compare to otherother- the object to compare to actual- Returns:
- true if actual is less than or equal to other, false otherwise.
- Throws:
UnsupportedOperationException- if operation is not supported by a concrete implementation.
-
iterableContains
-
iterableRemoves
-
iterablesRemoveFirst
Removes the first value initerablethat matches thevalueaccording to the implemented comparison strategy. If givenIterableis null, does nothing. -
duplicatesFrom
Returns any duplicate elements from the givenIterableaccording to the implemented comparison strategy. -
arrayContains
Returns true if given array contains given value according to the implemented comparison strategy, false otherwise.- Parameters:
array- the array to search value in (must not be null)value- the object to look for in given array- Returns:
- true if given array contains given value according to the implemented comparison strategy, false otherwise.
-
stringContains
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.
-
stringStartsWith
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
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.
-
isStandard
boolean isStandard()Return true if comparison strategy is default/standard, false otherwise- Returns:
- true if comparison strategy is default/standard, false otherwise
-
asText
Used in error messages when a custom comparison strategy was used to compare values.For example
ComparatorBasedComparisonStrategyreturns:"when comparing values using " + toString()- Returns:
- the comparison strategy description used in error messages.
-