From f3fe8f2ad85c2fa1408e39838a000dad8d42577b Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 1 Jul 2014 12:47:56 -0700 Subject: [PATCH] Extracted CommandMapping interface. --- .../util/command/CommandMapping.java | 57 ++++----------- .../util/command/SimpleCommandMapping.java | 72 +++++++++++++++++++ .../util/command/SimpleDispatcher.java | 2 +- 3 files changed, 85 insertions(+), 46 deletions(-) create mode 100644 src/main/java/com/sk89q/worldedit/util/command/SimpleCommandMapping.java diff --git a/src/main/java/com/sk89q/worldedit/util/command/CommandMapping.java b/src/main/java/com/sk89q/worldedit/util/command/CommandMapping.java index 6e44bff17..093850728 100644 --- a/src/main/java/com/sk89q/worldedit/util/command/CommandMapping.java +++ b/src/main/java/com/sk89q/worldedit/util/command/CommandMapping.java @@ -19,70 +19,37 @@ package com.sk89q.worldedit.util.command; -import java.util.Arrays; - /** - * Tracks a command registration. + * Provides information about a mapping between a command and its aliases. */ -public class CommandMapping { - - private final String[] aliases; - private final CommandCallable callable; - - /** - * Create a new instance. - * - * @param callable the command callable - * @param alias a list of all aliases, where the first one is the primary one - */ - public CommandMapping(CommandCallable callable, String... alias) { - super(); - this.aliases = alias; - this.callable = callable; - } +public interface CommandMapping { /** * Get the primary alias. - * + * * @return the primary alias */ - public String getPrimaryAlias() { - return aliases[0]; - } - + String getPrimaryAlias(); + /** * Get a list of all aliases. - * + * * @return aliases */ - public String[] getAllAliases() { - return aliases; - } - + String[] getAllAliases(); + /** * Get the callable - * + * * @return the callable */ - public CommandCallable getCallable() { - return callable; - } + CommandCallable getCallable(); /** * Get the {@link Description} form the callable. - * + * * @return the description */ - public Description getDescription() { - return getCallable().getDescription(); - } - - @Override - public String toString() { - return "CommandMapping{" + - "aliases=" + Arrays.toString(aliases) + - ", callable=" + callable + - '}'; - } + Description getDescription(); } diff --git a/src/main/java/com/sk89q/worldedit/util/command/SimpleCommandMapping.java b/src/main/java/com/sk89q/worldedit/util/command/SimpleCommandMapping.java new file mode 100644 index 000000000..982832c48 --- /dev/null +++ b/src/main/java/com/sk89q/worldedit/util/command/SimpleCommandMapping.java @@ -0,0 +1,72 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.command; + +import java.util.Arrays; + +/** + * Tracks a command registration. + */ +public class SimpleCommandMapping implements CommandMapping { + + private final String[] aliases; + private final CommandCallable callable; + + /** + * Create a new instance. + * + * @param callable the command callable + * @param alias a list of all aliases, where the first one is the primary one + */ + public SimpleCommandMapping(CommandCallable callable, String... alias) { + super(); + this.aliases = alias; + this.callable = callable; + } + + @Override + public String getPrimaryAlias() { + return aliases[0]; + } + + @Override + public String[] getAllAliases() { + return aliases; + } + + @Override + public CommandCallable getCallable() { + return callable; + } + + @Override + public Description getDescription() { + return getCallable().getDescription(); + } + + @Override + public String toString() { + return "CommandMapping{" + + "aliases=" + Arrays.toString(aliases) + + ", callable=" + callable + + '}'; + } + +} diff --git a/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java b/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java index 8bb7d52c5..86dbcc70a 100644 --- a/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java +++ b/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java @@ -55,7 +55,7 @@ public class SimpleDispatcher implements Dispatcher { @Override public void registerCommand(CommandCallable callable, String... alias) { - CommandMapping mapping = new CommandMapping(callable, alias); + CommandMapping mapping = new SimpleCommandMapping(callable, alias); // Check for replacements for (String a : alias) {