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 booleancomparatorExists(Class<?> firstType, Class<?> secondType) A method for determining whether a Comparator offirstTypeandsecondTypeexists.static <T1,T2> Relation compare(T1 first, T2 second) Compares two objects to see if a Relation exists between them.static booleanexactComparatorExists(Class<?> firstType, Class<?> secondType) A method for determining whether a direct Comparator offirstTypeandsecondTypeexists.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 offirstTypeandsecondType.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 offirstTypeandsecondType.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
ComparatorInfos. 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 offirstTypeandsecondType.
-
exactComparatorExists
A method for determining whether a direct Comparator offirstTypeandsecondTypeexists. Unlike other methods of this class, it is not the case thatSkript.isAcceptRegistrations()must returnfalsefor this method to be used.- Parameters:
firstType- The first type for comparison.secondType- The second type for comparison.- Returns:
- Whether a direct Comparator of
firstTypeandsecondTypeexists.
-
comparatorExists
A method for determining whether a Comparator offirstTypeandsecondTypeexists.- Parameters:
firstType- The first type for comparison.secondType- The second type for comparison.- Returns:
- Whether a Comparator of
firstTypeandsecondTypeexists.
-
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_EQUALif 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 offirstTypeandsecondType. 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
Relationbetween two objects offirstTypeandsecondType. Will be null if no comparator capable of comparing two objects offirstTypeandsecondTypewas 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 offirstTypeandsecondType. 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
Relationbetween two objects offirstTypeandsecondType. Will be null if no info for comparing two objects offirstTypeandsecondTypewas found.
-