Package org.fest.assertions.internal
Class ComparatorBasedComparisonStrategy
- java.lang.Object
-
- org.fest.assertions.internal.AbstractComparisonStrategy
-
- org.fest.assertions.internal.ComparatorBasedComparisonStrategy
-
- All Implemented Interfaces:
ComparisonStrategy
public class ComparatorBasedComparisonStrategy extends AbstractComparisonStrategy
ImplementsComparisonStrategy
contract with a comparison strategy based on aComparator
.- Author:
- Joel Costigliola
-
-
Constructor Summary
Constructors Constructor Description ComparatorBasedComparisonStrategy(java.util.Comparator comparator)
Creates a newComparatorBasedComparisonStrategy
specifying the comparison strategy with given comparator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 internalcomparator
does not have too.java.lang.Iterable<?>
duplicatesFrom(java.lang.Iterable<?> iterable)
Returns any duplicate elements from the givenIterable
according tocomparator
.java.util.Comparator<?>
getComparator()
boolean
isGreaterThan(java.lang.Object actual, java.lang.Object other)
Returns true if actual is greater than other, false otherwise.boolean
iterableContains(java.lang.Iterable<?> iterable, java.lang.Object value)
Returns true if givenIterable
contains given value according tocomparator
, false otherwise.
If givenIterable
is null or empty, return false.void
iterableRemoves(java.lang.Iterable<?> iterable, java.lang.Object value)
Look for given value in givenIterable
according to theComparator
, if value is found it is removed from it.
Does nothing if givenIterable
is null (meaning no exception thrown).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 sstring 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.java.lang.String
toString()
-
Methods inherited from class org.fest.assertions.internal.AbstractComparisonStrategy
arrayContains, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo
-
-
-
-
Constructor Detail
-
ComparatorBasedComparisonStrategy
public ComparatorBasedComparisonStrategy(java.util.Comparator comparator)
Creates a newComparatorBasedComparisonStrategy
specifying the comparison strategy with given comparator.- Parameters:
comparator
- the comparison strategy to use.
-
-
Method Detail
-
iterableContains
public boolean iterableContains(java.lang.Iterable<?> iterable, java.lang.Object value)
Returns true if givenIterable
contains given value according tocomparator
, false otherwise.
If givenIterable
is null or empty, return false.- Parameters:
iterable
- theIterable
to search value invalue
- the object to look for in givenIterable
- Returns:
- true if given
Iterable
contains given value according tocomparator
, false otherwise.
-
iterableRemoves
public void iterableRemoves(java.lang.Iterable<?> iterable, java.lang.Object value)
Look for given value in givenIterable
according to theComparator
, if value is found it is removed from it.
Does nothing if givenIterable
is null (meaning no exception thrown).- Parameters:
iterable
- theIterable
we 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 internalcomparator
does 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 givenIterable
according tocomparator
.- 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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getComparator
public java.util.Comparator<?> getComparator()
-
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 sstring 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.
-
-