Class SpecializationComparator
java.lang.Object
org.microbean.assign.SpecializationComparator
- All Implemented Interfaces:
Comparator<TypeMirror>
A
Comparator of TypeMirrors 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 intcompare(TypeMirror t, TypeMirror s) Compares twoTypeMirrors and returns the result.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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- ifdomainisnull
-
-
Method Details
-
compare
Compares twoTypeMirrors and returns the result.The following rules are evaluated in order to calculate the returned result:
If
t==s, ortandsare the same time, returns0.If
tisnullandsis not, returns a positive value.If
sisnullandtis not, returns a negative value.If
tis a subtype ofs, returns a negative value.If
sis a subtype oft, returns a positive value.In all other cases
.0is returned.- Specified by:
comparein interfaceComparator<TypeMirror>- Parameters:
t- aTypeMirror; may benulls- aTypeMirror; may benull- Returns:
- a comparison result
- See Also:
-