Top Description Fields Constructors Methods
org.assertj.core.internal

public Class ComparatorBasedComparisonStrategy

extends AbstractComparisonStrategy
Class Inheritance
Static Imports
org.assertj.core.configuration.ConfigurationProvider.CONFIGURATION_PROVIDER, org.assertj.core.util.IterableUtil.isNullOrEmpty

Implements ComparisonStrategy contract with a comparison strategy based on a Comparator.
Author
Joel Costigliola

Field Summary

Modifier and TypeField and Description
private final Comparator<T>
private final String
pack-priv static final int

Constructor Summary

AccessConstructor and Description
public
ComparatorBasedComparisonStrategy(Comparator<T>
the comparison strategy to use.
comparator
)

Creates a new ComparatorBasedComparisonStrategy specifying the comparison strategy with given comparator.

public
ComparatorBasedComparisonStrategy(Comparator<T>
the comparison strategy to use.
comparator
,
String
the comparator description to use in assertion messages.
comparatorDescription
)

Creates a new ComparatorBasedComparisonStrategy specifying the comparison strategy with given comparator and comparator description

public
ComparatorBasedComparisonStrategy(DescribableComparator<?>
the comparator to use in the comparison strategy.
comparator
)

Creates a new ComparatorBasedComparisonStrategy specifying the comparison strategy with given DescribableComparator.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if actual and other are equal according to comparator, false otherwise.
areEqual
(Object
the object to compare to other
actual
,
Object
the object to compare to actual
other
)

Implements org.assertj.core.internal.ComparisonStrategy.areEqual.

Returns true if actual and other are equal according to comparator, false otherwise.
public String
asText()

Overrides default org.assertj.core.internal.ComparisonStrategy.asText.

Used in error messages when a custom comparison strategy was used to compare values.
public Iterable<?>

Returns:

an Iterable containing the duplicate elements of the given one. If no duplicates are found, an empty Iterable is returned.
duplicatesFrom
(Iterable<?>
the given Iterable we want to extract duplicate elements.
iterable
)

Overrides org.assertj.core.internal.AbstractComparisonStrategy.duplicatesFrom.

Implements org.assertj.core.internal.ComparisonStrategy.duplicatesFrom.

Returns any duplicate elements from the given Iterable according to comparator.
public Comparator<?>
public String
public boolean
isGreaterThan(Object
the object to compare to other
actual
,
Object
the object to compare to actual
other
)

Implements org.assertj.core.internal.ComparisonStrategy.isGreaterThan.

Returns true if actual is greater than other, false otherwise.
public boolean
isStandard()

Overrides org.assertj.core.internal.AbstractComparisonStrategy.isStandard.

Implements org.assertj.core.internal.ComparisonStrategy.isStandard.

Return true if comparison strategy is default/standard, false otherwise
public boolean

Returns:

true if given Iterable contains given value according to comparator, false otherwise.
iterableContains
(Iterable<?>
the Iterable to search value in
iterable
,
Object
the object to look for in given Iterable
value
)

Implements org.assertj.core.internal.ComparisonStrategy.iterableContains.

Returns true if given Iterable contains given value according to comparator, false otherwise.
public void
iterableRemoves(Iterable<?>
the Iterable we want remove value from
iterable
,
Object
object to remove from given Iterable
value
)

Implements org.assertj.core.internal.ComparisonStrategy.iterableRemoves.

Look for given value in given Iterable according to the Comparator, if value is found it is removed from it.
public void
iterablesRemoveFirst(Iterable<?>
the Iterable we want remove value from
iterable
,
Object
object to remove from given Iterable
value
)

Implements org.assertj.core.internal.ComparisonStrategy.iterablesRemoveFirst.

Removes the first value in iterable that matches the value according to the implemented comparison strategy.
protected Set<Object>
public boolean
stringContains(String
the string to search sequence in (must not be null)
string
,
String
the String to look for in given string
sequence
)

Implements org.assertj.core.internal.ComparisonStrategy.stringContains.

