Add equality checking to each command node
This commit is contained in:
@@ -38,4 +38,26 @@ public class ArgumentCommandNode<T> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user