java.lang.Object
io.github.darvil.utils.MultiComparator<T>
- Type Parameters:
T- The type of the objects to compare.
A class that allows you to compare two objects using a list of predicates.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddPredicate(Predicate<T> p) Adds a predicate to the list of predicates to be used when comparing.addPredicate(Predicate<T> p, int priority) Adds a predicate to the list of predicates to be used when comparing.intCompares the two objects given using the predicates added to this comparator.
-
Constructor Details
-
MultiComparator
public MultiComparator()
-
-
Method Details
-
addPredicate
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
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
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.
-