From 1694df732dee7bf049a4d37fad0c4546a08e2d17 Mon Sep 17 00:00:00 2001 From: Jason <11360596+jpenilla@users.noreply.github.com> Date: Wed, 23 Nov 2022 15:45:50 -0700 Subject: [PATCH] Improve nullability annotations on generics in CommandContext (#405) --- .../context/CommandContext.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java b/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java index 593b3fac..2d84e291 100644 --- a/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java +++ b/cloud-core/src/main/java/cloud/commandframework/context/CommandContext.java @@ -200,7 +200,7 @@ public class CommandContext { * @param value Value * @param Value type */ - public void store(final @NonNull String key, final @NonNull T value) { + public void store(final @NonNull String key, final T value) { this.internalStorage.put(SimpleCloudKey.of(key), value); } @@ -212,7 +212,7 @@ public class CommandContext { * @param value Value * @param Value type */ - public void store(final @NonNull CloudKey key, final @NonNull T value) { + public void store(final @NonNull CloudKey key, final T value) { this.internalStorage.put(key, value); } @@ -224,7 +224,7 @@ public class CommandContext { * @param value Value * @param Value type */ - public void store(final @NonNull CommandArgument keyHolder, final @NonNull T value) { + public void store(final @NonNull CommandArgument keyHolder, final T value) { this.store((CloudKeyHolder) keyHolder, value); } @@ -238,7 +238,7 @@ public class CommandContext { * @since 1.4.0 */ @API(status = API.Status.STABLE, since = "1.4.0") - public void store(final @NonNull CloudKeyHolder keyHolder, final @NonNull T value) { + public void store(final @NonNull CloudKeyHolder keyHolder, final T value) { this.internalStorage.put(keyHolder.getKey(), value); } @@ -327,7 +327,7 @@ public class CommandContext { * @param Value type * @return Value */ - public @NonNull Optional getOptional(final @NonNull String key) { + public @NonNull Optional getOptional(final @NonNull String key) { final Object value = this.internalStorage.get(SimpleCloudKey.of(key)); if (value != null) { @SuppressWarnings("unchecked") final T castedValue = (T) value; @@ -347,7 +347,7 @@ public class CommandContext { * @since 1.4.0 */ @API(status = API.Status.STABLE, since = "1.4.0") - public @NonNull Optional getOptional(final @NonNull CloudKey key) { + public @NonNull Optional getOptional(final @NonNull CloudKey key) { final Object value = this.internalStorage.get(key); if (value != null) { @SuppressWarnings("unchecked") final T castedValue = (T) value; @@ -366,7 +366,7 @@ public class CommandContext { * @return Value */ @SuppressWarnings("unused") - public @NonNull Optional getOptional(final @NonNull CommandArgument keyHolder) { + public @NonNull Optional getOptional(final @NonNull CommandArgument keyHolder) { return this.getOptional((CloudKeyHolder) keyHolder); } @@ -381,7 +381,7 @@ public class CommandContext { */ @SuppressWarnings("unused") @API(status = API.Status.STABLE, since = "1.4.0") - public @NonNull Optional getOptional(final @NonNull CloudKeyHolder keyHolder) { + public @NonNull Optional getOptional(final @NonNull CloudKeyHolder keyHolder) { final Object value = this.internalStorage.get(keyHolder.getKey()); if (value != null) { @SuppressWarnings("unchecked") final T castedValue = (T) value; @@ -412,7 +412,7 @@ public class CommandContext { } /** - * Get a required argument from the context. This will thrown an exception + * Get a required argument from the context. This will throw an exception * if there's no value associated with the given key * * @param key Argument key @@ -421,7 +421,7 @@ public class CommandContext { * @throws NullPointerException If no such argument is stored */ @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"}) - public @NonNull T get(final @NonNull String key) { + public T get(final @NonNull String key) { final Object value = this.internalStorage.get(SimpleCloudKey.of(key)); if (value == null) { throw new NullPointerException("No such object stored in the context: " + key); @@ -430,7 +430,7 @@ public class CommandContext { } /** - * Get a required argument from the context. This will thrown an exception + * Get a required argument from the context. This will throw an exception * if there's no value associated with the given key * * @param key Argument key @@ -441,7 +441,7 @@ public class CommandContext { */ @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"}) @API(status = API.Status.STABLE, since = "1.4.0") - public @NonNull T get(final @NonNull CloudKey key) { + public T get(final @NonNull CloudKey key) { final Object value = this.internalStorage.get(key); if (value == null) { throw new NullPointerException("No such object stored in the context: " + key); @@ -450,7 +450,7 @@ public class CommandContext { } /** - * Get a required argument from the context. This will thrown an exception + * Get a required argument from the context. This will throw an exception * if there's no value associated with the given argument * * @param keyHolder Holder of the identifying key @@ -458,12 +458,12 @@ public class CommandContext { * @return Stored value * @throws NullPointerException If no such value is stored */ - public @NonNull T get(final @NonNull CommandArgument keyHolder) { + public T get(final @NonNull CommandArgument keyHolder) { return this.get(keyHolder.getKey()); } /** - * Get a required argument from the context. This will thrown an exception + * Get a required argument from the context. This will throw an exception * if there's no value associated with the given argument * * @param keyHolder Holder of the identifying key @@ -473,7 +473,7 @@ public class CommandContext { * @since 1.4.0 */ @API(status = API.Status.STABLE, since = "1.4.0") - public @NonNull T get(final @NonNull CloudKeyHolder keyHolder) { + public T get(final @NonNull CloudKeyHolder keyHolder) { return this.get(keyHolder.getKey()); } @@ -485,9 +485,9 @@ public class CommandContext { * @param Argument type * @return Stored value, or supplied default value */ - public @Nullable T getOrDefault( - final @NonNull CommandArgument argument, - final @Nullable T defaultValue + public T getOrDefault( + final @NonNull CommandArgument argument, + final T defaultValue ) { return this.getOptional(argument.getName()).orElse(defaultValue); } @@ -500,11 +500,11 @@ public class CommandContext { * @param Argument type * @return Argument, or supplied default value */ - public @Nullable T getOrDefault( + public T getOrDefault( final @NonNull String key, - final @Nullable T defaultValue + final T defaultValue ) { - return this.getOptional(key).orElse(defaultValue); + return this.<@NonNull T>getOptional(key).orElse(defaultValue); } /** @@ -517,9 +517,9 @@ public class CommandContext { * @since 1.4.0 */ @API(status = API.Status.STABLE, since = "1.4.0") - public @Nullable T getOrDefault( - final @NonNull CloudKey key, - final @Nullable T defaultValue + public T getOrDefault( + final @NonNull CloudKey<@NonNull T> key, + final T defaultValue ) { return this.getOptional(key).orElse(defaultValue); } @@ -534,11 +534,11 @@ public class CommandContext { * @since 1.2.0 */ @API(status = API.Status.STABLE, since = "1.2.0") - public @Nullable T getOrSupplyDefault( + public T getOrSupplyDefault( final @NonNull String key, - final @NonNull Supplier<@Nullable T> defaultSupplier + final @NonNull Supplier defaultSupplier ) { - return this.getOptional(key).orElseGet(defaultSupplier); + return this.<@NonNull T>getOptional(key).orElseGet(defaultSupplier); } /** @@ -551,9 +551,9 @@ public class CommandContext { * @since 1.4.0 */ @API(status = API.Status.STABLE, since = "1.4.0") - public @Nullable T getOrSupplyDefault( - final @NonNull CloudKey key, - final @NonNull Supplier<@Nullable T> defaultSupplier + public T getOrSupplyDefault( + final @NonNull CloudKey<@NonNull T> key, + final @NonNull Supplier defaultSupplier ) { return this.getOptional(key).orElseGet(defaultSupplier); }