public class ComparatorBasedComparisonStrategy extends AbstractComparisonStrategy
ComparisonStrategy contract with a comparison strategy based on a Comparator.| Constructor and Description |
|---|
ComparatorBasedComparisonStrategy(Comparator comparator)
Creates a new
specifying the comparison strategy with given
comparator. |
ComparatorBasedComparisonStrategy(Comparator comparator,
String comparatorDescription)
Creates a new
specifying the comparison strategy with given
comparator and comparator description |
| Modifier and Type | Method and Description |
|---|---|
boolean |
areEqual(Object actual,
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. |
String |
asText() |
Iterable<?> |
duplicatesFrom(Iterable<?> iterable)
Returns any duplicate elements from the given
Iterable according to comparator. |
Comparator<?> |
getComparator() |
String |
getComparatorDescription() |
boolean |
isGreaterThan(Object actual,
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(Iterable<?> iterable,
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(Iterable<?> iterable,
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). |
void |
iterablesRemoveFirst(Iterable<?> iterable,
Object value)
Removes the first value in
iterable that matches the value according to the implemented comparison
strategy. |
protected Set<Object> |
newSetUsingComparisonStrategy()
Returns a
Set honoring the comparison strategy used. |
boolean |
stringContains(String string,
String sequence)
Returns true if given string contains given sequence according to the implemented comparison strategy, false otherwise.
|
boolean |
stringEndsWith(String string,
String suffix)
Returns true if string ends with suffix according to the implemented comparison strategy, false otherwise.
|
boolean |
stringStartsWith(String string,
String prefix)
Returns true if string starts with prefix according to the implemented comparison strategy, false otherwise.
|
String |
toString() |
arrayContains, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTopublic ComparatorBasedComparisonStrategy(Comparator comparator)
ComparatorBasedComparisonStrategy specifying the comparison strategy with given
comparator.comparator - the comparison strategy to use.public ComparatorBasedComparisonStrategy(Comparator comparator, String comparatorDescription)
ComparatorBasedComparisonStrategy specifying the comparison strategy with given
comparator and comparator descriptioncomparator - the comparison strategy to use.comparatorDescription - the comparator description to use in assertion messages.public boolean iterableContains(Iterable<?> iterable, 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 IterableIterable contains given value according to comparator, false otherwise.public void iterableRemoves(Iterable<?> iterable, Object value)
Iterable according to the Comparator, if value is found it is removed
from it.Iterable is null (meaning no exception thrown).public void iterablesRemoveFirst(Iterable<?> iterable, Object value)
ComparisonStrategyiterable that matches the value according to the implemented comparison
strategy. If given Iterable is null, does nothing.public boolean areEqual(Object actual, 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 Iterable<?> duplicatesFrom(Iterable<?> iterable)
Iterable according to comparator.duplicatesFrom in interface ComparisonStrategyduplicatesFrom in class AbstractComparisonStrategyiterable - 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 Set<Object> newSetUsingComparisonStrategy()
AbstractComparisonStrategySet honoring the comparison strategy used.newSetUsingComparisonStrategy in class AbstractComparisonStrategySet honoring the comparison strategy used.public String asText()
asText in class AbstractComparisonStrategypublic Comparator<?> getComparator()
public String getComparatorDescription()
public boolean stringStartsWith(String string, String prefix)
ComparisonStrategystring - the String we want to look starting prefixprefix - the prefix String to look for at string's startpublic boolean stringEndsWith(String string, String suffix)
ComparisonStrategystring - the String we want to look starting suffixsuffix - the suffix String to look for at string's endpublic boolean stringContains(String string, String sequence)
ComparisonStrategystring - the string to search sequence in (must not be null)sequence - the String to look for in given stringpublic boolean isGreaterThan(Object actual, Object other)
ComparisonStrategyactual - the object to compare to otherother - the object to compare to actualpublic boolean isStandard()
ComparisonStrategyisStandard in interface ComparisonStrategyisStandard in class AbstractComparisonStrategyCopyright © 2014–2019 AssertJ. All rights reserved.