Class SpecializationComparator
java.lang.Object
org.microbean.assign.SpecializationComparator
- All Implemented Interfaces:
Comparator<TypeMirror>
A
Comparator
of TypeMirror
s that establishes a partial order on its arguments, enforcing
only that more specialized types precede less specialized ones.
Instances of this class are (deliberately) not consistent with equals.- Author:
- Laird Nelson
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSpecializationComparator
(Domain domain) Creates a newSpecializationComparator
. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
compare
(TypeMirror t, TypeMirror s) Compares twoTypeMirror
s and returns the result.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
SpecializationComparator
Creates a newSpecializationComparator
.- Parameters:
domain
- aDomain
; must not benull
- Throws:
NullPointerException
- ifdomain
isnull
-
-
Method Details
-
compare
Compares twoTypeMirror
s and returns the result.The following rules are evaluated in order to calculate the returned result:
If
t
==
s
, ort
ands
are the same time, returns0
.If
t
isnull
ands
is not, returns a positive value.If
s
isnull
andt
is not, returns a negative value.If
t
is a subtype ofs
, returns a negative value.If
s
is a subtype oft
, returns a positive value.In all other cases
.0
is returned.- Specified by:
compare
in interfaceComparator<TypeMirror>
- Parameters:
t
- aTypeMirror
; may benull
s
- aTypeMirror
; may benull
- Returns:
- a comparison result
- See Also:
-