diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/BooleanComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/BooleanComponent.java index c4187d0c..ddb5a0fc 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/BooleanComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/BooleanComponent.java @@ -1,3 +1,26 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// package com.intellectualsites.commands.components.standard; import com.intellectualsites.commands.components.CommandComponent; @@ -12,30 +35,59 @@ import java.util.List; import java.util.Queue; @SuppressWarnings("unused") -public class BooleanComponent extends CommandComponent { +public final class BooleanComponent extends CommandComponent { private final boolean liberal; - public BooleanComponent(final boolean required, @Nonnull final String name, - final boolean liberal, @Nonnull final String defaultValue) { + private BooleanComponent(final boolean required, @Nonnull final String name, + final boolean liberal, @Nonnull final String defaultValue) { super(required, name, new BooleanParser<>(liberal), defaultValue); this.liberal = liberal; } + /** + * Create a new builder + * + * @param name Name of the component + * @param Command sender type + * @return Created builder + */ @Nonnull public static Builder newBuilder(@Nonnull final String name) { return new Builder<>(name); } + /** + * Create a new required command component + * + * @param name Component name + * @param Command sender type + * @return Created component + */ @Nonnull public static CommandComponent required(@Nonnull final String name) { return BooleanComponent.newBuilder(name).asRequired().build(); } + /** + * Create a new optional command component + * + * @param name Component name + * @param Command sender type + * @return Created component + */ @Nonnull public static CommandComponent optional(@Nonnull final String name) { return BooleanComponent.newBuilder(name).asOptional().build(); } + /** + * Create a new required command component with a default value + * + * @param name Component name + * @param defaultNum Default num + * @param Command sender type + * @return Created component + */ @Nonnull public static CommandComponent optional(@Nonnull final String name, final String defaultNum) { @@ -50,38 +102,49 @@ public class BooleanComponent extends CommandComponent< super(name); } + /** + * Set the liberal toggle + * + * @param liberal liberal value + * @return Builder instance + */ @Nonnull public Builder withLiberal(final boolean liberal) { this.liberal = liberal; return this; } + /** + * Builder a new boolean component + * + * @return Constructed component + */ @Nonnull @Override public BooleanComponent build() { - return new BooleanComponent<>(this.required, this.name, this.liberal, this.defaultValue); + return new BooleanComponent<>(this.isRequired(), this.getName(), this.liberal, this.getDefaultValue()); } } /** - * Get the greedy boolean + * Get the liberal boolean * - * @return Greedy boolean + * @return Liberal boolean */ public boolean isLiberal() { return liberal; } private static final class BooleanParser implements ComponentParser { - // todo + private static final List LIBERAL = Arrays.asList("TRUE", "YES", "ON", "FALSE", "NO", "OFF"); private static final List LIBERAL_TRUE = Arrays.asList("TRUE", "YES", "ON"); private static final List LIBERAL_FALSE = Arrays.asList("FALSE", "NO", "OFF"); private final boolean liberal; - public BooleanParser(final boolean liberal) { + private BooleanParser(final boolean liberal) { this.liberal = liberal; } @@ -136,11 +199,22 @@ public class BooleanComponent extends CommandComponent< private final boolean liberal; + /** + * Construct a new boolean parse exception + * + * @param input String input + * @param liberal Liberal value + */ public BooleanParseException(@Nonnull final String input, final boolean liberal) { super(input); this.liberal = liberal; } + /** + * Get the liberal boolean value + * + * @return Liberal value + */ public boolean isLiberal() { return liberal; } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/StringComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/StringComponent.java index 938134dc..56320a47 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/StringComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/StringComponent.java @@ -11,30 +11,59 @@ import java.util.StringJoiner; import javax.annotation.Nonnull; @SuppressWarnings("unused") -public class StringComponent extends CommandComponent { +public final class StringComponent extends CommandComponent { private final boolean greedy; - public StringComponent(final boolean required, @Nonnull final String name, - final boolean greedy, @Nonnull final String defaultValue) { + private StringComponent(final boolean required, @Nonnull final String name, + final boolean greedy, @Nonnull final String defaultValue) { super(required, name, new StringParser<>(greedy), defaultValue); this.greedy = greedy; } + /** + * Create a new builder + * + * @param name Name of the component + * @param Command sender type + * @return Created builder + */ @Nonnull public static StringComponent.Builder newBuilder(@Nonnull final String name) { return new StringComponent.Builder<>(name); } + /** + * Create a new required command component + * + * @param name Component name + * @param Command sender type + * @return Created component + */ @Nonnull public static CommandComponent required(@Nonnull final String name) { return StringComponent.newBuilder(name).asRequired().build(); } + /** + * Create a new optional command component + * + * @param name Component name + * @param Command sender type + * @return Created component + */ @Nonnull public static CommandComponent optional(@Nonnull final String name) { return StringComponent.newBuilder(name).asOptional().build(); } + /** + * Create a new required command component with a default value + * + * @param name Component name + * @param defaultNum Default num + * @param Command sender type + * @return Created component + */ @Nonnull public static CommandComponent optional(@Nonnull final String name, final String defaultNum) { @@ -49,16 +78,27 @@ public class StringComponent extends CommandComponent withGreedy(final boolean greedy) { this.greedy = greedy; return this; } + /** + * Builder a new string component + * + * @return Constructed component + */ @Nonnull @Override public StringComponent build() { - return new StringComponent<>(this.required, this.name, this.greedy, this.defaultValue); + return new StringComponent<>(this.isRequired(), this.getName(), this.greedy, this.getDefaultValue()); } } @@ -76,7 +116,7 @@ public class StringComponent extends CommandComponent