Class FlagContext
- java.lang.Object
-
- cloud.commandframework.arguments.flags.FlagContext
-
public final class FlagContext extends java.lang.Object
Flag value mappings
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Object
FLAG_PRESENCE_VALUE
Dummy object stored as a flag value when the flag has no associated parser
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPresenceFlag(@NonNull CommandFlag<?> flag)
Indicate that a presence flag was supplied<T> void
addValueFlag(@NonNull CommandFlag<T> flag, @NonNull T value)
Store a value associated with a value flagboolean
contains(@NonNull CommandFlag<?> flag)
Check whether a flag is present.boolean
contains(@NonNull java.lang.String name)
Check whether a flag is present.static @NonNull FlagContext
create()
Create a new flag context instance<T> @Nullable T
get(@NonNull CommandFlag<T> flag)
Get a flag value<T> @Nullable T
get(@NonNull java.lang.String name)
Get a flag value<T> @NonNull java.util.Optional<T>
getValue(@NonNull CommandFlag<T> flag)
Get a flag value as an optional.<T> @Nullable T
getValue(@NonNull CommandFlag<T> name, @Nullable T defaultValue)
Get a flag value<T> @NonNull java.util.Optional<T>
getValue(@NonNull java.lang.String name)
Get a flag value as an optional.<T> @Nullable T
getValue(@NonNull java.lang.String name, @Nullable T defaultValue)
Get a flag valueboolean
hasFlag(@NonNull CommandFlag<?> flag)
Check whether a flag is present.boolean
hasFlag(@NonNull java.lang.String name)
Check whether a flag is present.boolean
isPresent(@NonNull CommandFlag<java.lang.Void> flag)
Check whether a presence flag is present.boolean
isPresent(@NonNull java.lang.String flag)
Check whether a presence flag is present.
-
-
-
Method Detail
-
create
public static @NonNull FlagContext create()
Create a new flag context instance- Returns:
- Constructed instance
-
addPresenceFlag
public void addPresenceFlag(@NonNull CommandFlag<?> flag)
Indicate that a presence flag was supplied- Parameters:
flag
- Flag instance
-
addValueFlag
public <T> void addValueFlag(@NonNull CommandFlag<T> flag, @NonNull T value)
Store a value associated with a value flag- Type Parameters:
T
- Value type- Parameters:
flag
- Value flagvalue
- Flag value
-
isPresent
public boolean isPresent(@NonNull java.lang.String flag)
Check whether a presence flag is present. This will returnfalse
for all value flags.- Parameters:
flag
- Flag name- Returns:
true
if the flag is a presence flag and is present, elsefalse
-
isPresent
public boolean isPresent(@NonNull CommandFlag<java.lang.Void> flag)
Check whether a presence flag is present. This will returnfalse
for all value flags.- Parameters:
flag
- A presence flag instance- Returns:
true
if the flag is a presence flag and is present, elsefalse
- Since:
- 1.4.0
-
getValue
public <T> @NonNull java.util.Optional<T> getValue(@NonNull java.lang.String name)
Get a flag value as an optional. Will be empty if the value is not present.- Type Parameters:
T
- Value type- Parameters:
name
- Flag name- Returns:
- Optional containing stored value if present
- Since:
- 1.2.0
-
getValue
public <T> @NonNull java.util.Optional<T> getValue(@NonNull CommandFlag<T> flag)
Get a flag value as an optional. Will be empty if the value is not present.- Type Parameters:
T
- Value type- Parameters:
flag
- Flag type- Returns:
- Optional containing stored value if present
- Since:
- 1.4.0
-
getValue
public <T> @Nullable T getValue(@NonNull java.lang.String name, @Nullable T defaultValue)
Get a flag value- Type Parameters:
T
- Value type- Parameters:
name
- Flag namedefaultValue
- Default value- Returns:
- Stored value, or the supplied default value
-
getValue
public <T> @Nullable T getValue(@NonNull CommandFlag<T> name, @Nullable T defaultValue)
Get a flag value- Type Parameters:
T
- Value type- Parameters:
name
- Flag valuedefaultValue
- Default value- Returns:
- Stored value, or the supplied default value
- Since:
- 1.4.0
-
hasFlag
public boolean hasFlag(@NonNull java.lang.String name)
Check whether a flag is present. This will returntrue
if the flag is a presence flag and is present, or if the flag is a value flag and has a value provided.- Parameters:
name
- Flag name- Returns:
- whether the flag is present
- Since:
- 1.2.0
-
hasFlag
public boolean hasFlag(@NonNull CommandFlag<?> flag)
Check whether a flag is present. This will returntrue
if the flag is a presence flag and is present, or if the flag is a value flag and has a value provided.- Parameters:
flag
- The flag instance- Returns:
- whether the flag is present
- Since:
- 1.4.0
-
contains
public boolean contains(@NonNull java.lang.String name)
Check whether a flag is present. This will returntrue
if the flag is a presence flag and is present, or if the flag is a value flag and has a value provided.- Parameters:
name
- Flag name- Returns:
- whether the flag is present
- Since:
- 1.3.0
-
contains
public boolean contains(@NonNull CommandFlag<?> flag)
Check whether a flag is present. This will returntrue
if the flag is a presence flag and is present, or if the flag is a value flag and has a value provided.- Parameters:
flag
- Flag instance- Returns:
- whether the flag is present
- Since:
- 1.4.0
-
get
public <T> @Nullable T get(@NonNull java.lang.String name)
Get a flag value- Type Parameters:
T
- Value type- Parameters:
name
- Flag name- Returns:
- Stored value if present, else
null
- Since:
- 1.3.0
-
get
public <T> @Nullable T get(@NonNull CommandFlag<T> flag)
Get a flag value- Type Parameters:
T
- Value type- Parameters:
flag
- Flag name- Returns:
- Stored value if present, else
null
- Since:
- 1.4.0
-
-