From e9178b083431d23f85e4b4794c9aa6135312fbec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 18 Dec 2020 08:56:52 +0100 Subject: [PATCH] :sparkles: Add some QoL methods to FlagContext --- .../arguments/flags/FlagContext.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cloud-core/src/main/java/cloud/commandframework/arguments/flags/FlagContext.java b/cloud-core/src/main/java/cloud/commandframework/arguments/flags/FlagContext.java index 560359f8..5b921f8e 100644 --- a/cloud-core/src/main/java/cloud/commandframework/arguments/flags/FlagContext.java +++ b/cloud-core/src/main/java/cloud/commandframework/arguments/flags/FlagContext.java @@ -140,4 +140,31 @@ public final class FlagContext { return this.getValue(name).isPresent(); } + /** + * Check whether a flag is present. This will return {@code true} if the flag + * is a presence flag and is present, or if the flag is a value flag and has + * a value provided. + * + * @param name Flag name + * @return {@code true} if the flag is present, else {@code false} + * @since 1.3.0 + */ + public boolean contains(final @NonNull String name) { + return this.hasFlag(name); + } + + /** + * Get a flag value + * + * @param name Flag name + * @param Value type + * @return Stored value, or the supplied default value + * @since 1.3.0 + */ + public @Nullable T get( + final @NonNull String name + ) { + return this.getValue(name).orElse(null); + } + }