Class Comparators
java.lang.Object
org.skriptlang.skript.lang.comparator.Comparators
Comparators are used to provide Skript with specific instructions for comparing two objects.
By integrating with the
Converter
system, comparators can be used to compare two objects.
that seemingly have no Relation
.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
comparatorExists
(Class<?> firstType, Class<?> secondType) A method for determining whether a Comparator offirstType
andsecondType
exists.static <T1,
T2> Relation compare
(T1 first, T2 second) Compares two objects to see if a Relation exists between them.static boolean
exactComparatorExists
(Class<?> firstType, Class<?> secondType) A method for determining whether a direct Comparator offirstType
andsecondType
exists.static <T1,
T2> @Nullable Comparator <T1, T2> getComparator
(Class<T1> firstType, Class<T2> secondType) A method for obtaining a Comparator that can compare two objects offirstType
andsecondType
.static <T1,
T2> @Nullable ComparatorInfo <T1, T2> getComparatorInfo
(Class<T1> firstType, Class<T2> secondType) A method for obtaining the info of a Comparator that can compare two objects offirstType
andsecondType
.static @Unmodifiable List
<ComparatorInfo<?, ?>> static <T1,
T2> void registerComparator
(Class<T1> firstType, Class<T2> secondType, Comparator<T1, T2> comparator) Registers a new Comparator with Skript's collection of Comparators.
-
Method Details
-
getComparatorInfos
- Returns:
- An unmodifiable list containing all registered
ComparatorInfo
s. Please note that this does not include any special Comparators resolved by Skript during runtime. This method ONLY returns Comparators explicitly registered during registration. Thus, it is recommended to usegetComparator(Class, Class)
if possible.
-
registerComparator
public static <T1,T2> void registerComparator(Class<T1> firstType, Class<T2> secondType, Comparator<T1, T2> comparator) Registers a new Comparator with Skript's collection of Comparators.- Parameters:
firstType
- The first type for comparison.secondType
- The second type for comparison.comparator
- A Comparator for comparing objects offirstType
andsecondType
.
-
exactComparatorExists
A method for determining whether a direct Comparator offirstType
andsecondType
exists. Unlike other methods of this class, it is not the case thatSkript.isAcceptRegistrations()
must returnfalse
for this method to be used.- Parameters:
firstType
- The first type for comparison.secondType
- The second type for comparison.- Returns:
- Whether a direct Comparator of
firstType
andsecondType
exists.
-
comparatorExists
A method for determining whether a Comparator offirstType
andsecondType
exists.- Parameters:
firstType
- The first type for comparison.secondType
- The second type for comparison.- Returns:
- Whether a Comparator of
firstType
andsecondType
exists.
-
compare
Compares two objects to see if a Relation exists between them.- Parameters:
first
- The first object for comparison.second
- The second object for comparison.- Returns:
- The Relation between the two provided objects.
Guaranteed to be
Relation.NOT_EQUAL
if either parameter is null.
-
getComparator
@Nullable public static <T1,T2> @Nullable Comparator<T1,T2> getComparator(Class<T1> firstType, Class<T2> secondType) A method for obtaining a Comparator that can compare two objects offirstType
andsecondType
. Please note that comparators may convert objects if necessary for comparisons.- Parameters:
firstType
- The first type for comparison.secondType
- The second type for comparison.- Returns:
- A Comparator capable of determine the
Relation
between two objects offirstType
andsecondType
. Will be null if no comparator capable of comparing two objects offirstType
andsecondType
was found.
-
getComparatorInfo
@Nullable public static <T1,T2> @Nullable ComparatorInfo<T1,T2> getComparatorInfo(Class<T1> firstType, Class<T2> secondType) A method for obtaining the info of a Comparator that can compare two objects offirstType
andsecondType
. Please note that comparators may convert objects if necessary for comparisons.- Parameters:
firstType
- The first type for comparison.secondType
- The second type for comparison.- Returns:
- The info of a Comparator capable of determine the
Relation
between two objects offirstType
andsecondType
. Will be null if no info for comparing two objects offirstType
andsecondType
was found.
-