public class Priority extends Object implements Comparable<Priority>
This class implements an extensible priority system based on lexicographical ordering. In its simplest use, Priority.create(0)
is ordered before Priority.create(1)
, then Priority.create(2)
, etc.
To create a priority that is ordered between two existing ones, simply add another parameter: Priority.create(1, 1)
comes after Priority.create(1)
, but before Priority.create(2)
. In this way,
priorities can always be inserted anywhere in a sequence.
The next()
method creates a priority that is ordered immediately following the current one, and is distinct
from all priorities obtained by any other means. This provides a convenient way to order entire segments of lists.
A special priority, obtained by Priority.getDefault()
, sorts before all other priorities.
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Priority o) |
static Priority |
create(int weight,
int... weights)
Create a
Priority with the given sequence. |
boolean |
equals(Object obj) |
static Priority |
getDefault() |
int |
hashCode() |
boolean |
isDefault() |
Priority |
next() |
String |
toString() |
public static Priority getDefault()
public static Priority create(int weight, int... weights)
Priority
with the given sequence.weight
- The first value of the weight sequence.weights
- An integer sequence. These sequences are sorted lexicographically, so Priority.create(1)
sorts before Priority.create(1, 1)
, which sorts before Priority.create(2)
.Priority
.public boolean isDefault()
getDefault()
.public Priority next()
Priority
which immediately follows this one, and which is distinct from all other
priorities obtained by create(int, int...)
.public int compareTo(Priority o)
compareTo
in interface Comparable<Priority>
Copyright © 2014. All rights reserved.