Package org.assertj.core.internal
Class TypeComparators
- java.lang.Object
-
- org.assertj.core.internal.TypeHolder<java.util.Comparator<?>>
-
- org.assertj.core.internal.TypeComparators
-
public class TypeComparators extends TypeHolder<java.util.Comparator<?>>
An internal holder of the comparators for type. It is used to store comparators for registered classes. When looking for a Comparator for a given class the holder returns the most relevant comparator.
-
-
Field Summary
Fields Modifier and Type Field Description private static DoubleComparator
DEFAULT_DOUBLE_COMPARATOR
private static FloatComparator
DEFAULT_FLOAT_COMPARATOR
private static java.util.Comparator<java.nio.file.Path>
DEFAULT_PATH_COMPARATOR
private static double
DOUBLE_COMPARATOR_PRECISION
private static float
FLOAT_COMPARATOR_PRECISION
-
Fields inherited from class org.assertj.core.internal.TypeHolder
typeHolder
-
-
Constructor Summary
Constructors Constructor Description TypeComparators()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.stream.Stream<java.util.Map.Entry<java.lang.Class<?>,java.util.Comparator<?>>>
comparatorByTypes()
Returns a sequence of all type-comparator pairs which the current holder supplies.static TypeComparators
defaultTypeComparators()
java.util.Comparator<?>
getComparatorForType(java.lang.Class<?> clazz)
This method returns the most relevant comparator for the given class.boolean
hasComparatorForType(java.lang.Class<?> type)
Checks, whether an any custom comparator is associated with the giving type.<T> void
registerComparator(java.lang.Class<T> clazz, java.util.Comparator<? super T> comparator)
Puts thecomparator
for the givenclazz
.-
Methods inherited from class org.assertj.core.internal.TypeHolder
clear, entityByTypes, equals, get, hasEntity, hashCode, isEmpty, put, toString
-
-
-
-
Field Detail
-
DOUBLE_COMPARATOR_PRECISION
private static final double DOUBLE_COMPARATOR_PRECISION
- See Also:
- Constant Field Values
-
DEFAULT_DOUBLE_COMPARATOR
private static final DoubleComparator DEFAULT_DOUBLE_COMPARATOR
-
FLOAT_COMPARATOR_PRECISION
private static final float FLOAT_COMPARATOR_PRECISION
- See Also:
- Constant Field Values
-
DEFAULT_FLOAT_COMPARATOR
private static final FloatComparator DEFAULT_FLOAT_COMPARATOR
-
DEFAULT_PATH_COMPARATOR
private static final java.util.Comparator<java.nio.file.Path> DEFAULT_PATH_COMPARATOR
-
-
Method Detail
-
defaultTypeComparators
public static TypeComparators defaultTypeComparators()
-
getComparatorForType
public java.util.Comparator<?> getComparatorForType(java.lang.Class<?> clazz)
This method returns the most relevant comparator for the given class. The most relevant comparator is the comparator which is registered for the class that is closest in the inheritance chain of the givenclazz
. The order of checks is the following: 1. If there is a registered comparator forclazz
then this one is used 2. We check if there is a registered comparator for a superclass ofclazz
3. We check if there is a registered comparator for an interface ofclazz
- Parameters:
clazz
- the class for which to find a comparator- Returns:
- the most relevant comparator, or
null
if no comparator could be found
-
hasComparatorForType
public boolean hasComparatorForType(java.lang.Class<?> type)
Checks, whether an any custom comparator is associated with the giving type.- Parameters:
type
- the type for which to check a comparator- Returns:
- is the giving type associated with any custom comparator
-
registerComparator
public <T> void registerComparator(java.lang.Class<T> clazz, java.util.Comparator<? super T> comparator)
Puts thecomparator
for the givenclazz
.- Type Parameters:
T
- the type of the objects for the comparator- Parameters:
clazz
- the class for the comparatorcomparator
- the comparator itself
-
comparatorByTypes
public java.util.stream.Stream<java.util.Map.Entry<java.lang.Class<?>,java.util.Comparator<?>>> comparatorByTypes()
Returns a sequence of all type-comparator pairs which the current holder supplies.- Returns:
- sequence of field-comparator pairs
-
-