public final class PrioritySpec
extends java.lang.Object
ParameterType.
This allows parameters to explicitly mark themselves as of higher priority over other parameters, or of lower priority than others.
If a parameter has higher priority, it will be tested first to see if it can take certain input. If it can, parameters of lower priority will not be tested. Otherwise, the parser will move on to the next parameters.
It is always advisable to explicitly define some priority for mutually inclusive
parameters (i.e. parameters that both may work with the same input), such as
an enum and a String, or a int and a double.
Otherwise, Lamp has the right to execute either of them and makes no guarantees
whatsoever.
Note that it is sufficient to declare priority on a single type. If you declare that type A has higher priority than type B, you do not need to declare that type B has lower priority than type A. Either will suffice.
PrioritySpec can be created using toBuilder().
| Modifier and Type | Class and Description |
|---|---|
static class |
PrioritySpec.Builder
A builder for creating a
PrioritySpec. |
| Constructor and Description |
|---|
PrioritySpec(java.util.Comparator<ParameterType<?,?>> comparator) |
| Modifier and Type | Method and Description |
|---|---|
static @NotNull PrioritySpec.Builder |
builder()
Creates a new
PrioritySpec.Builder |
java.util.Comparator<ParameterType<?,?>> |
comparator() |
static @NotNull PrioritySpec |
defaultPriority()
The default
PrioritySpec, which treats all types with
equal priority. |
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
static @NotNull PrioritySpec |
highest()
Represents a
PrioritySpec that will always come first. |
static @NotNull PrioritySpec |
lowest()
Represents a
PrioritySpec that will always come last. |
@NotNull PrioritySpec.Builder |
toBuilder()
Creates a new
PrioritySpec.Builder from this priority specification |
java.lang.String |
toString() |
public PrioritySpec(java.util.Comparator<ParameterType<?,?>> comparator)
comparator - The underlying comparator of this priority specification.@Contract(value="-> new") @NotNull public static @NotNull PrioritySpec.Builder builder()
PrioritySpec.Builder@NotNull public static @NotNull PrioritySpec lowest()
PrioritySpec that will always come last. This
is useful for types that can accept any type
of input, such as a StringParameterType.PrioritySpec possible.@NotNull public static @NotNull PrioritySpec highest()
PrioritySpec that will always come first. This
is useful for types that can accept a certain, closed set of possible
values, such as boolean or enum types.
You should use this priority sparingly, and avoid it with inputs that do not have known values beforehand, or whose values may change over time.
This is best used
PrioritySpec possible.@NotNull public static @NotNull PrioritySpec defaultPriority()
PrioritySpec, which treats all types with
equal priority.@Contract(pure=true,
value="-> new")
@NotNull
public @NotNull PrioritySpec.Builder toBuilder()
PrioritySpec.Builder from this priority specificationpublic java.util.Comparator<ParameterType<?,?>> comparator()
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object