Class Comparators

java.lang.Object
org.skriptlang.skript.lang.comparator.Comparators

public final class Comparators extends Object
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 Details

    • getComparatorInfos

      public static @Unmodifiable List<ComparatorInfo<?,?>> 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 use getComparator(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 of 'firstType' and 'secondType'.
    • compare

      public static <T1, T2> Relation compare(@Nullable T1 first, @Nullable T2 second)
      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

      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 of 'firstType' and 'secondType'. 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 of 'firstType' and 'secondType'. Will be null if no comparator capable of comparing two objects of 'firstType' and 'secondType' was found.
    • getComparatorInfo

      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 of 'firstType' and 'secondType'. 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 of 'firstType' and 'secondType'. Will be null if no info for comparing two objects of 'firstType' and 'secondType' was found.