Class SelectorOptional<T>
java.lang.Object
xyz.srnyx.annoyingapi.command.selector.SelectorOptional<T>
- Type Parameters:
T- the type of the selector
A class representing an optional selector.
-
Constructor Summary
ConstructorsConstructorDescriptionSelectorOptional(@NotNull AnnoyingSender sender, @Nullable String raw, @Nullable Selector<T> selector) Constructor for SelectorOptional -
Method Summary
Modifier and TypeMethodDescription@NotNull StringgetRaw()Gets the raw input string before being parsed as a selectorGets the selector@NotNull AnnoyingSenderGets the sender who executed the commandbooleanisEmpty()Checks if the selector is absentbooleanChecks if the selector is present@NotNull SelectorOptional<T> Applies a function to therawinput string if present (after selector parsing)static <T> @NotNull SelectorOptional<T> noArgument(@NotNull AnnoyingSender sender) Creates a SelectorOptional with no argumentstatic <T> @NotNull SelectorOptional<T> noSelector(@NotNull AnnoyingSender sender, @Nullable String raw) Creates a SelectorOptional with no selectorstatic <T> @NotNull SelectorOptional<T> of(@NotNull AnnoyingSender sender, @NotNull String input) Creates a SelectorOptional with no type filtering from the given input stringstatic <T> @NotNull SelectorOptional<T> of(@NotNull AnnoyingSender sender, @NotNull String input, @NotNull Class<T> type) Creates a SelectorOptional with type filtering from the given input stringExpands the selector if present, otherwise uses the provided function to get a default valueExpands the selector if present, otherwise uses the provided function to get an optional default valueorElseFlatSingle(@NotNull Function<String, Optional<T>> other) Expands the selector if present, otherwise uses the provided function to get an optional single default valueorElseSingle(@NotNull Function<String, T> other) Expands the selector if present, otherwise uses the provided function to get a single default value
-
Constructor Details
-
SelectorOptional
public SelectorOptional(@NotNull @NotNull AnnoyingSender sender, @Nullable @Nullable String raw, @Nullable @Nullable Selector<T> selector) Constructor for SelectorOptional- Parameters:
sender- the sender who executed the commandraw- the raw input string before being parsed as a selector, if presentselector- the selector, if present
-
-
Method Details
-
getSender
Gets the sender who executed the command- Returns:
- the sender
-
getRaw
Gets the raw input string before being parsed as a selector- Returns:
- the raw input string
- Throws:
IllegalStateException- if called before checkingisEmpty()
-
getSelector
Gets the selector- Returns:
- the selector
- Throws:
IllegalStateException- if called before checkingisEmpty()
-
isPresent
public boolean isPresent()Checks if the selector is present- Returns:
- true if the selector is present, false otherwise
-
isEmpty
public boolean isEmpty()Checks if the selector is absent- Returns:
- true if the selector is absent, false otherwise
-
mapRaw
@NotNull public @NotNull SelectorOptional<T> mapRaw(@NotNull @NotNull Function<String, String> mapper) Applies a function to therawinput string if present (after selector parsing)- Parameters:
mapper- the function to map the raw input string- Returns:
- a new SelectorOptional with the mapped raw input string
-
orElse
@Nullable public @Nullable @Unmodifiable List<T> orElse(@NotNull @NotNull Function<String, List<T>> other) Expands the selector if present, otherwise uses the provided function to get a default value- Parameters:
other- the function to get a default value if the selector is absent. The raw input string (after mappings) is provided as an argument.- Returns:
- the expanded selector or the default value (both unmodifiable)
-
orElseSingle
@Nullable public @Nullable @Unmodifiable List<T> orElseSingle(@NotNull @NotNull Function<String, T> other) Expands the selector if present, otherwise uses the provided function to get a single default value- Parameters:
other- the function to get a single default value if the selector is absent. The raw input string (after mappings) is provided as an argument.- Returns:
- the expanded selector or a singleton list containing the default value (both unmodifiable)
-
orElseFlat
@Nullable public @Nullable @Unmodifiable List<T> orElseFlat(@NotNull @NotNull Function<String, Optional<List<T>>> other) Expands the selector if present, otherwise uses the provided function to get an optional default value- Parameters:
other- the function to get an optional default value if the selector is absent. The raw input string (after mappings) is provided as an argument.- Returns:
- the expanded selector (unmodifiable) or the default value
-
orElseFlatSingle
@Nullable public @Nullable @Unmodifiable List<T> orElseFlatSingle(@NotNull @NotNull Function<String, Optional<T>> other) Expands the selector if present, otherwise uses the provided function to get an optional single default value- Parameters:
other- the function to get an optional single default value if the selector is absent. The raw input string (after mappings) is provided as an argument.- Returns:
- the expanded selector or a singleton list containing the default value (both unmodifiable)
-
noArgument
@NotNull public static <T> @NotNull SelectorOptional<T> noArgument(@NotNull @NotNull AnnoyingSender sender) Creates a SelectorOptional with no argument- Type Parameters:
T- the type of the selector- Parameters:
sender- the sender who executed the command- Returns:
- a SelectorOptional with no argument
-
noSelector
@NotNull public static <T> @NotNull SelectorOptional<T> noSelector(@NotNull @NotNull AnnoyingSender sender, @Nullable @Nullable String raw) Creates a SelectorOptional with no selector- Type Parameters:
T- the type of the selector- Parameters:
sender- the sender who executed the commandraw- the raw input string that was attempted to be parsed as a selector- Returns:
- a SelectorOptional with no selector
-
of
@NotNull public static <T> @NotNull SelectorOptional<T> of(@NotNull @NotNull AnnoyingSender sender, @NotNull @NotNull String input) Creates a SelectorOptional with no type filtering from the given input string- Type Parameters:
T- the type of the selector- Parameters:
sender- the sender who executed the commandinput- the input string to parse as a selector- Returns:
- a SelectorOptional with the parsed selector, or no selector if none matched
-
of
@NotNull public static <T> @NotNull SelectorOptional<T> of(@NotNull @NotNull AnnoyingSender sender, @NotNull @NotNull String input, @NotNull @NotNull Class<T> type) Creates a SelectorOptional with type filtering from the given input string- Type Parameters:
T- the type of the selector- Parameters:
sender- the sender who executed the commandinput- the input string to parse as a selectortype- the type to filter selectors by- Returns:
- a SelectorOptional with the parsed selector, or no selector if none matched
-