Package org.assertj.core.internal
Class TypeComparators
java.lang.Object
org.assertj.core.internal.TypeComparators
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.
- Author:
- Filip Hrisafov
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all registered entities.Stream<Map.Entry<Class<?>, Comparator<?>>> Returns a sequence of all type-comparator pairs which the current holder supplies.static TypeComparatorsStream<Map.Entry<Class<?>, Comparator<?>>> Returns a sequence of all type-entity pairs which the current holder supplies.booleanComparator<?> This method returns the most relevant entity for the given class.Comparator<?> getComparatorForType(Class<?> clazz) This method returns the most relevant comparator for the given class.booleanhasComparatorForType(Class<?> type) Checks, whether an any custom comparator is associated with the giving type.booleanChecks, whether an entity is associated with the giving type.inthashCode()booleanisEmpty()voidput(Class<?> clazz, Comparator<?> entity) Puts theentityfor the givenclazz.<T> voidregisterComparator(Class<T> clazz, Comparator<? super T> comparator) Puts thecomparatorfor the givenclazz.toString()
-
Field Details
-
typeHolder
-
-
Constructor Details
-
TypeComparators
public TypeComparators()
-
-
Method Details
-
defaultTypeComparators
-
getComparatorForType
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 forclazzthen this one is used 2. We check if there is a registered comparator for a superclass ofclazz3. 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
nullif no comparator could be found
-
hasComparatorForType
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
Puts thecomparatorfor the givenclazz.- Type Parameters:
T- the type of the objects for the comparator- Parameters:
clazz- the class for the comparatorcomparator- the comparator itself
-
comparatorByTypes
Returns a sequence of all type-comparator pairs which the current holder supplies.- Returns:
- sequence of field-comparator pairs
-
get
This method returns the most relevant entity for the given class. The most relevant entity is the entity 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 entity forclazzthen this one is used 2. We check if there is a registered entity for a superclass ofclazz3. We check if there is a registered entity for an interface ofclazz- Parameters:
clazz- the class for which to find a entity- Returns:
- the most relevant entity, or
nullif on entity could be found
-
put
Puts theentityfor the givenclazz.- Parameters:
clazz- the class for the comparatorentity- the entity itself
-
hasEntity
Checks, whether an entity is associated with the giving type.- Parameters:
type- the type for which to check an entity- Returns:
- is the giving type associated with any entity
-
isEmpty
public boolean isEmpty()- Returns:
trueis there are registered entities,falseotherwise
-
clear
public void clear()Removes all registered entities. -
entityByTypes
Returns a sequence of all type-entity pairs which the current holder supplies.- Returns:
- sequence of field-entity pairs
-
equals
-
hashCode
public int hashCode() -
toString
-