Class FlagContext
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectDummy object stored as a flag value when the flag has no associated parser -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPresenceFlag(@NonNull CommandFlag<?> flag) Indicate that a presence flag was supplied<T> voidaddValueFlag(@NonNull CommandFlag<T> flag, @NonNull T value) Store a value associated with a value flagbooleancontains(@NonNull CommandFlag<?> flag) Check whether a flag is present.booleanCheck whether a flag is present.<T> intcount(@NonNull CommandFlag<T> flag) Returns the number of values associated with the givenflag.<T> intReturns the number of values associated with the givenflag.static @NonNull FlagContextcreate()Create a new flag context instance<T> @Nullable Tget(@NonNull CommandFlag<T> flag) Returns a flag value.<T> @Nullable TReturns a flag value.<T> @NonNull Collection<T>getAll(@NonNull CommandFlag<T> flag) Returns all supplied flag values for the givenflag.<T> @NonNull Collection<T>Returns all supplied flag values for the givenflag.<T> @NonNull Optional<T>getValue(@NonNull CommandFlag<T> flag) Returns a flag value.<T> @Nullable TgetValue(@NonNull CommandFlag<T> name, @Nullable T defaultValue) Returns a flag value.<T> @NonNull Optional<T>Returns a flag value.<T> @Nullable TReturns a flag value.booleanhasFlag(@NonNull CommandFlag<?> flag) Check whether a flag is present.booleanCheck whether a flag is present.booleanisPresent(@NonNull CommandFlag<Void> flag) Check whether a presence flag is present.booleanCheck whether a presence flag is present.
-
Field Details
-
FLAG_PRESENCE_VALUE
Dummy object stored as a flag value when the flag has no associated parser
-
-
Method Details
-
create
Create a new flag context instance- Returns:
- Constructed instance
-
addPresenceFlag
Indicate that a presence flag was supplied- Parameters:
flag- Flag instance
-
addValueFlag
Store a value associated with a value flag- Type Parameters:
T- Value type- Parameters:
flag- Value flagvalue- Flag value
-
count
Returns the number of values associated with the givenflag.- Type Parameters:
T- the flag value type- Parameters:
flag- the flag- Returns:
- the number of values associated with the flag
- Since:
- 1.7.0
-
count
Returns the number of values associated with the givenflag.- Type Parameters:
T- the flag value type- Parameters:
flag- the flag- Returns:
- the number of values associated with the flag
- Since:
- 1.7.0
-
isPresent
Check whether a presence flag is present. This will returnfalsefor all value flags.- Parameters:
flag- Flag name- Returns:
trueif the flag is a presence flag and is present, elsefalse
-
isPresent
Check whether a presence flag is present. This will returnfalsefor all value flags.- Parameters:
flag- A presence flag instance- Returns:
trueif the flag is a presence flag and is present, elsefalse- Since:
- 1.4.0
-
getValue
Returns a flag value.If using
CommandFlag.FlagMode.SINGLEthen this returns the only value, if it has been specified. If usingCommandFlag.FlagMode.REPEATABLEthen it'll return the first value.- Type Parameters:
T- Value type- Parameters:
name- Flag name- Returns:
- Optional containing stored value if present
- Since:
- 1.2.0
-
getValue
@API(status=STABLE, since="1.4.0") public <T> @NonNull Optional<T> getValue(@NonNull CommandFlag<T> flag) Returns a flag value.If using
CommandFlag.FlagMode.SINGLEthen this returns the only value, if it has been specified. If usingCommandFlag.FlagMode.REPEATABLEthen it'll return the first value.- Type Parameters:
T- Value type- Parameters:
flag- Flag type- Returns:
- Optional containing stored value if present
- Since:
- 1.4.0
-
getValue
Returns a flag value.If using
CommandFlag.FlagMode.SINGLEthen this returns the only value, if it has been specified. If usingCommandFlag.FlagMode.REPEATABLEthen it'll return the first value.- Type Parameters:
T- Value type- Parameters:
name- Flag namedefaultValue- Default value- Returns:
- Stored value, or the supplied default value
-
getValue
@API(status=STABLE, since="1.4.0") public <T> @Nullable T getValue(@NonNull CommandFlag<T> name, @Nullable T defaultValue) Returns a flag value.If using
CommandFlag.FlagMode.SINGLEthen this returns the only value, if it has been specified. If usingCommandFlag.FlagMode.REPEATABLEthen it'll return the first 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
Check whether a flag is present. This will returntrueif 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
Check whether a flag is present. This will returntrueif 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
Check whether a flag is present. This will returntrueif 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
Check whether a flag is present. This will returntrueif 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
Returns a flag value.If using
CommandFlag.FlagMode.SINGLEthen this returns the only value, if it has been specified. If usingCommandFlag.FlagMode.REPEATABLEthen it'll return the first value.- Type Parameters:
T- Value type- Parameters:
name- Flag name- Returns:
- Stored value if present, else
null - Since:
- 1.3.0
-
get
Returns a flag value.If using
CommandFlag.FlagMode.SINGLEthen this returns the only value, if it has been specified. If usingCommandFlag.FlagMode.REPEATABLEthen it'll return the first value.- Type Parameters:
T- Value type- Parameters:
flag- Flag name- Returns:
- Stored value if present, else
null - Since:
- 1.4.0
-
getAll
@API(status=STABLE, since="1.7.0") public <T> @NonNull Collection<T> getAll(@NonNull CommandFlag<T> flag) Returns all supplied flag values for the givenflag.- Type Parameters:
T- the flag value type- Parameters:
flag- the flag- Returns:
- unmodifiable view of all stored flag values, or
Collections.emptyList(). - Since:
- 1.7.0
-
getAll
Returns all supplied flag values for the givenflag.- Type Parameters:
T- the flag value type- Parameters:
flag- the flag- Returns:
- unmodifiable view of all stored flag values, or
Collections.emptyList(). - Since:
- 1.7.0
-