Class SelectorOptional<T>

java.lang.Object
xyz.srnyx.annoyingapi.command.selector.SelectorOptional<T>
Type Parameters:
T - the type of the selector

public class SelectorOptional<T> extends Object
A class representing an optional selector.
  • 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 command
      raw - the raw input string before being parsed as a selector, if present
      selector - the selector, if present
  • Method Details

    • getSender

      @NotNull public @NotNull AnnoyingSender getSender()
      Gets the sender who executed the command
      Returns:
      the sender
    • getRaw

      @NotNull public @NotNull String getRaw()
      Gets the raw input string before being parsed as a selector
      Returns:
      the raw input string
      Throws:
      IllegalStateException - if called before checking isEmpty()
    • getSelector

      @NotNull public @NotNull Selector<T> getSelector()
      Gets the selector
      Returns:
      the selector
      Throws:
      IllegalStateException - if called before checking isEmpty()
    • 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 the raw input 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 command
      raw - 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 command
      input - 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 command
      input - the input string to parse as a selector
      type - the type to filter selectors by
      Returns:
      a SelectorOptional with the parsed selector, or no selector if none matched