Record Class SelectorOptional<T>
java.lang.Object
java.lang.Record
xyz.srnyx.annoyingapi.command.selector.SelectorOptional<T>
- Type Parameters:
T- the type of the selector- Record Components:
sender- The sender who executed the commandraw- The raw input string before being parsed as a selector, if presentselector- The selector, if present
public record SelectorOptional<T>(@NotNull AnnoyingSender sender, @Nullable String raw, @Nullable Selector<T> selector)
extends Record
A class representing an optional selector.
-
Constructor Summary
ConstructorsConstructorDescriptionSelectorOptional(@NotNull AnnoyingSender sender, @Nullable String raw, @Nullable Selector<T> selector) Creates an instance of aSelectorOptionalrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisEmpty()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@NotNull Stringraw()Gets the raw input string before being parsed as a selectorselector()Gets the selector@NotNull AnnoyingSendersender()Gets the sender who executed the commandfinal StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SelectorOptional
public SelectorOptional(@NotNull @NotNull AnnoyingSender sender, @Nullable @Nullable String raw, @Nullable @Nullable Selector<T> selector) Creates an instance of aSelectorOptionalrecord class.
-
-
Method Details
-
sender
Gets the sender who executed the command- Returns:
- the sender
-
raw
Gets the raw input string before being parsed as a selector- Returns:
- the raw input string
- Throws:
IllegalStateException- if called before checkingisEmpty()
-
selector
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
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object).
-