Returns true if given string contains given sequence according to the implemented comparison strategy, false otherwise.
public boolean
stringEndsWith(String
the String we want to look starting suffix
string
,
String
the suffix String to look for at string's end
suffix
)

Implements org.assertj.core.internal.ComparisonStrategy.stringEndsWith.

Returns true if string ends with suffix according to the implemented comparison strategy, false otherwise.
public boolean
stringStartsWith(String
the String we want to look starting prefix
string
,
String
the prefix String to look for at string's start
prefix
)

Implements org.assertj.core.internal.ComparisonStrategy.stringStartsWith.

Returns true if string starts with prefix according to the implemented comparison strategy, false otherwise.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.assertj.core.internal.AbstractComparisonStrategy:
arrayContainsisGreaterThanOrEqualToisLessThanisLessThanOrEqualTo

Field Detail

comparatorback to summary
private final Comparator<T> comparator
Annotations
@SuppressWarnings:rawtypes
comparatorDescriptionback to summary
private final String comparatorDescription
NOT_EQUALback to summary
pack-priv static final int NOT_EQUAL

Constructor Detail

ComparatorBasedComparisonStrategyback to summary
public ComparatorBasedComparisonStrategy(Comparator<T> comparator)

Creates a new ComparatorBasedComparisonStrategy specifying the comparison strategy with given comparator.

Parameters
comparator:Comparator<T>

the comparison strategy to use.

ComparatorBasedComparisonStrategyback to summary
public ComparatorBasedComparisonStrategy(Comparator<T> comparator, String comparatorDescription)

Creates a new ComparatorBasedComparisonStrategy specifying the comparison strategy with given comparator and comparator description

Parameters
comparator:Comparator<T>

the comparison strategy to use.

comparatorDescription:String

the comparator description to use in assertion messages.

ComparatorBasedComparisonStrategyback to summary
public ComparatorBasedComparisonStrategy(DescribableComparator<?> comparator)

Creates a new ComparatorBasedComparisonStrategy specifying the comparison strategy with given DescribableComparator.

Parameters
comparator:DescribableComparator<?>

the comparator to use in the comparison strategy.

Method Detail

areEqualback to summary
public boolean areEqual(Object actual, Object other)

Implements org.assertj.core.internal.ComparisonStrategy.areEqual.

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.

Parameters
actual:Object

the object to compare to other

other:Object

the object to compare to actual

Returns:boolean

true if actual and other are equal according to comparator, false otherwise.

Annotations
@Override
@SuppressWarnings:unchecked
asTextback to summary
public String asText()

Overrides default org.assertj.core.internal.ComparisonStrategy.asText.

Doc from org.assertj.core.internal.ComparisonStrategy.asText.

Used in error messages when a custom comparison strategy was used to compare values.

For example ComparatorBasedComparisonStrategy returns:

"when comparing values using " + toString()
Returns:String

the comparison strategy description used in error messages.

Annotations
@Override
duplicatesFromback to summary
public Iterable<?> duplicatesFrom(Iterable<?> iterable)

Overrides org.assertj.core.internal.AbstractComparisonStrategy.duplicatesFrom.

Implements org.assertj.core.internal.ComparisonStrategy.duplicatesFrom.

Returns any duplicate elements from the given Iterable according to comparator.

Parameters
iterable:Iterable<?>

the given Iterable we want to extract duplicate elements.

Returns:Iterable<?>

an Iterable containing the duplicate elements of the given one. If no duplicates are found, an empty Iterable is returned.

Annotations
@Override
getComparatorback to summary
public Comparator<?> getComparator()
getComparatorDescriptionback to summary
public String getComparatorDescription()
isGreaterThanback to summary
public boolean isGreaterThan(Object actual, Object other)

Implements org.assertj.core.internal.ComparisonStrategy.isGreaterThan.

Doc from org.assertj.core.internal.ComparisonStrategy.isGreaterThan.

Returns true if actual is greater than other, false otherwise.

Parameters
actual:Object

the object to compare to other

other:Object

the object to compare to actual

Returns:boolean

true if actual is greater than other, false otherwise.

Annotations
@Override
@SuppressWarnings:unchecked
isStandardback to summary
public boolean isStandard()

