Package org.assertj.core.internal
Class ComparatorBasedComparisonStrategy
- java.lang.Object
-
- org.assertj.core.internal.AbstractComparisonStrategy
-
- org.assertj.core.internal.ComparatorBasedComparisonStrategy
-
- All Implemented Interfaces:
ComparisonStrategy
public class ComparatorBasedComparisonStrategy extends AbstractComparisonStrategy
ImplementsComparisonStrategycontract with a comparison strategy based on aComparator.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Comparatorcomparatorprivate java.lang.StringcomparatorDescription(package private) static intNOT_EQUAL
-
Constructor Summary
Constructors Constructor Description ComparatorBasedComparisonStrategy(java.util.Comparator comparator)Creates a newspecifying the comparison strategy with given comparator.ComparatorBasedComparisonStrategyComparatorBasedComparisonStrategy(java.util.Comparator comparator, java.lang.String comparatorDescription)Creates a newspecifying the comparison strategy with given comparator and comparator descriptionComparatorBasedComparisonStrategyComparatorBasedComparisonStrategy(DescribableComparator<?> comparator)Creates a newspecifying the comparison strategy with givenComparatorBasedComparisonStrategyDescribableComparator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanareEqual(java.lang.Object actual, java.lang.Object other)Returns true if actual and other are equal according tocomparator, false otherwise.
Handles the cases where one of the parameter is null so that internalcomparatordoes not have too.java.lang.StringasText()Used in error messages when a custom comparison strategy was used to compare values.java.lang.Iterable<?>duplicatesFrom(java.lang.Iterable<?> iterable)Returns any duplicate elements from the givenIterableaccording tocomparator.java.util.Comparator<?>getComparator()java.lang.StringgetComparatorDescription()booleanisGreaterThan(java.lang.Object actual, java.lang.Object other)Returns true if actual is greater than other, false otherwise.booleanisStandard()Return true if comparison strategy is default/standard, false otherwisebooleaniterableContains(java.lang.Iterable<?> iterable, java.lang.Object value)Returns true if givenIterablecontains given value according tocomparator, false otherwise.
If givenIterableis null or empty, return false.voiditerableRemoves(java.lang.Iterable<?> iterable, java.lang.Object value)Look for given value in givenIterableaccording to theComparator, if value is found it is removed from it.
Does nothing if givenIterableis null (meaning no exception thrown).voiditerablesRemoveFirst(java.lang.Iterable<?> iterable, java.lang.Object value)Removes the first value initerablethat matches thevalueaccording to the implemented comparison strategy.protected java.util.Set<java.lang.Object>newSetUsingComparisonStrategy()Returns aSethonoring the comparison strategy used.booleanstringContains(java.lang.String string, java.lang.String sequence)Returns true if given string contains given sequence according to the implemented comparison strategy, false otherwise.booleanstringEndsWith(java.lang.String string, java.lang.String suffix)Returns true if string ends with suffix according to the implemented comparison strategy, false otherwise.booleanstringStartsWith(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.StringtoString()-
Methods inherited from class org.assertj.core.internal.AbstractComparisonStrategy
arrayContains, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo
-
-
-
-
Field Detail
-
NOT_EQUAL
static final int NOT_EQUAL
- See Also:
- Constant Field Values
-
comparator
private final java.util.Comparator comparator
-
comparatorDescription
private final java.lang.String comparatorDescription
-
-
Constructor Detail
-
ComparatorBasedComparisonStrategy
public ComparatorBasedComparisonStrategy(java.util.Comparator comparator)
Creates a newspecifying the comparison strategy with given comparator.ComparatorBasedComparisonStrategy- Parameters:
comparator- the comparison strategy to use.
-
ComparatorBasedComparisonStrategy
public ComparatorBasedComparisonStrategy(java.util.Comparator comparator, java.lang.String comparatorDescription)Creates a newspecifying the comparison strategy with given comparator and comparator descriptionComparatorBasedComparisonStrategy- Parameters:
comparator- the comparison strategy to use.comparatorDescription- the comparator description to use in assertion messages.
-
ComparatorBasedComparisonStrategy
public ComparatorBasedComparisonStrategy(DescribableComparator<?> comparator)
Creates a newspecifying the comparison strategy with givenComparatorBasedComparisonStrategyDescribableComparator.- Parameters:
comparator- the comparator to use in the comparison strategy.
-
-
Method Detail
-
iterableContains
public boolean iterableContains(java.lang.Iterable<?> iterable, java.lang.Object value)Returns true if givenIterablecontains given value according tocomparator, false otherwise.
If givenIterableis null or empty, return false.- Parameters:
iterable- theIterableto search value invalue- the object to look for in givenIterable- Returns:
- true if given
Iterablecontains given value according tocomparator, false otherwise.
-
iterableRemoves
public void iterableRemoves(java.lang.Iterable<?> iterable, java.lang.Object value)Look for given value in givenIterableaccording to theComparator, if value is found it is removed from it.
Does nothing if givenIterableis null (meaning no exception thrown).- Parameters:
iterable- theIterablewe want remove value fromvalue- object to remove from givenIterable
-
iterablesRemoveFirst
public void iterablesRemoveFirst(java.lang.Iterable<?> iterable, java.lang.Object value)Description copied from interface:ComparisonStrategyRemoves the first value initerablethat matches thevalueaccording to the implemented comparison strategy. If givenIterableis null, does nothing.- Parameters:
iterable- theIterablewe want remove value fromvalue- object to remove from givenIterable
-
areEqual
public boolean areEqual(java.lang.Object actual, java.lang.Object other)Returns true if actual and other are equal according tocomparator, false otherwise.
Handles the cases where one of the parameter is null so that internalcomparatordoes not have too.- Parameters:
actual- the object to compare to otherother- the object to compare to actual- Returns:
- true if actual and other are equal according to
comparator, false otherwise.
-
duplicatesFrom
public java.lang.Iterable<?> duplicatesFrom(java.lang.Iterable<?> iterable)
Returns any duplicate elements from the givenIterableaccording tocomparator.- Specified by:
duplicatesFromin interfaceComparisonStrategy- Overrides:
duplicatesFromin classAbstractComparisonStrategy- Parameters:
iterable- the givenIterablewe want to extract duplicate elements.- Returns:
- an
Iterablecontaining the duplicate elements of the given one. If no duplicates are found, an emptyIterableis returned.
-
newSetUsingComparisonStrategy
protected java.util.Set<java.lang.Object> newSetUsingComparisonStrategy()
Description copied from class:AbstractComparisonStrategyReturns aSethonoring the comparison strategy used.- Specified by:
newSetUsingComparisonStrategyin classAbstractComparisonStrategy- Returns:
- a
Sethonoring the comparison strategy used.
-
asText
public java.lang.String asText()
Description copied from interface:ComparisonStrategyUsed 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.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getComparator
public java.util.Comparator<?> getComparator()
-
getComparatorDescription
public java.lang.String getComparatorDescription()
-
stringStartsWith
public boolean stringStartsWith(java.lang.String string, java.lang.String prefix)Description copied from interface:ComparisonStrategyReturns 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:ComparisonStrategyReturns 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:ComparisonStrategyReturns 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:ComparisonStrategyReturns 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.
-
isStandard
public boolean isStandard()
Description copied from interface:ComparisonStrategyReturn true if comparison strategy is default/standard, false otherwise- Specified by:
isStandardin interfaceComparisonStrategy- Overrides:
isStandardin classAbstractComparisonStrategy- Returns:
- true if comparison strategy is default/standard, false otherwise
-
-