diff --git a/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java b/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java index 4f0b7ab..bdfd40f 100644 --- a/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java @@ -38,4 +38,26 @@ public class ArgumentCommandNode extends CommandNode { return ""; } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ArgumentCommandNode)) return false; + + ArgumentCommandNode that = (ArgumentCommandNode) o; + + if (!name.equals(that.name)) return false; + if (!type.equals(that.type)) return false; + if (!getChildren().equals(that.getChildren())) return false; + + return true; + } + + @Override + public int hashCode() { + int result = name.hashCode(); + result = 31 * result + type.hashCode(); + result = 31 * result + getChildren().hashCode(); + return result; + } } diff --git a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java index ba98e32..6cc8bc0 100644 --- a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java @@ -29,4 +29,24 @@ public class LiteralCommandNode extends CommandNode { int start = expected.length(); return command.substring(start); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof LiteralCommandNode)) return false; + + LiteralCommandNode that = (LiteralCommandNode) o; + + if (!literal.equals(that.literal)) return false; + if (!getChildren().equals(that.getChildren())) return false; + + return true; + } + + @Override + public int hashCode() { + int result = literal.hashCode(); + result = 31 * result + getChildren().hashCode(); + return result; + } } diff --git a/src/main/java/net/minecraft/commands/tree/RootCommandNode.java b/src/main/java/net/minecraft/commands/tree/RootCommandNode.java index c70f084..4008553 100644 --- a/src/main/java/net/minecraft/commands/tree/RootCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/RootCommandNode.java @@ -13,4 +13,21 @@ public class RootCommandNode extends CommandNode { public String parse(String command, CommandContextBuilder contextBuilder) throws IllegalArgumentSyntaxException, ArgumentValidationException { return command; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof RootCommandNode)) return false; + + RootCommandNode that = (RootCommandNode) o; + + if (!getChildren().equals(that.getChildren())) return false; + + return true; + } + + @Override + public int hashCode() { + return getChildren().hashCode(); + } } diff --git a/src/test/java/net/minecraft/commands/tree/ArgumentCommandNodeTest.java b/src/test/java/net/minecraft/commands/tree/ArgumentCommandNodeTest.java index eba45d4..fee72ac 100644 --- a/src/test/java/net/minecraft/commands/tree/ArgumentCommandNodeTest.java +++ b/src/test/java/net/minecraft/commands/tree/ArgumentCommandNodeTest.java @@ -1,5 +1,6 @@ package net.minecraft.commands.tree; +import com.google.common.testing.EqualsTester; import net.minecraft.commands.context.CommandContextBuilder; import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; import org.junit.Before; @@ -40,4 +41,30 @@ public class ArgumentCommandNodeTest { public void testParseInvalid() throws Exception { node.parse("foo", contextBuilder); } + + @Test + public void testEquals() throws Exception { + new EqualsTester() + .addEqualityGroup( + argument("foo", integer()).build(), + argument("foo", integer()).build() + ) + .addEqualityGroup( + argument("bar", integer(-100, 100)).build(), + argument("bar", integer(-100, 100)).build() + ) + .addEqualityGroup( + argument("foo", integer(-100, 100)).build(), + argument("foo", integer(-100, 100)).build() + ) + .addEqualityGroup( + argument("foo", integer()).then( + argument("bar", integer()) + ).build(), + argument("foo", integer()).then( + argument("bar", integer()) + ).build() + ) + .testEquals(); + } } \ No newline at end of file diff --git a/src/test/java/net/minecraft/commands/tree/LiteralCommandNodeTest.java b/src/test/java/net/minecraft/commands/tree/LiteralCommandNodeTest.java index e676e25..dd7769e 100644 --- a/src/test/java/net/minecraft/commands/tree/LiteralCommandNodeTest.java +++ b/src/test/java/net/minecraft/commands/tree/LiteralCommandNodeTest.java @@ -1,5 +1,6 @@ package net.minecraft.commands.tree; +import com.google.common.testing.EqualsTester; import net.minecraft.commands.context.CommandContextBuilder; import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; import org.junit.Before; @@ -38,4 +39,26 @@ public class LiteralCommandNodeTest { public void testParseInvalid() throws Exception { node.parse("bar", contextBuilder); } + + @Test + public void testEquals() throws Exception { + new EqualsTester() + .addEqualityGroup( + literal("foo").build(), + literal("foo").build() + ) + .addEqualityGroup( + literal("bar").build(), + literal("bar").build() + ) + .addEqualityGroup( + literal("foo").then( + literal("bar") + ).build(), + literal("foo").then( + literal("bar") + ).build() + ) + .testEquals(); + } } \ No newline at end of file diff --git a/src/test/java/net/minecraft/commands/tree/RootCommandNodeTest.java b/src/test/java/net/minecraft/commands/tree/RootCommandNodeTest.java index 87d9610..3d506f7 100644 --- a/src/test/java/net/minecraft/commands/tree/RootCommandNodeTest.java +++ b/src/test/java/net/minecraft/commands/tree/RootCommandNodeTest.java @@ -1,9 +1,11 @@ package net.minecraft.commands.tree; +import com.google.common.testing.EqualsTester; import net.minecraft.commands.context.CommandContextBuilder; import org.junit.Before; import org.junit.Test; +import static net.minecraft.commands.builder.LiteralArgumentBuilder.literal; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -18,6 +20,23 @@ public class RootCommandNodeTest { @Test public void testParse() throws Exception { assertThat(node.parse("foo bar baz", new CommandContextBuilder()), is("foo bar baz")); + } + @Test + public void testEquals() throws Exception { + new EqualsTester() + .addEqualityGroup( + new RootCommandNode(), + new RootCommandNode() + ) + .addEqualityGroup( + new RootCommandNode() {{ + addChild(literal("foo").build()); + }}, + new RootCommandNode() {{ + addChild(literal("foo").build()); + }} + ) + .testEquals(); } } \ No newline at end of file