Overrides org.assertj.core.internal.AbstractComparisonStrategy.isStandard.

Implements org.assertj.core.internal.ComparisonStrategy.isStandard.

Doc from org.assertj.core.internal.ComparisonStrategy.isStandard.

Return true if comparison strategy is default/standard, false otherwise

Returns:boolean

true if comparison strategy is default/standard, false otherwise

Annotations
@Override
iterableContainsback to summary
public boolean iterableContains(Iterable<?> iterable, Object value)

Implements org.assertj.core.internal.ComparisonStrategy.iterableContains.

Returns true if given Iterable contains given value according to comparator, false otherwise.
If given Iterable is null or empty, return false.

Parameters
iterable:Iterable<?>

the Iterable to search value in

value:Object

the object to look for in given Iterable

Returns:boolean

true if given Iterable contains given value according to comparator, false otherwise.

Annotations
@Override
@SuppressWarnings:unchecked
iterableRemovesback to summary
public void iterableRemoves(Iterable<?> iterable, Object value)

Implements org.assertj.core.internal.ComparisonStrategy.iterableRemoves.

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).

Parameters
iterable:Iterable<?>

the Iterable we want remove value from

value:Object

object to remove from given Iterable

Annotations
@Override
@SuppressWarnings:unchecked
iterablesRemoveFirstback to summary
public void iterablesRemoveFirst(Iterable<?> iterable, Object value)

Implements org.assertj.core.internal.ComparisonStrategy.iterablesRemoveFirst.

Doc from org.assertj.core.internal.ComparisonStrategy.iterablesRemoveFirst.

Removes the first value in iterable that matches the value according to the implemented comparison strategy. If given Iterable is null, does nothing.

Parameters
iterable:Iterable<?>

the Iterable we want remove value from

value:Object

object to remove from given Iterable

Annotations
@Override
@SuppressWarnings:unchecked
newSetUsingComparisonStrategyback to summary
protected Set<Object> newSetUsingComparisonStrategy()

Implements abstract org.assertj.core.internal.AbstractComparisonStrategy.newSetUsingComparisonStrategy.

Doc from org.assertj.core.internal.AbstractComparisonStrategy.newSetUsingComparisonStrategy.

Returns a Set honoring the comparison strategy used.

Returns:Set<Object>

a Set honoring the comparison strategy used.

Annotations
@SuppressWarnings:unchecked
@Override
stringContainsback to summary
public boolean stringContains(String string, String sequence)

Implements org.assertj.core.internal.ComparisonStrategy.stringContains.

Doc from org.assertj.core.internal.ComparisonStrategy.stringContains.

Returns true if given string contains given sequence according to the implemented comparison strategy, false otherwise.

Parameters
string:String

the string to search sequence in (must not be null)

sequence:String

the String to look for in given string

Returns:boolean

true if given string contains given sequence according to the implemented comparison strategy, false otherwise.

Annotations
@Override
stringEndsWithback to summary
public boolean stringEndsWith(String string, String suffix)

Implements org.assertj.core.internal.ComparisonStrategy.stringEndsWith.

Doc from org.assertj.core.internal.ComparisonStrategy.stringEndsWith.

Returns true if string ends with suffix according to the implemented comparison strategy, false otherwise.

Parameters
string:String

the String we want to look starting suffix

suffix:String

the suffix String to look for at string's end

Returns:boolean

true if string ends with suffix according to the implemented comparison strategy, false otherwise.

Annotations
@Override
@SuppressWarnings:unchecked
stringStartsWithback to summary
public boolean stringStartsWith(String string, String prefix)

Implements org.assertj.core.internal.ComparisonStrategy.stringStartsWith.

Doc from org.assertj.core.internal.ComparisonStrategy.stringStartsWith.

Returns true if string starts with prefix according to the implemented comparison strategy, false otherwise.

Parameters
string:String

the String we want to look starting prefix

prefix:String

the prefix String to look for at string's start

Returns:boolean

true if string starts with prefix according to the implemented comparison strategy, false otherwise.

Annotations
@Override
@SuppressWarnings:unchecked
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override