From cd5c8d7cdfd23b267d4f4504c8dad108f1bc2090 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 21 Dec 2019 19:58:37 -0500 Subject: [PATCH] NodeEqualityPredicate refactoring --- .../api/node/DummyNodeEqualityPredicate.java | 29 ++++ .../java/net/luckperms/api/node/Node.java | 13 +- .../api/node/NodeEqualityPredicate.java | 127 ++++++++++++------ .../luckperms/common/node/AbstractNode.java | 45 ++++--- 4 files changed, 150 insertions(+), 64 deletions(-) create mode 100644 api/src/main/java/net/luckperms/api/node/DummyNodeEqualityPredicate.java diff --git a/api/src/main/java/net/luckperms/api/node/DummyNodeEqualityPredicate.java b/api/src/main/java/net/luckperms/api/node/DummyNodeEqualityPredicate.java new file mode 100644 index 000000000..baddb7fba --- /dev/null +++ b/api/src/main/java/net/luckperms/api/node/DummyNodeEqualityPredicate.java @@ -0,0 +1,29 @@ +package net.luckperms.api.node; + +import org.checkerframework.checker.nullness.qual.NonNull; + +/** + * Dummy implementation of {@link NodeEqualityPredicate}, used for the given constant + * implementations. + * + *

The implementation rule of not calling {@link Node#equals(Node, NodeEqualityPredicate)} is + * intentionally disregarded by this dummy implementation. The equals method has a special case for + * the dummy instances, preventing a stack overflow.

+ */ +final class DummyNodeEqualityPredicate implements NodeEqualityPredicate { + private final String name; + + DummyNodeEqualityPredicate(String name) { + this.name = name; + } + + @Override + public boolean areEqual(@NonNull Node o1, @NonNull Node o2) { + return o1.equals(o2, this); + } + + @Override + public String toString() { + return "NodeEqualityPredicate#" + this.name; + } +} diff --git a/api/src/main/java/net/luckperms/api/node/Node.java b/api/src/main/java/net/luckperms/api/node/Node.java index 8e505645f..e1fa62958 100644 --- a/api/src/main/java/net/luckperms/api/node/Node.java +++ b/api/src/main/java/net/luckperms/api/node/Node.java @@ -63,15 +63,24 @@ import java.util.stream.Stream; * node, as well as methods to query and extract additional state and properties * from these settings.

* - *

Nodes have the following attributes:

+ *

Nodes have the following 4 key attributes:

*

* * + *

These are the key attributes which are considered when evaluating node + * {@link #equals(Object) equality}.

+ * + *

Nodes can also optionally have {@link #metadata(NodeMetadataKey) metadata} attached to them, + * added during construction using {@link NodeBuilder#withMetadata(NodeMetadataKey, Object)}, and + * queried using {@link #metadata(NodeMetadataKey)} and {@link #getMetadata(NodeMetadataKey)}. + * Such metadata is never considered when evaluating {@link #equals(Object)} or + * {@link #equals(Node, NodeEqualityPredicate)} (any form of equality check).

+ * *

There are a number of node types, all of which extend from this class:

*

*