Class MultiComparator<T>

java.lang.Object
io.github.darvil.utils.MultiComparator<T>
Type Parameters:
T - The type of the objects to compare.

public class MultiComparator<T> extends Object
A class that allows you to compare two objects using a list of predicates.
  • Constructor Details

    • MultiComparator

      public MultiComparator()
  • Method Details

    • addPredicate

      public MultiComparator<T> addPredicate(Predicate<T> p, int priority)
      Adds a predicate to the list of predicates to be used when comparing.
      Parameters:
      p - The predicate to add.
      priority - The priority of the predicate. The higher the priority, the earlier the predicate will be checked.
    • addPredicate

      public MultiComparator<T> addPredicate(Predicate<T> p)
      Adds a predicate to the list of predicates to be used when comparing. The priority of the predicate will be 0.
      Parameters:
      p - The predicate to add.
    • compare

      public int compare(T first, T second)
      Compares the two objects given using the predicates added to this comparator.
      Parameters:
      first - The first object to compare.
      second - The second object to compare.
      Returns:
      -1 if the first object is "greater" than the second, 1 if the second object is "greater" than the first, 0 if they are equal.