diff --git a/build.gradle b/build.gradle index 6d9ca83..2b9365b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import groovy.io.FileType + apply plugin: 'java-library' apply plugin: 'maven' @@ -78,7 +80,7 @@ uploadArchives { doLast { // Purge all annoying files that arent needed - repoDir.traverse(type: groovy.io.FileType.FILES, nameFilter: ~/.*\.(xml|xml\.sha1|md5)$/) { + repoDir.traverse(type: FileType.FILES, nameFilter: ~/.*\.(xml|xml\.sha1|md5)$/) { it.delete() } } diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index ef7f546..f2671a1 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -1,9 +1,7 @@ package com.mojang.brigadier; -import com.google.common.base.Predicate; import com.google.common.collect.ComparisonChain; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContextBuilder; @@ -13,15 +11,15 @@ import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.RootCommandNode; -import java.util.Collections; -import java.util.Comparator; import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; public class CommandDispatcher { private static final Predicate HAS_COMMAND = new Predicate() { @Override - public boolean apply(CommandNode input) { - return input != null && (input.getCommand() != null || Iterables.any(input.getChildren(), HAS_COMMAND)); + public boolean test(CommandNode input) { + return input != null && (input.getCommand() != null || input.getChildren().stream().anyMatch(HAS_COMMAND)); } }; @@ -40,7 +38,7 @@ public class CommandDispatcher { } public void execute(String command, T source) throws CommandException { - CommandContext context = parseNodes(root, command, new CommandContextBuilder(source)); + CommandContext context = parseNodes(root, command, new CommandContextBuilder<>(source)); context.getCommand().run(context); } @@ -71,23 +69,18 @@ public class CommandDispatcher { } public String getUsage(String command, T source) throws CommandException { - CommandContext context = parseNodes(root, command, new CommandContextBuilder(source)); + CommandContext context = parseNodes(root, command, new CommandContextBuilder<>(source)); CommandNode base = Iterables.getLast(context.getNodes().keySet()); - List children = Lists.newArrayList(Iterables.filter(base.getChildren(), HAS_COMMAND)); + List children = base.getChildren().stream().filter(HAS_COMMAND).collect(Collectors.toList()); boolean optional = base.getCommand() != null; if (children.isEmpty()) { return context.getInput(); } - Collections.sort(children, new Comparator() { - @Override - public int compare(CommandNode o1, CommandNode o2) { - return ComparisonChain.start() - .compareTrueFirst(o1 instanceof LiteralCommandNode, o2 instanceof LiteralCommandNode) - .result(); - } - }); + children.sort((o1, o2) -> ComparisonChain.start() + .compareTrueFirst(o1 instanceof LiteralCommandNode, o2 instanceof LiteralCommandNode) + .result()); StringBuilder result = new StringBuilder(context.getInput()); result.append(ARGUMENT_SEPARATOR); diff --git a/src/main/java/com/mojang/brigadier/arguments/IntegerArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/IntegerArgumentType.java index 6594600..4748e08 100644 --- a/src/main/java/com/mojang/brigadier/arguments/IntegerArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/IntegerArgumentType.java @@ -52,7 +52,7 @@ public class IntegerArgumentType implements CommandArgumentType { throw ERROR_TOO_BIG.create(value, maximum); } - return new ParsedArgument(raw, value); + return new ParsedArgument<>(raw, value); } catch (NumberFormatException ignored) { throw ERROR_NOT_A_NUMBER.create(raw); } diff --git a/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java b/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java index 204a453..e1b8d1d 100644 --- a/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java +++ b/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java @@ -14,7 +14,7 @@ public class RequiredArgumentBuilder extends ArgumentBuilder RequiredArgumentBuilder argument(String name, CommandArgumentType type) { - return new RequiredArgumentBuilder(name, type); + return new RequiredArgumentBuilder<>(name, type); } @Override @@ -31,7 +31,7 @@ public class RequiredArgumentBuilder extends ArgumentBuilder build() { - ArgumentCommandNode result = new ArgumentCommandNode(getName(), getType(), getCommand()); + ArgumentCommandNode result = new ArgumentCommandNode<>(getName(), getType(), getCommand()); for (CommandNode argument : getArguments()) { result.addChild(argument); diff --git a/src/main/java/com/mojang/brigadier/context/CommandContextBuilder.java b/src/main/java/com/mojang/brigadier/context/CommandContextBuilder.java index 7fafada..97c8c7e 100644 --- a/src/main/java/com/mojang/brigadier/context/CommandContextBuilder.java +++ b/src/main/java/com/mojang/brigadier/context/CommandContextBuilder.java @@ -36,7 +36,7 @@ public class CommandContextBuilder { } public CommandContextBuilder copy() { - CommandContextBuilder copy = new CommandContextBuilder(source); + CommandContextBuilder copy = new CommandContextBuilder<>(source); copy.command = this.command; copy.arguments.putAll(this.arguments); copy.nodes.putAll(this.nodes); @@ -44,6 +44,6 @@ public class CommandContextBuilder { } public CommandContext build() { - return new CommandContext(source, arguments, command, nodes); + return new CommandContext<>(source, arguments, command, nodes); } } diff --git a/src/main/java/com/mojang/brigadier/exceptions/SimpleCommandExceptionType.java b/src/main/java/com/mojang/brigadier/exceptions/SimpleCommandExceptionType.java index d9c4ad2..d32d676 100644 --- a/src/main/java/com/mojang/brigadier/exceptions/SimpleCommandExceptionType.java +++ b/src/main/java/com/mojang/brigadier/exceptions/SimpleCommandExceptionType.java @@ -22,7 +22,7 @@ public class SimpleCommandExceptionType implements CommandExceptionType { } public CommandException create() { - return new CommandException(this, ImmutableMap.of()); + return new CommandException(this, ImmutableMap.of()); } @Override diff --git a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java index 008bc25..aea7769 100644 --- a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java @@ -68,7 +68,6 @@ public class ArgumentCommandNode extends CommandNode { public int hashCode() { int result = name.hashCode(); result = 31 * result + type.hashCode(); - result = 31 * super.hashCode(); return result; } } diff --git a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java index fe9ce3c..7c37f30 100644 --- a/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java +++ b/src/test/java/com/mojang/brigadier/CommandDispatcherTest.java @@ -20,7 +20,6 @@ import static com.mojang.brigadier.builder.RequiredArgumentBuilder.argument; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) @@ -31,7 +30,7 @@ public class CommandDispatcherTest { @Before public void setUp() throws Exception { - subject = new CommandDispatcher(); + subject = new CommandDispatcher<>(); } @Test @@ -90,7 +89,7 @@ public class CommandDispatcherTest { subject.execute("foo", source); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) CommandDispatcher.ERROR_UNKNOWN_COMMAND)); + assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_COMMAND)); assertThat(ex.getData(), is(Collections.emptyMap())); } } @@ -103,7 +102,7 @@ public class CommandDispatcherTest { subject.execute("foo bar", source); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) CommandDispatcher.ERROR_UNKNOWN_COMMAND)); + assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_COMMAND)); assertThat(ex.getData(), is(Collections.emptyMap())); } } @@ -134,8 +133,8 @@ public class CommandDispatcherTest { subject.execute("foo bar", source); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) IntegerArgumentType.ERROR_NOT_A_NUMBER)); - assertThat(ex.getData(), is((Map) ImmutableMap.of("found", "bar"))); + assertThat(ex.getType(), is(IntegerArgumentType.ERROR_NOT_A_NUMBER)); + assertThat(ex.getData(), is(ImmutableMap.of("found", "bar"))); } } } \ No newline at end of file diff --git a/src/test/java/com/mojang/brigadier/CommandDispatcherUsagesTest.java b/src/test/java/com/mojang/brigadier/CommandDispatcherUsagesTest.java index 7205581..c4484a2 100644 --- a/src/test/java/com/mojang/brigadier/CommandDispatcherUsagesTest.java +++ b/src/test/java/com/mojang/brigadier/CommandDispatcherUsagesTest.java @@ -26,7 +26,7 @@ public class CommandDispatcherUsagesTest { @Before public void setUp() throws Exception { - subject = new CommandDispatcher(); + subject = new CommandDispatcher<>(); } @Test @@ -35,7 +35,7 @@ public class CommandDispatcherUsagesTest { subject.getUsage("foo", source); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) CommandDispatcher.ERROR_UNKNOWN_COMMAND)); + assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_COMMAND)); assertThat(ex.getData(), is(Collections.emptyMap())); } } diff --git a/src/test/java/com/mojang/brigadier/arguments/IntegerArgumentTypeTest.java b/src/test/java/com/mojang/brigadier/arguments/IntegerArgumentTypeTest.java index dd43684..0ed6195 100644 --- a/src/test/java/com/mojang/brigadier/arguments/IntegerArgumentTypeTest.java +++ b/src/test/java/com/mojang/brigadier/arguments/IntegerArgumentTypeTest.java @@ -40,8 +40,8 @@ public class IntegerArgumentTypeTest { type.parse("fifty"); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) IntegerArgumentType.ERROR_NOT_A_NUMBER)); - assertThat(ex.getData(), is((Map) ImmutableMap.of("found", "fifty"))); + assertThat(ex.getType(), is(IntegerArgumentType.ERROR_NOT_A_NUMBER)); + assertThat(ex.getData(), is(ImmutableMap.of("found", "fifty"))); } } @@ -51,8 +51,8 @@ public class IntegerArgumentTypeTest { type.parse("-101"); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) IntegerArgumentType.ERROR_TOO_SMALL)); - assertThat(ex.getData(), is((Map) ImmutableMap.of("found", -101, "minimum", -100))); + assertThat(ex.getType(), is(IntegerArgumentType.ERROR_TOO_SMALL)); + assertThat(ex.getData(), is(ImmutableMap.of("found", -101, "minimum", -100))); } } @@ -70,8 +70,8 @@ public class IntegerArgumentTypeTest { type.parse("101"); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) IntegerArgumentType.ERROR_TOO_BIG)); - assertThat(ex.getData(), is((Map) ImmutableMap.of("found", 101, "maximum", 100))); + assertThat(ex.getType(), is(IntegerArgumentType.ERROR_TOO_BIG)); + assertThat(ex.getData(), is(ImmutableMap.of("found", 101, "maximum", 100))); } } @@ -85,7 +85,7 @@ public class IntegerArgumentTypeTest { @Test public void testGetInteger() throws Exception { - CommandContext context = new CommandContextBuilder(new Object()).withArgument("foo", type.parse("100")).build(); + CommandContext context = new CommandContextBuilder<>(new Object()).withArgument("foo", type.parse("100")).build(); assertThat(IntegerArgumentType.getInteger(context, "foo"), is(100)); } diff --git a/src/test/java/com/mojang/brigadier/context/CommandContextTest.java b/src/test/java/com/mojang/brigadier/context/CommandContextTest.java index 2858e59..ed1ca9d 100644 --- a/src/test/java/com/mojang/brigadier/context/CommandContextTest.java +++ b/src/test/java/com/mojang/brigadier/context/CommandContextTest.java @@ -23,7 +23,7 @@ public class CommandContextTest { @Before public void setUp() throws Exception { - builder = new CommandContextBuilder(source); + builder = new CommandContextBuilder<>(source); } @Test(expected = IllegalArgumentException.class) @@ -56,13 +56,13 @@ public class CommandContextTest { CommandNode node = mock(CommandNode.class); CommandNode otherNode = mock(CommandNode.class); new EqualsTester() - .addEqualityGroup(new CommandContextBuilder(source).build(), new CommandContextBuilder(source).build()) - .addEqualityGroup(new CommandContextBuilder(otherSource).build(), new CommandContextBuilder(otherSource).build()) - .addEqualityGroup(new CommandContextBuilder(source).withCommand(command).build(), new CommandContextBuilder(source).withCommand(command).build()) - .addEqualityGroup(new CommandContextBuilder(source).withCommand(otherCommand).build(), new CommandContextBuilder(source).withCommand(otherCommand).build()) - .addEqualityGroup(new CommandContextBuilder(source).withArgument("foo", integer().parse("123")).build(), new CommandContextBuilder(source).withArgument("foo", integer().parse("123")).build()) - .addEqualityGroup(new CommandContextBuilder(source).withNode(node, "foo").withNode(otherNode, "bar").build(), new CommandContextBuilder(source).withNode(node, "foo").withNode(otherNode, "bar").build()) - .addEqualityGroup(new CommandContextBuilder(source).withNode(otherNode, "bar").withNode(node, "foo").build(), new CommandContextBuilder(source).withNode(otherNode, "bar").withNode(node, "foo").build()) + .addEqualityGroup(new CommandContextBuilder<>(source).build(), new CommandContextBuilder<>(source).build()) + .addEqualityGroup(new CommandContextBuilder<>(otherSource).build(), new CommandContextBuilder<>(otherSource).build()) + .addEqualityGroup(new CommandContextBuilder<>(source).withCommand(command).build(), new CommandContextBuilder<>(source).withCommand(command).build()) + .addEqualityGroup(new CommandContextBuilder<>(source).withCommand(otherCommand).build(), new CommandContextBuilder<>(source).withCommand(otherCommand).build()) + .addEqualityGroup(new CommandContextBuilder<>(source).withArgument("foo", integer().parse("123")).build(), new CommandContextBuilder<>(source).withArgument("foo", integer().parse("123")).build()) + .addEqualityGroup(new CommandContextBuilder<>(source).withNode(node, "foo").withNode(otherNode, "bar").build(), new CommandContextBuilder<>(source).withNode(node, "foo").withNode(otherNode, "bar").build()) + .addEqualityGroup(new CommandContextBuilder<>(source).withNode(otherNode, "bar").withNode(node, "foo").build(), new CommandContextBuilder<>(source).withNode(otherNode, "bar").withNode(node, "foo").build()) .testEquals(); } diff --git a/src/test/java/com/mojang/brigadier/context/ParsedArgumentTest.java b/src/test/java/com/mojang/brigadier/context/ParsedArgumentTest.java index 0599b6f..e50bb08 100644 --- a/src/test/java/com/mojang/brigadier/context/ParsedArgumentTest.java +++ b/src/test/java/com/mojang/brigadier/context/ParsedArgumentTest.java @@ -7,9 +7,9 @@ public class ParsedArgumentTest { @Test public void testEquals() throws Exception { new EqualsTester() - .addEqualityGroup(new ParsedArgument("foo", "bar"), new ParsedArgument("foo", "bar")) - .addEqualityGroup(new ParsedArgument("bar", "baz"), new ParsedArgument("bar", "baz")) - .addEqualityGroup(new ParsedArgument("foo", "baz"), new ParsedArgument("foo", "baz")) + .addEqualityGroup(new ParsedArgument<>("foo", "bar"), new ParsedArgument<>("foo", "bar")) + .addEqualityGroup(new ParsedArgument<>("bar", "baz"), new ParsedArgument<>("bar", "baz")) + .addEqualityGroup(new ParsedArgument<>("foo", "baz"), new ParsedArgument<>("foo", "baz")) .testEquals(); } } \ No newline at end of file diff --git a/src/test/java/com/mojang/brigadier/exceptions/ParameterizedCommandExceptionTypeTest.java b/src/test/java/com/mojang/brigadier/exceptions/ParameterizedCommandExceptionTypeTest.java index 5b8e925..9dd48fa 100644 --- a/src/test/java/com/mojang/brigadier/exceptions/ParameterizedCommandExceptionTypeTest.java +++ b/src/test/java/com/mojang/brigadier/exceptions/ParameterizedCommandExceptionTypeTest.java @@ -32,8 +32,8 @@ public class ParameterizedCommandExceptionTypeTest { @Test public void testCreate() throws Exception { CommandException exception = type.create("World"); - assertThat(exception.getType(), is((CommandExceptionType) type)); - assertThat(exception.getData(), is((Map) ImmutableMap.of("name", "World"))); + assertThat(exception.getType(), is(type)); + assertThat(exception.getData(), is(ImmutableMap.of("name", "World"))); assertThat(exception.getMessage(), is("Hello, World!")); } diff --git a/src/test/java/com/mojang/brigadier/exceptions/SimpleCommandExceptionTypeTest.java b/src/test/java/com/mojang/brigadier/exceptions/SimpleCommandExceptionTypeTest.java index 66d6263..1939896 100644 --- a/src/test/java/com/mojang/brigadier/exceptions/SimpleCommandExceptionTypeTest.java +++ b/src/test/java/com/mojang/brigadier/exceptions/SimpleCommandExceptionTypeTest.java @@ -13,7 +13,7 @@ public class SimpleCommandExceptionTypeTest { public void testCreate() throws Exception { SimpleCommandExceptionType type = new SimpleCommandExceptionType("foo", "bar"); CommandException exception = type.create(); - assertThat(exception.getType(), is((CommandExceptionType) type)); + assertThat(exception.getType(), is(type)); assertThat(exception.getMessage(), is("bar")); assertThat(exception.getData().values(), empty()); } diff --git a/src/test/java/com/mojang/brigadier/tree/ArgumentCommandNodeTest.java b/src/test/java/com/mojang/brigadier/tree/ArgumentCommandNodeTest.java index 9f4b0ba..beac3c1 100644 --- a/src/test/java/com/mojang/brigadier/tree/ArgumentCommandNodeTest.java +++ b/src/test/java/com/mojang/brigadier/tree/ArgumentCommandNodeTest.java @@ -31,7 +31,7 @@ public class ArgumentCommandNodeTest extends AbstractCommandNodeTest { @Before public void setUp() throws Exception { node = argument("foo", integer()).build(); - contextBuilder = new CommandContextBuilder(new Object()); + contextBuilder = new CommandContextBuilder<>(new Object()); } @Test @@ -39,7 +39,7 @@ public class ArgumentCommandNodeTest extends AbstractCommandNodeTest { assertThat(node.parse("123 456", contextBuilder), is("456")); assertThat(contextBuilder.getArguments().containsKey("foo"), is(true)); - assertThat(contextBuilder.getArguments().get("foo").getResult(), is((Object) 123)); + assertThat(contextBuilder.getArguments().get("foo").getResult(), is(123)); } @Test @@ -47,7 +47,7 @@ public class ArgumentCommandNodeTest extends AbstractCommandNodeTest { assertThat(node.parse("123", contextBuilder), is("")); assertThat(contextBuilder.getArguments().containsKey("foo"), is(true)); - assertThat(contextBuilder.getArguments().get("foo").getResult(), is((Object) 123)); + assertThat(contextBuilder.getArguments().get("foo").getResult(), is(123)); } @Test @@ -56,8 +56,8 @@ public class ArgumentCommandNodeTest extends AbstractCommandNodeTest { node.parse("foo", contextBuilder); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) IntegerArgumentType.ERROR_NOT_A_NUMBER)); - assertThat(ex.getData(), is((Map) ImmutableMap.of("found", "foo"))); + assertThat(ex.getType(), is(IntegerArgumentType.ERROR_NOT_A_NUMBER)); + assertThat(ex.getData(), is(ImmutableMap.of("found", "foo"))); } } diff --git a/src/test/java/com/mojang/brigadier/tree/LiteralCommandNodeTest.java b/src/test/java/com/mojang/brigadier/tree/LiteralCommandNodeTest.java index 43dcbc2..5530d96 100644 --- a/src/test/java/com/mojang/brigadier/tree/LiteralCommandNodeTest.java +++ b/src/test/java/com/mojang/brigadier/tree/LiteralCommandNodeTest.java @@ -29,7 +29,7 @@ public class LiteralCommandNodeTest extends AbstractCommandNodeTest { @Before public void setUp() throws Exception { node = literal("foo").build(); - contextBuilder = new CommandContextBuilder(new Object()); + contextBuilder = new CommandContextBuilder<>(new Object()); } @Test @@ -48,8 +48,8 @@ public class LiteralCommandNodeTest extends AbstractCommandNodeTest { node.parse("foobar", contextBuilder); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) LiteralCommandNode.ERROR_INCORRECT_LITERAL)); - assertThat(ex.getData(), is((Map)ImmutableMap.of("expected", "foo"))); + assertThat(ex.getType(), is(LiteralCommandNode.ERROR_INCORRECT_LITERAL)); + assertThat(ex.getData(), is(ImmutableMap.of("expected", "foo"))); } } @@ -59,8 +59,8 @@ public class LiteralCommandNodeTest extends AbstractCommandNodeTest { node.parse("bar", contextBuilder); fail(); } catch (CommandException ex) { - assertThat(ex.getType(), is((CommandExceptionType) LiteralCommandNode.ERROR_INCORRECT_LITERAL)); - assertThat(ex.getData(), is((Map)ImmutableMap.of("expected", "foo"))); + assertThat(ex.getType(), is(LiteralCommandNode.ERROR_INCORRECT_LITERAL)); + assertThat(ex.getData(), is(ImmutableMap.of("expected", "foo"))); } } diff --git a/src/test/java/com/mojang/brigadier/tree/RootCommandNodeTest.java b/src/test/java/com/mojang/brigadier/tree/RootCommandNodeTest.java index 4b99de1..2e23986 100644 --- a/src/test/java/com/mojang/brigadier/tree/RootCommandNodeTest.java +++ b/src/test/java/com/mojang/brigadier/tree/RootCommandNodeTest.java @@ -24,7 +24,7 @@ public class RootCommandNodeTest extends AbstractCommandNodeTest { @Test public void testParse() throws Exception { - assertThat(node.parse("foo bar baz", new CommandContextBuilder(new Object())), is("foo bar baz")); + assertThat(node.parse("foo bar baz", new CommandContextBuilder<>(new Object())), is("foo bar baz")); } @Test(expected = UnsupportedOperationException.class)