Remove unnecessary constructor in CommandDescription

- Remove one of two unnecessary constructors in CommandDescription (in favor of the builder)
- Remove TODO about unlimited arguments (not currently a priority, will create a story instead of leaving a dangling TODO for ages in the code)
This commit is contained in:
ljacqu 2015-12-05 00:10:45 +01:00
parent 8eb1b38d21
commit 44aa91dfff
2 changed files with 32 additions and 35 deletions

View File

@ -5,8 +5,6 @@ package fr.xephi.authme.command;
*/ */
public class CommandArgumentDescription { public class CommandArgumentDescription {
// TODO: Allow argument to consist of infinite parts. <label ...>
/** /**
* Argument label (one-word description of the argument). * Argument label (one-word description of the argument).
*/ */

View File

@ -26,7 +26,7 @@ public class CommandDescription {
* Defines the labels to execute the command. For example, if labels are "register" and "r" and the parent is * Defines the labels to execute the command. For example, if labels are "register" and "r" and the parent is
* the command for "/authme", then both "/authme register" and "/authme r" will be handled by this command. * the command for "/authme", then both "/authme register" and "/authme r" will be handled by this command.
*/ */
private List<String> labels = new ArrayList<>(); // TODO remove field initialization private List<String> labels;
/** /**
* Command description. * Command description.
*/ */
@ -50,7 +50,7 @@ public class CommandDescription {
/** /**
* The arguments the command takes. * The arguments the command takes.
*/ */
private List<CommandArgumentDescription> arguments = new ArrayList<>(); // TODO remove field initialization private List<CommandArgumentDescription> arguments;
/** /**
* Defines the command permissions. * Defines the command permissions.
*/ */
@ -67,55 +67,54 @@ public class CommandDescription {
*/ */
@Deprecated @Deprecated
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent) { public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent) {
this(executableCommand, labels, description, detailedDescription, parent,
new ArrayList<CommandArgumentDescription>());
}
/**
* Constructor.
*
* @param executableCommand The executable command, or null.
* @param labels List of command labels.
* @param description Command description.
* @param detailedDescription Detailed comment description.
* @param parent Parent command.
* @param arguments Command arguments.
*/
@Deprecated
public CommandDescription(ExecutableCommand executableCommand, List<String> labels, String description, String detailedDescription, CommandDescription parent, List<CommandArgumentDescription> arguments) {
setExecutableCommand(executableCommand); setExecutableCommand(executableCommand);
this.labels = labels; this.labels = labels;
this.description = description; this.description = description;
this.detailedDescription = detailedDescription; this.detailedDescription = detailedDescription;
setParent(parent); setParent(parent);
this.arguments = arguments; this.arguments = new ArrayList<>();
} }
/** /**
* Private constructor. Use {@link CommandDescription#builder()} to create instances of this class. * Private constructor. Use {@link CommandDescription#builder()} to create instances of this class.
* <p />
* Note for developers: Instances should be created with {@link CommandDescription#createInstance} to be properly
* registered in the command tree.
*/
private CommandDescription() {
}
/**
* Create an instance for internal use.
* *
* @param executableCommand The executable command, or null.
* @param labels List of command labels. * @param labels List of command labels.
* @param description Command description. * @param description Command description.
* @param detailedDescription Detailed comment description. * @param detailedDescription Detailed comment description.
* @param executableCommand The executable command, or null.
* @param parent Parent command. * @param parent Parent command.
* @param arguments Command arguments. * @param arguments Command arguments.
* @param permissions The permissions required to execute this command.
*
* @return The created instance
* @see CommandDescription#builder()
*/ */
private CommandDescription(List<String> labels, String description, String detailedDescription, private static CommandDescription createInstance(List<String> labels, String description,
ExecutableCommand executableCommand, CommandDescription parent, String detailedDescription, ExecutableCommand executableCommand,
List<CommandArgumentDescription> arguments, CommandPermissions permissions) { CommandDescription parent, List<CommandArgumentDescription> arguments,
this.labels = labels; CommandPermissions permissions) {
this.description = description; CommandDescription instance = new CommandDescription();
this.detailedDescription = detailedDescription; instance.labels = labels;
this.executableCommand = executableCommand; instance.description = description;
this.parent = parent; instance.detailedDescription = detailedDescription;
this.arguments = arguments; instance.executableCommand = executableCommand;
this.permissions = permissions; instance.parent = parent;
instance.arguments = arguments;
instance.permissions = permissions;
if (parent != null) { if (parent != null) {
// Passing `this` in constructor is not very nice; consider creating a "static create()" method instead parent.addChild(instance);
parent.addChild(this);
} }
return instance;
} }
/** /**
@ -589,7 +588,7 @@ public class CommandDescription {
* @return The generated CommandDescription object * @return The generated CommandDescription object
*/ */
public CommandDescription build() { public CommandDescription build() {
return new CommandDescription( return createInstance(
getOrThrow(labels, "labels"), getOrThrow(labels, "labels"),
firstNonNull(description, ""), firstNonNull(description, ""),
firstNonNull(detailedDescription, ""), firstNonNull(detailedDescription, ""),