org.assertj.core.internal
Class StandardComparisonStrategy

java.lang.Object
  extended by org.assertj.core.internal.AbstractComparisonStrategy
      extended by org.assertj.core.internal.StandardComparisonStrategy
All Implemented Interfaces:
ComparisonStrategy
Direct Known Subclasses:
IterableElementComparisonStrategy

public class StandardComparisonStrategy
extends AbstractComparisonStrategy

Implements ComparisonStrategy contract with a comparison strategy based on Objects.areEqual(Object, Object) method, it is also based on Comparable.compareTo(Object) when Object are Comparable method.

Author:
Joel Costigliola

Constructor Summary
protected StandardComparisonStrategy()
          Creates a new StandardComparisonStrategy, comparison strategy being based on Objects.areEqual(Object, Object).
 
Method Summary
 boolean areEqual(Object actual, Object other)
          Returns true if actual and other are equal based on Objects.areEqual(Object, Object), false otherwise.
 String asText()
           
 Iterable<?> duplicatesFrom(Iterable<?> iterable)
          Returns any duplicate elements from the given collection according to Objects.areEqual(Object, Object) comparison strategy.
static StandardComparisonStrategy instance()
          Returns the singleton instance of this class.
 boolean isGreaterThan(Object actual, Object other)
          Returns true if actual is greater than other, false otherwise.
 boolean isLessThan(Object actual, Object other)
          Returns true if actual is less 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 based on Objects.areEqual(Object, Object), false otherwise.
If given Iterable is null, return false.
 void iterableRemoves(Iterable<?> iterable, Object value)
          Look for given value in given Iterable according to the implemented comparison strategy, if value is found it is removed from it.
If given Iterable is null, does nothing.
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 sstring 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.
 
Methods inherited from class org.assertj.core.internal.AbstractComparisonStrategy
arrayContains, isGreaterThanOrEqualTo, isLessThanOrEqualTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardComparisonStrategy

protected StandardComparisonStrategy()
Creates a new StandardComparisonStrategy, comparison strategy being based on Objects.areEqual(Object, Object).

Method Detail

instance

public static StandardComparisonStrategy instance()
Returns the singleton instance of this class.

Returns:
the singleton instance of this class.

newSetUsingComparisonStrategy

protected Set<Object> newSetUsingComparisonStrategy()
Description copied from class: AbstractComparisonStrategy
Returns a Set honoring the comparison strategy used.

Specified by:
newSetUsingComparisonStrategy in class AbstractComparisonStrategy
Returns:
a Set honoring the comparison strategy used.

asText

public String asText()
Specified by:
asText in class AbstractComparisonStrategy

areEqual

public boolean areEqual(Object actual,
                        Object other)
Returns true if actual and other are equal based on Objects.areEqual(Object, Object), false otherwise.

Parameters:
actual - the object to compare to other
other - the object to compare to actual
Returns:
true if actual and other are equal based on Objects.areEqual(Object, Object), false otherwise.

iterableContains

public boolean iterableContains(Iterable<?> iterable,
                                Object value)
Returns true if given Iterable contains given value based on Objects.areEqual(Object, Object), false otherwise.
If given Iterable is null, return false.

Parameters:
iterable - the Iterable to search value in
value - the object to look for in given Iterable
Returns:
true if given Iterable contains given value based on Objects.areEqual(Object, Object), false otherwise.

iterableRemoves

public void iterableRemoves(Iterable<?> iterable,
                            Object value)
Look for given value in given Iterable according to the implemented comparison strategy, if value is found it is removed from it.
If given Iterable is null, does nothing.

Parameters:
iterable - the Iterable we want remove value from
value - object to remove from given Iterable

duplicatesFrom

public Iterable<?> duplicatesFrom(Iterable<?> iterable)
Returns any duplicate elements from the given collection according to Objects.areEqual(Object, Object) comparison strategy.

Specified by:
duplicatesFrom in interface ComparisonStrategy
Overrides:
duplicatesFrom in class AbstractComparisonStrategy
Parameters:
iterable - the given Iterable we want to extract duplicate elements.
Returns:
an Iterable containing the duplicate elements of the given one. If no duplicates are found, an empty Iterable is returned.

stringStartsWith

public boolean stringStartsWith(String string,
                                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 prefix
prefix - 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(String string,
                              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 suffix
suffix - 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(String string,
                              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(Object actual,
                             Object other)
Description copied from interface: ComparisonStrategy
Returns true if actual is greater than other, false otherwise.

Parameters:
actual - the object to compare to other
other - the object to compare to actual
Returns:
true if actual is greater than other, false otherwise.

isLessThan

public boolean isLessThan(Object actual,
                          Object other)
Description copied from interface: ComparisonStrategy
Returns true if actual is less than other, false otherwise.

Specified by:
isLessThan in interface ComparisonStrategy
Overrides:
isLessThan in class AbstractComparisonStrategy
Parameters:
actual - the object to compare to other
other - the object to compare to actual
Returns:
true if actual is less than other, false otherwise.

isStandard

public boolean isStandard()
Description copied from interface: ComparisonStrategy
Return true if comparison strategy is default/standard, false otherwise

Specified by:
isStandard in interface ComparisonStrategy
Overrides:
isStandard in class AbstractComparisonStrategy
Returns:
true if comparison strategy is default/standard, false otherwise


Copyright © 2013–2015 AssertJ. All rights reserved.