From b19ec931cbf5df4c1fcf5b27e443b54266dd4398 Mon Sep 17 00:00:00 2001 From: Jason <11360596+jpenilla@users.noreply.github.com> Date: Fri, 25 Nov 2022 17:40:42 -0700 Subject: [PATCH] Add Command.Builder#apply (#409) --- .../java/cloud/commandframework/Command.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cloud-core/src/main/java/cloud/commandframework/Command.java b/cloud-core/src/main/java/cloud/commandframework/Command.java index fe880a39..6b99550a 100644 --- a/cloud-core/src/main/java/cloud/commandframework/Command.java +++ b/cloud-core/src/main/java/cloud/commandframework/Command.java @@ -466,6 +466,20 @@ public class Command { return this.commandPermission; } + /** + * Applies the provided {@link Applicable} to this {@link Builder}, and returns the result. + * + * @param applicable operation + * @return operation result + * @since 1.8.0 + */ + @API(status = API.Status.STABLE, since = "1.8.0") + public @NonNull Builder<@NonNull C> apply( + final @NonNull Applicable<@NonNull C> applicable + ) { + return applicable.applyToCommandBuilder(this); + } + /** * Add command meta to the internal command meta map * @@ -1199,5 +1213,27 @@ public class Command { this.commandMeta ); } + + /** + * Essentially a {@link java.util.function.UnaryOperator} for {@link Builder}, + * but as a separate interface to avoid conflicts. + * + * @param sender type + * @since 1.8.0 + */ + @API(status = API.Status.STABLE, since = "1.8.0") + @FunctionalInterface + public interface Applicable { + + /** + * Accepts a {@link Builder} and returns either the same or a modified {@link Builder} instance. + * + * @param builder builder + * @return possibly modified builder + * @since 1.8.0 + */ + @API(status = API.Status.STABLE, since = "1.8.0") + @NonNull Builder applyToCommandBuilder(@NonNull Builder builder); + } } }