mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Some node equality changes
This commit is contained in:
parent
085e7af681
commit
de24817d9c
@ -430,17 +430,6 @@ public interface Node {
|
||||
@Override
|
||||
boolean equals(Object obj);
|
||||
|
||||
/**
|
||||
* Gets if this Node is equal to another node as defined by the given
|
||||
* {@link StandardNodeEquality} predicate.
|
||||
*
|
||||
* @param other the other node
|
||||
* @param equalityPredicate the predicate
|
||||
* @return true if this node is considered equal
|
||||
* @since 4.1
|
||||
*/
|
||||
boolean standardEquals(Node other, StandardNodeEquality equalityPredicate);
|
||||
|
||||
/**
|
||||
* Gets if this Node is equal to another node as defined by the given
|
||||
* {@link NodeEqualityPredicate}.
|
||||
@ -450,9 +439,7 @@ public interface Node {
|
||||
* @return true if this node is considered equal
|
||||
* @since 4.1
|
||||
*/
|
||||
default boolean equals(Node other, NodeEqualityPredicate equalityPredicate) {
|
||||
return equalityPredicate.areEqual(this, other);
|
||||
}
|
||||
boolean equals(Node other, NodeEqualityPredicate equalityPredicate);
|
||||
|
||||
/**
|
||||
* Similar to {@link Node#equals(Object)}, except doesn't take note of the
|
||||
|
@ -41,7 +41,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
public interface NodeEqualityPredicate {
|
||||
|
||||
/**
|
||||
* Returns if the two nodes are equal
|
||||
* Returns if the two nodes are equal.
|
||||
*
|
||||
* <p>This method should avoid making calls to {@link Node#equals(Node, NodeEqualityPredicate)}
|
||||
* with {@code this} as the second argument, directly or otherwise.</p>
|
||||
*
|
||||
* @param o1 the first node
|
||||
* @param o2 the second node
|
||||
|
@ -73,6 +73,6 @@ public enum StandardNodeEquality implements NodeEqualityPredicate {
|
||||
|
||||
@Override
|
||||
public boolean areEqual(@NonNull Node o1, @NonNull Node o2) {
|
||||
return o1.standardEquals(o2, this);
|
||||
return o1.equals(o2, this);
|
||||
}
|
||||
}
|
||||
|
@ -166,10 +166,12 @@ public final class NodeMap {
|
||||
}
|
||||
|
||||
private LocalizedNode localise(Node node) {
|
||||
if (node instanceof LocalizedNode) {
|
||||
while (node instanceof LocalizedNode) {
|
||||
LocalizedNode localizedNode = (LocalizedNode) node;
|
||||
if (this.holder.getObjectName().equals(localizedNode.getLocation())) {
|
||||
return localizedNode;
|
||||
} else {
|
||||
node = localizedNode.getNode();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,16 @@ import java.util.Optional;
|
||||
|
||||
public abstract class ForwardingNode implements Node {
|
||||
|
||||
static ImmutableNode unwrapForwarding(Node node) {
|
||||
while (node instanceof ForwardingNode) {
|
||||
node = ((ForwardingNode) node).delegate();
|
||||
}
|
||||
if (!(node instanceof ImmutableNode)) {
|
||||
throw new IllegalArgumentException("Node type cannot be casted to ImmutableNode: " + node.getClass());
|
||||
}
|
||||
return ((ImmutableNode) node);
|
||||
}
|
||||
|
||||
public abstract Node delegate();
|
||||
|
||||
@Override
|
||||
@ -224,11 +234,6 @@ public abstract class ForwardingNode implements Node {
|
||||
return delegate().getSuffix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean standardEquals(Node other, StandardNodeEquality equalityPredicate) {
|
||||
return delegate().standardEquals(other, equalityPredicate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Node other, NodeEqualityPredicate equalityPredicate) {
|
||||
return delegate().equals(other, equalityPredicate);
|
||||
|
@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.NodeEqualityPredicate;
|
||||
import me.lucko.luckperms.api.StandardNodeEquality;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
@ -273,37 +274,31 @@ public final class ImmutableNode implements Node {
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof Node)) return false;
|
||||
|
||||
Node other = (Node) o;
|
||||
while (other instanceof ForwardingNode) {
|
||||
other = ((ForwardingNode) other).delegate();
|
||||
}
|
||||
return other instanceof ImmutableNode && Equality.EXACT.areEqual(this, (ImmutableNode) other);
|
||||
return Equality.EXACT.areEqual(this, ForwardingNode.unwrapForwarding((Node) o));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean standardEquals(Node o, StandardNodeEquality equalityPredicate) {
|
||||
while (o instanceof ForwardingNode) {
|
||||
o = ((ForwardingNode) o).delegate();
|
||||
}
|
||||
if (!(o instanceof ImmutableNode)) {
|
||||
return false;
|
||||
}
|
||||
ImmutableNode other = (ImmutableNode) o;
|
||||
switch (equalityPredicate) {
|
||||
case EXACT:
|
||||
return Equality.EXACT.areEqual(this, other);
|
||||
case IGNORE_VALUE:
|
||||
return Equality.IGNORE_VALUE.areEqual(this, other);
|
||||
case IGNORE_EXPIRY_TIME:
|
||||
return Equality.IGNORE_EXPIRY_TIME.areEqual(this, other);
|
||||
case IGNORE_EXPIRY_TIME_AND_VALUE:
|
||||
return Equality.IGNORE_EXPIRY_TIME_AND_VALUE.areEqual(this, other);
|
||||
case IGNORE_VALUE_OR_IF_TEMPORARY:
|
||||
return Equality.IGNORE_VALUE_OR_IF_TEMPORARY.areEqual(this, other);
|
||||
default:
|
||||
throw new AssertionError();
|
||||
public boolean equals(Node o, NodeEqualityPredicate equalityPredicate) {
|
||||
if (equalityPredicate instanceof StandardNodeEquality) {
|
||||
StandardNodeEquality stdEqualityPredicate = (StandardNodeEquality) equalityPredicate;
|
||||
ImmutableNode other = ForwardingNode.unwrapForwarding(o);
|
||||
switch (stdEqualityPredicate) {
|
||||
case EXACT:
|
||||
return Equality.EXACT.areEqual(this, other);
|
||||
case IGNORE_VALUE:
|
||||
return Equality.IGNORE_VALUE.areEqual(this, other);
|
||||
case IGNORE_EXPIRY_TIME:
|
||||
return Equality.IGNORE_EXPIRY_TIME.areEqual(this, other);
|
||||
case IGNORE_EXPIRY_TIME_AND_VALUE:
|
||||
return Equality.IGNORE_EXPIRY_TIME_AND_VALUE.areEqual(this, other);
|
||||
case IGNORE_VALUE_OR_IF_TEMPORARY:
|
||||
return Equality.IGNORE_VALUE_OR_IF_TEMPORARY.areEqual(this, other);
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
return equalityPredicate.areEqual(this, o);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user