mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Some node equality changes
This commit is contained in:
parent
085e7af681
commit
de24817d9c
@ -430,17 +430,6 @@ public interface Node {
|
|||||||
@Override
|
@Override
|
||||||
boolean equals(Object obj);
|
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
|
* Gets if this Node is equal to another node as defined by the given
|
||||||
* {@link NodeEqualityPredicate}.
|
* {@link NodeEqualityPredicate}.
|
||||||
@ -450,9 +439,7 @@ public interface Node {
|
|||||||
* @return true if this node is considered equal
|
* @return true if this node is considered equal
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*/
|
*/
|
||||||
default boolean equals(Node other, NodeEqualityPredicate equalityPredicate) {
|
boolean equals(Node other, NodeEqualityPredicate equalityPredicate);
|
||||||
return equalityPredicate.areEqual(this, other);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Similar to {@link Node#equals(Object)}, except doesn't take note of the
|
* 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 {
|
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 o1 the first node
|
||||||
* @param o2 the second node
|
* @param o2 the second node
|
||||||
|
@ -73,6 +73,6 @@ public enum StandardNodeEquality implements NodeEqualityPredicate {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areEqual(@NonNull Node o1, @NonNull Node o2) {
|
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) {
|
private LocalizedNode localise(Node node) {
|
||||||
if (node instanceof LocalizedNode) {
|
while (node instanceof LocalizedNode) {
|
||||||
LocalizedNode localizedNode = (LocalizedNode) node;
|
LocalizedNode localizedNode = (LocalizedNode) node;
|
||||||
if (this.holder.getObjectName().equals(localizedNode.getLocation())) {
|
if (this.holder.getObjectName().equals(localizedNode.getLocation())) {
|
||||||
return localizedNode;
|
return localizedNode;
|
||||||
|
} else {
|
||||||
|
node = localizedNode.getNode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,16 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public abstract class ForwardingNode implements Node {
|
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();
|
public abstract Node delegate();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -224,11 +234,6 @@ public abstract class ForwardingNode implements Node {
|
|||||||
return delegate().getSuffix();
|
return delegate().getSuffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean standardEquals(Node other, StandardNodeEquality equalityPredicate) {
|
|
||||||
return delegate().standardEquals(other, equalityPredicate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Node other, NodeEqualityPredicate equalityPredicate) {
|
public boolean equals(Node other, NodeEqualityPredicate equalityPredicate) {
|
||||||
return delegate().equals(other, 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.Contexts;
|
||||||
import me.lucko.luckperms.api.Node;
|
import me.lucko.luckperms.api.Node;
|
||||||
|
import me.lucko.luckperms.api.NodeEqualityPredicate;
|
||||||
import me.lucko.luckperms.api.StandardNodeEquality;
|
import me.lucko.luckperms.api.StandardNodeEquality;
|
||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
@ -273,37 +274,31 @@ public final class ImmutableNode implements Node {
|
|||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof Node)) return false;
|
if (!(o instanceof Node)) return false;
|
||||||
|
return Equality.EXACT.areEqual(this, ForwardingNode.unwrapForwarding((Node) o));
|
||||||
Node other = (Node) o;
|
|
||||||
while (other instanceof ForwardingNode) {
|
|
||||||
other = ((ForwardingNode) other).delegate();
|
|
||||||
}
|
|
||||||
return other instanceof ImmutableNode && Equality.EXACT.areEqual(this, (ImmutableNode) other);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean standardEquals(Node o, StandardNodeEquality equalityPredicate) {
|
public boolean equals(Node o, NodeEqualityPredicate equalityPredicate) {
|
||||||
while (o instanceof ForwardingNode) {
|
if (equalityPredicate instanceof StandardNodeEquality) {
|
||||||
o = ((ForwardingNode) o).delegate();
|
StandardNodeEquality stdEqualityPredicate = (StandardNodeEquality) equalityPredicate;
|
||||||
}
|
ImmutableNode other = ForwardingNode.unwrapForwarding(o);
|
||||||
if (!(o instanceof ImmutableNode)) {
|
switch (stdEqualityPredicate) {
|
||||||
return false;
|
case EXACT:
|
||||||
}
|
return Equality.EXACT.areEqual(this, other);
|
||||||
ImmutableNode other = (ImmutableNode) o;
|
case IGNORE_VALUE:
|
||||||
switch (equalityPredicate) {
|
return Equality.IGNORE_VALUE.areEqual(this, other);
|
||||||
case EXACT:
|
case IGNORE_EXPIRY_TIME:
|
||||||
return Equality.EXACT.areEqual(this, other);
|
return Equality.IGNORE_EXPIRY_TIME.areEqual(this, other);
|
||||||
case IGNORE_VALUE:
|
case IGNORE_EXPIRY_TIME_AND_VALUE:
|
||||||
return Equality.IGNORE_VALUE.areEqual(this, other);
|
return Equality.IGNORE_EXPIRY_TIME_AND_VALUE.areEqual(this, other);
|
||||||
case IGNORE_EXPIRY_TIME:
|
case IGNORE_VALUE_OR_IF_TEMPORARY:
|
||||||
return Equality.IGNORE_EXPIRY_TIME.areEqual(this, other);
|
return Equality.IGNORE_VALUE_OR_IF_TEMPORARY.areEqual(this, other);
|
||||||
case IGNORE_EXPIRY_TIME_AND_VALUE:
|
default:
|
||||||
return Equality.IGNORE_EXPIRY_TIME_AND_VALUE.areEqual(this, other);
|
throw new AssertionError();
|
||||||
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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user