From 58bd7de66a4f832eb94d95340704b3e6d92818bf Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 2 May 2018 20:35:20 +0100 Subject: [PATCH] Implement equals, hashcode and toString for NodeTypes --- .../common/node/model/NodeTypes.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/common/src/main/java/me/lucko/luckperms/common/node/model/NodeTypes.java b/common/src/main/java/me/lucko/luckperms/common/node/model/NodeTypes.java index e1a9be50b..4ca128fcf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/model/NodeTypes.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/model/NodeTypes.java @@ -41,6 +41,7 @@ import me.lucko.luckperms.common.utils.PatternCache; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import javax.annotation.Nonnull; @@ -193,6 +194,24 @@ public final class NodeTypes { public String getGroupName() { return this.groupName; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Inheritance that = (Inheritance) o; + return Objects.equals(this.groupName, that.groupName); + } + + @Override + public int hashCode() { + return Objects.hash(this.groupName); + } + + @Override + public String toString() { + return "InheritanceType{groupName='" + this.groupName + "'}"; + } } private static final class Meta implements MetaType { @@ -215,6 +234,25 @@ public final class NodeTypes { public String getValue() { return this.value; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Meta that = (Meta) o; + return Objects.equals(this.key, that.key) && + Objects.equals(this.value, that.value); + } + + @Override + public int hashCode() { + return Objects.hash(this.key, this.value); + } + + @Override + public String toString() { + return "MetaType{key='" + this.key + "', value='" + this.value + "'}"; + } } private static final class Prefix implements PrefixType, Map.Entry { @@ -257,6 +295,25 @@ public final class NodeTypes { public String setValue(String value) { throw new UnsupportedOperationException(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Prefix that = (Prefix) o; + return this.priority == that.priority && + Objects.equals(this.prefix, that.prefix); + } + + @Override + public int hashCode() { + return Objects.hash(this.priority, this.prefix); + } + + @Override + public String toString() { + return "PrefixType{priority=" + this.priority + ", prefix='" + this.prefix + "'}"; + } } private static final class Suffix implements SuffixType, Map.Entry { @@ -299,6 +356,25 @@ public final class NodeTypes { public String setValue(String value) { throw new UnsupportedOperationException(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Suffix that = (Suffix) o; + return this.priority == that.priority && + Objects.equals(this.suffix, that.suffix); + } + + @Override + public int hashCode() { + return Objects.hash(this.priority, this.suffix); + } + + @Override + public String toString() { + return "SuffixType{priority=" + this.priority + ", suffix='" + this.suffix + "'}"; + } } private static final class Weight implements WeightType { @@ -312,6 +388,24 @@ public final class NodeTypes { public int getWeight() { return this.weight; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Weight that = (Weight) o; + return this.weight == that.weight; + } + + @Override + public int hashCode() { + return Objects.hash(this.weight); + } + + @Override + public String toString() { + return "WeightType{weight=" + this.weight + '}'; + } } private NodeTypes() {}