public class PrioritySorter<T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected static class |
PrioritySorter.PrioritizedObject<T> |
protected class |
PrioritySorter.PrioritizingComparator |
Constructor and Description |
---|
PrioritySorter()
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
PrioritySorter<T> |
add(T object,
int priority)
Adds an object with its associated priority.
|
static <E> PrioritySorter<E> |
create()
Creates a new instance of this class.
|
protected java.util.Comparator<? super T> |
createComparator() |
int |
getDefaultPriority()
Returns the default priority for objects not registered with this sorter.
|
protected java.util.function.BiFunction<T,T,java.lang.Boolean> |
getMatchFunction() |
protected PrioritySorter.PrioritizedObject<T> |
getPrioritizedObject(T object) |
protected java.util.List<PrioritySorter.PrioritizedObject<T>> |
getPrioritizedObjects() |
protected boolean |
matches(PrioritySorter.PrioritizedObject<T> prioritizedObject,
T object) |
PrioritySorter<T> |
setDefaultPriority(int defaultPriority)
Sets the default priority for objects not registered with this sorter
to the given value.
|
PrioritySorter<T> |
setMatchFunction(java.util.function.BiFunction<T,T,java.lang.Boolean> matchFunction)
Sets a function that will be used to match registered prioritized objects
against objects from the collection to be sorted.
|
java.util.List<T> |
sortAscending(java.util.Collection<T> collection)
Sorts the given list of objects according to their associated priorities.
|
java.util.List<T> |
sortDescending(java.util.Collection<T> collection)
Sorts the given list of objects according to their associated priorities
in a descending order.
|
public static <E> PrioritySorter<E> create()
public java.util.List<T> sortAscending(java.util.Collection<T> collection)
add(Object, int)
method will be detected by its
equals()
method and then compared for sorting by its associated
priority.
getDefaultPriority()
value.
The order of the input list will not be changed!
collection
- The collection of objects to be sorted (must not be null).public java.util.List<T> sortDescending(java.util.Collection<T> collection)
add(Object, int)
method will be detected by its
equals()
method and then compared for sorting by its associated
priority.
getDefaultPriority()
value.
The order of the input list will not be changed!
collection
- The collection of objects to be sorted (must not be null).public PrioritySorter<T> add(T object, int priority)
getDefaultPriority()
and is initialized to 100.object
- The object to register along with the given priority (must not be null).priority
- The priority value to associate to the given object.public int getDefaultPriority()
public PrioritySorter<T> setDefaultPriority(int defaultPriority)
defaultPriority
- The new default priority.public PrioritySorter<T> setMatchFunction(java.util.function.BiFunction<T,T,java.lang.Boolean> matchFunction)
equals()
will be used.
The first argument to the function's apply()
method is the registered
object and the second argument an element from the collection to be sorted.
matchFunction
- The function to match objects against registered prioritized objects.protected PrioritySorter.PrioritizedObject<T> getPrioritizedObject(T object)
protected boolean matches(PrioritySorter.PrioritizedObject<T> prioritizedObject, T object)
protected java.util.Comparator<? super T> createComparator()
protected java.util.List<PrioritySorter.PrioritizedObject<T>> getPrioritizedObjects()