Class FlagSet
java.lang.Object
com.github.alex1304.ultimategdbot.api.command.FlagSet
public class FlagSet
extends java.lang.Object
Contains the set of flags used in a command. A flag is defined by a name and
an optional value.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FlagSet.FlagSetBuilder
-
Constructor Summary
Constructors Constructor Description FlagSet(java.util.Map<java.lang.String,java.util.Optional<java.lang.String>> flagMap)
-
Method Summary
Modifier and Type Method Description static FlagSet.FlagSetBuilder
builder()
Creates a builder to configure a new set of flags.java.util.Optional<java.lang.String>
get(java.lang.String name)
Gets the value of the flag with the given name.boolean
has(java.lang.String name)
Checks whether the flag with he given name is present in this set.<T> java.util.Optional<T>
parseAndGet(java.lang.String name, java.util.function.Function<java.lang.String,T> parser)
Gets the value of the flag with the given name, and transforms the value using the supplied function.java.lang.String
toString()
-
Constructor Details
-
FlagSet
public FlagSet(java.util.Map<java.lang.String,java.util.Optional<java.lang.String>> flagMap)
-
-
Method Details
-
builder
Creates a builder to configure a new set of flags.- Returns:
- a flag builder
-
has
public boolean has(java.lang.String name)Checks whether the flag with he given name is present in this set.- Parameters:
name
- the name of the flag to look for- Returns:
- true if present in the set, false otherwise
-
get
public java.util.Optional<java.lang.String> get(java.lang.String name)Gets the value of the flag with the given name. If the flag has no value, an empty Optional is returned. If the flag is not present at all,NoSuchElementException
will be thrown.- Parameters:
name
- the name of the flag to look for- Returns:
- the value of the flag, or empty optional if no value
- Throws:
java.util.NoSuchElementException
- if the flag is not present at all
-
parseAndGet
public <T> java.util.Optional<T> parseAndGet(java.lang.String name, java.util.function.Function<java.lang.String,T> parser)Gets the value of the flag with the given name, and transforms the value using the supplied function.- Type Parameters:
T
- the target type of the flag value- Parameters:
name
- the name of the flag to look forparser
- the transformation function of the value- Returns:
- the transformed value, or empty if no value
- Throws:
java.util.NoSuchElementException
- if the flag is not present at all
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-