public interface Node
The Node class encapsulates more than just permission assignments.
Nodes are used to store data about inherited groups, as well as assigned
prefixes, suffixes and meta values.
Combining these various states into one object (a "node") means that a holder only has to have one type of data set (a set of nodes) in order to take on various properties.
It is recommended that users of the API make use of Streams
to manipulate data and obtain the required information.
This interface provides a number of methods to read the attributes of the node, as well as methods to query and extract additional state and properties from these settings.
Nodes have the following 4 key attributes:
key - the key of the nodevalue - the value of the node (false for negated)context - the contexts required for this node to applyexpiry - the time when this node should expireThese are the key attributes which are considered when evaluating node
equality.
Nodes can also optionally have metadata attached to them,
added during construction using NodeBuilder.withMetadata(NodeMetadataKey, Object), and
queried using metadata(NodeMetadataKey) and getMetadata(NodeMetadataKey).
Such metadata is never considered when evaluating equals(Object) or
equals(Node, NodeEqualityPredicate) (any form of equality check).
There are a number of node types, all of which extend from this class:
PermissionNode - represents an assigned permissionRegexPermissionNode - represents an assigned regex permissionInheritanceNode - an "inheritance node" marks that the holder should inherit data from another groupPrefixNode - represents an assigned prefixSuffixNode - represents an assigned suffixMetaNode - represents an assigned meta optionWeightNode - marks the weight of the object holding this nodeDisplayNameNode - marks the display name of the object holding this nodeThe core node state must be immutable in all implementations.
| Modifier and Type | Method and Description |
|---|---|
static @NonNull NodeBuilder<?,?> |
builder(@NonNull String key)
Gets a
NodeBuilder for the given node key. |
boolean |
equals(@NonNull Node other,
@NonNull NodeEqualityPredicate equalityPredicate)
Gets if this Node is equal to another node as defined by the given
NodeEqualityPredicate. |
boolean |
equals(Object obj)
Gets if this Node is equal to another node.
|
@NonNull ImmutableContextSet |
getContexts()
Gets the contexts required for this node to apply.
|
@Nullable Instant |
getExpiry()
Gets the time when this node will expire.
|
@Nullable Duration |
getExpiryDuration()
Gets the time until this node will expire.
|
@NonNull String |
getKey()
Gets the key (
String) of the node. |
<T> Optional<T> |
getMetadata(NodeMetadataKey<T> key)
Gets the metadata corresponding to the given
key, if present. |
@NonNull NodeType<?> |
getType()
Gets the type of the node.
|
boolean |
getValue()
Gets the value of the node.
|
boolean |
hasExpired()
Gets if the node has expired.
|
boolean |
hasExpiry()
Gets if this node is assigned temporarily.
|
default boolean |
isNegated()
Gets if the node is negated.
|
default <T> T |
metadata(NodeMetadataKey<T> key)
Gets the metadata corresponding to the given
key, throwing an exception
if no data is present. |
@NonNull Collection<String> |
resolveShorthand()
Resolves any shorthand parts of this node and returns the full list of
resolved nodes.
|
@NonNull NodeBuilder<?,?> |
toBuilder()
Gets a
NodeBuilder, with the attributes of this node already
applied. |
static @NonNull NodeBuilder<?,?> builder(@NonNull String key)
NodeBuilder for the given node key.key - the key@NonNull NodeType<?> getType()
boolean getValue()
A negated setting would result in a value of false.
default boolean isNegated()
This is the inverse of the value.
@NonNull Collection<String> resolveShorthand()
The list will not contain the exact permission itself.
boolean hasExpiry()
@Nullable Instant getExpiry()
Instant when this node will expire, or
null if it doesn't have an expiry timeboolean hasExpired()
This returns false if the node is not temporary.
@Nullable Duration getExpiryDuration()
Returns null if the node doesn't have an expiry time,
and a negative duration if it has already expired.
@NonNull ImmutableContextSet getContexts()
<T> Optional<T> getMetadata(NodeMetadataKey<T> key)
key, if present.T - the metadata typekey - the keydefault <T> T metadata(NodeMetadataKey<T> key) throws IllegalStateException
key, throwing an exception
if no data is present.T - the metadata typekey - the keyIllegalStateException - if data isn't presentboolean equals(Object obj)
equals in class Objectobj - the other nodeNodeEqualityPredicate.EXACTboolean equals(@NonNull Node other, @NonNull NodeEqualityPredicate equalityPredicate)
NodeEqualityPredicate.other - the other nodeequalityPredicate - the predicate@NonNull NodeBuilder<?,?> toBuilder()
NodeBuilder, with the attributes of this node already
applied.