public interface ContextSet extends Iterable<Context>
Context in the most basic sense simply means the circumstances where something will apply.
A single "context" consists of a key and a value, both strings. The key describes the type of the context, and the value represents what the key is set to.
For example, a context with key=world and value=world_nether
describes that a subject is in the "world_nether" world.
Contexts are exposed to end users and manipulated when managing permissions. For this reason, context keys should strike a balance between being descriptive and succinct.
Context keys and values are case-insensitive, and will be automatically
converted to lowercase when added to a
context set. Keys and values cannot be null or empty (len=0 or consisting of
only whitespace).
If a context key is formed of more than one word, the parts should be
separated by the '-' character. (e.g. "server-type")
If a context key is likely to conflict with another plugin, it should be
appropriately namespaced using the name of the plugin providing the context.
The namespace should be at the start of the context key, and separated using
the ':' character. (e.g. "worldguard:region" for WorldGuard
regions)
Contexts can be combined with each other to form so called "context sets" - simply a collection of context pairs.
Two default ContextSet implementations are provided.
MutableContextSet allows the addition and removal of context keys
after construction, and ImmutableContextSet does not.
| Modifier and Type | Method and Description |
|---|---|
default boolean |
contains(@NonNull Context entry)
Returns if the
ContextSet contains a given context pairing. |
boolean |
contains(@NonNull String key,
@NonNull String value)
Returns if the
ContextSet contains a given context pairing. |
default boolean |
containsAny(@NonNull String key,
@NonNull Iterable<String> values)
Returns if the
ContextSet contains any of the given context pairings. |
boolean |
containsKey(@NonNull String key)
Returns if the
ContextSet contains at least one value for the
given key. |
default @NonNull Optional<String> |
getAnyValue(@NonNull String key)
Returns any value from this
ContextSet matching the key, if present. |
@NonNull Set<String> |
getValues(@NonNull String key)
Returns a
Set of the values mapped to the given key. |
@NonNull ImmutableContextSet |
immutableCopy()
Returns an immutable representation of this
ContextSet. |
boolean |
isEmpty()
Returns if the
ContextSet is empty. |
boolean |
isImmutable()
Gets if this
ContextSet is immutable. |
default boolean |
isSatisfiedBy(@NonNull ContextSet other)
Returns if this
ContextSet is "satisfied" by another set. |
boolean |
isSatisfiedBy(@NonNull ContextSet other,
@NonNull ContextSatisfyMode mode)
Returns if this
ContextSet is "satisfied" by another set, according to the given
mode. |
@NonNull Iterator<Context> |
iterator()
Returns an
Iterator over each of the context pairs in this set. |
@NonNull MutableContextSet |
mutableCopy()
Creates a mutable copy of this
ContextSet. |
int |
size()
Gets the number of context pairs in the
ContextSet. |
@NonNull Map<String,String> |
toFlattenedMap()
Deprecated.
because the resultant map may not contain all data in the ContextSet
|
@NonNull Map<String,Set<String>> |
toMap()
Returns a
Map representing the current state of this
ContextSet. |
@NonNull Set<Context> |
toSet()
|
forEach, spliteratorboolean isImmutable()
ContextSet is immutable.
The state of immutable instances will never change.
@NonNull ImmutableContextSet immutableCopy()
ContextSet.
If the set is already immutable, the same object will be returned. If the set is mutable, an immutable copy will be made.
@NonNull MutableContextSet mutableCopy()
ContextSet.
A new copy is returned regardless of the
mutability of this set.
@NonNull Set<Context> toSet()
Set of Contexts representing the current
state of this ContextSet.
The returned set is immutable, and is a copy of the current set. (will not update live)
@NonNull Map<String,Set<String>> toMap()
Map representing the current state of this
ContextSet.
The returned set is immutable, and is a copy of the current set. (will not update live)
@Deprecated @NonNull Map<String,String> toFlattenedMap()
Map loosely representing the current state of
this ContextSet.
The returned map is immutable, and is a copy of the current set. (will not update live)
As a single context key can be mapped to multiple values, this method may not be a true representation of the set.
@NonNull Iterator<Context> iterator()
Iterator over each of the context pairs in this set.
The returned iterator represents the state of the set at the time of creation. It is not updated as the set changes.
The iterator does not support Iterator.remove() calls.
boolean containsKey(@NonNull String key)
ContextSet contains at least one value for the
given key.key - the key to check forNullPointerException - if the key is null@NonNull Set<String> getValues(@NonNull String key)
Set of the values mapped to the given key.
The returned set is immutable, and only represents the current state
of the ContextSet. (will not update live)
key - the key to get values forNullPointerException - if the key is nulldefault @NonNull Optional<String> getAnyValue(@NonNull String key)
ContextSet matching the key, if present.
Note that context keys can be mapped to multiple values.
Use getValues(String) to retrieve all associated values.
key - the key to find values forboolean contains(@NonNull String key, @NonNull String value)
ContextSet contains a given context pairing.key - the key to look forvalue - the value to look forNullPointerException - if the key or value is nulldefault boolean contains(@NonNull Context entry)
ContextSet contains a given context pairing.entry - the entry to look forNullPointerException - if the key or value is nulldefault boolean containsAny(@NonNull String key, @NonNull Iterable<String> values)
ContextSet contains any of the given context pairings.key - the key to look forvalues - the values to look fordefault boolean isSatisfiedBy(@NonNull ContextSet other)
ContextSet is "satisfied" by another set.
ContextSatisfyMode.AT_LEAST_ONE_VALUE_PER_KEY is the mode used by this method.
other - the other setboolean isSatisfiedBy(@NonNull ContextSet other, @NonNull ContextSatisfyMode mode)
ContextSet is "satisfied" by another set, according to the given
mode.other - the other setmode - the mode to useboolean isEmpty()
ContextSet is empty.int size()
ContextSet.