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 command
raw - The raw input string before being parsed as a selector, if present
selector - 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 Details

    • SelectorOptional

      public SelectorOptional(@NotNull @NotNull AnnoyingSender sender, @Nullable @Nullable String raw, @Nullable @Nullable Selector<T> selector)
      Creates an instance of a SelectorOptional record class.
      Parameters:
      sender - the value for the sender record component
      raw - the value for the raw record component
      selector - the value for the selector record component
  • Method Details

    • sender

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

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

      @NotNull public @NotNull Selector<T> selector()
      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
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.