From d60e2015022ddbd4f64f82f8acc30d8765d14caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 13 Sep 2020 14:24:12 +0200 Subject: [PATCH] Fix checkstyle violations --- .../commands/annotations/specifier/Range.java | 3 +- .../annotations/specifier/package-info.java | 29 +++++++++++++++++++ .../components/parser/ParserParameter.java | 4 +-- .../components/parser/ParserParameters.java | 3 -- .../components/parser/ParserRegistry.java | 14 ++++----- .../parser/StandardParserRegistry.java | 12 +++++--- .../components/standard/IntegerComponent.java | 6 ++++ 7 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/package-info.java diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/Range.java b/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/Range.java index fcf72e21..6f1e6794 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/Range.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/Range.java @@ -30,7 +30,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Used to specify min and max values of numerical {@link com.intellectualsites.commands.components.parser.ComponentParser parsers} + * Used to specify min and max values of numerical + * {@link com.intellectualsites.commands.components.parser.ComponentParser parsers} */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/package-info.java new file mode 100644 index 00000000..9fef4f45 --- /dev/null +++ b/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/package-info.java @@ -0,0 +1,29 @@ +// +// 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. +// + +/** + * Standard annotations used to match {@link com.intellectualsites.commands.components.parser.ComponentParser} + * in {@link com.intellectualsites.commands.components.parser.ParserRegistry} + */ +package com.intellectualsites.commands.annotations.specifier; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameter.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameter.java index 1399cb4e..57f63d8e 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameter.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameter.java @@ -76,8 +76,8 @@ public class ParserParameter { return false; } final ParserParameter that = (ParserParameter) o; - return Objects.equals(key, that.key) && - Objects.equals(expectedType, that.expectedType); + return Objects.equals(key, that.key) + && Objects.equals(expectedType, that.expectedType); } @Override diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameters.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameters.java index 06b8d2fc..da496cef 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameters.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameters.java @@ -36,9 +36,6 @@ public final class ParserParameters { private final Map, Object> internalMap = Maps.newHashMap(); - public ParserParameters() { - } - /** * Get an empty {@link ParserParameters} instance * diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserRegistry.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserRegistry.java index 2e761cdf..bc40dd01 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserRegistry.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserRegistry.java @@ -50,8 +50,8 @@ public interface ParserRegistry { * to configure the parser, many of which are documented in {@link StandardParameters} * @param Generic type specifying what is produced by the parser */ - void registerParserSupplier(@Nonnull final TypeToken type, - @Nonnull final Function> supplier); + void registerParserSupplier(@Nonnull TypeToken type, + @Nonnull Function> supplier); /** * Register a mapper that maps annotation instances to a map of parameter-object pairs @@ -62,8 +62,8 @@ public interface ParserRegistry { * @param Annotation type * @param Type of the object that the parser is retrieved for */ - void registerAnnotationMapper(@Nonnull final Class annotation, - @Nonnull final BiFunction, + void registerAnnotationMapper(@Nonnull Class annotation, + @Nonnull BiFunction, ParserParameters> mapper); /** @@ -74,7 +74,7 @@ public interface ParserRegistry { * @return Parsed parameters */ @Nonnull - ParserParameters parseAnnotations(@Nonnull final TypeToken parsingType, @Nonnull final Collection annotations); + ParserParameters parseAnnotations(@Nonnull TypeToken parsingType, @Nonnull Collection annotations); /** * Attempt to create a {@link ComponentParser} for a specified type, using @@ -86,7 +86,7 @@ public interface ParserRegistry { * @return Parser, if one can be created */ @Nonnull - Optional> createParser(@Nonnull final TypeToken type, - @Nonnull final ParserParameters parserParameters); + Optional> createParser(@Nonnull TypeToken type, + @Nonnull ParserParameters parserParameters); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParserRegistry.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParserRegistry.java index 69f80008..cbb2997a 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParserRegistry.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParserRegistry.java @@ -43,9 +43,9 @@ import java.util.function.Function; * * @param Command sender type */ -public class StandardParserRegistry implements ParserRegistry { +public final class StandardParserRegistry implements ParserRegistry { - private static final Map, Class> primitiveMappings = ImmutableMap., Class>builder() + private static final Map, Class> PRIMITIVE_MAPPINGS = ImmutableMap., Class>builder() .put(char.class, Character.class) .put(int.class, Integer.class) .put(short.class, Short.class) @@ -60,6 +60,10 @@ public class StandardParserRegistry implements ParserRe private final Map, BiFunction, ParserParameters>> annotationMappers = new HashMap<>(); + /** + * Construct a new {@link StandardParserRegistry} instance. This will also + * register all standard annotation mappers and parser suppliers + */ public StandardParserRegistry() { /* Register standard mappers */ this.registerAnnotationMapper(Range.class, new RangeMapper<>()); @@ -107,7 +111,7 @@ public class StandardParserRegistry implements ParserRe @Nonnull final ParserParameters parserParameters) { final TypeToken actualType; if (type.isPrimitive()) { - actualType = TypeToken.of(primitiveMappings.get(type.getRawType())); + actualType = TypeToken.of(PRIMITIVE_MAPPINGS.get(type.getRawType())); } else { actualType = type; } @@ -127,7 +131,7 @@ public class StandardParserRegistry implements ParserRe public ParserParameters apply(final Range range, final TypeToken type) { final Class clazz; if (type.isPrimitive()) { - clazz = primitiveMappings.get(type.getRawType()); + clazz = PRIMITIVE_MAPPINGS.get(type.getRawType()); } else { clazz = type.getRawType(); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/IntegerComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/IntegerComponent.java index 09171d69..cc637289 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/IntegerComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/IntegerComponent.java @@ -171,6 +171,12 @@ public final class IntegerComponent extends CommandComp private final int min; private final int max; + /** + * Construct a new integer parser + * + * @param min Minimum acceptable value + * @param max Maximum acceptable value + */ public IntegerParser(final int min, final int max) { this.min = min; this.max = max;