Record Class StringAdapter<R extends @NonNull Object,T extends @NonNull Object>

java.lang.Object
java.lang.Record
dev.sympho.modular_commands.utils.parse.StringAdapter<R,T>
Type Parameters:
R - The raw type of the original parser.
T - The parsed argument type.
Record Components:
rawParser - The parser to use to pre-parse into the raw type.
valueParser - The parser to use to parse the raw type.
All Implemented Interfaces:
ParserFunction<String,T>, BiFunction<CommandContext,String,Mono<T>>

public record StringAdapter<R extends @NonNull Object,T extends @NonNull Object>(ParserFunction<String,R extends @NonNull Object> rawParser, ParserFunction<R extends @NonNull Object,T extends @NonNull Object> valueParser) extends Record implements ParserFunction<String,T>
Adapter that converts an existing parser into a string parser, by first pre-parsing the string into another raw type.
Since:
1.0
Version:
1.0
  • Constructor Details

    • StringAdapter

      public StringAdapter(ParserFunction<String,R> rawParser, ParserFunction<R,T> valueParser)
      Creates an instance of a StringAdapter record class.
      Parameters:
      rawParser - the value for the rawParser record component
      valueParser - the value for the valueParser record component
  • Method Details

    • parse

      public Mono<T> parse(CommandContext context, String raw)
      Description copied from interface: ParserFunction
      Parses the given raw argument from the user into the corresponding value.
      Specified by:
      parse in interface ParserFunction<R extends @NonNull Object,T extends @NonNull Object>
      Parameters:
      context - The execution context.
      raw - The raw argument received from the user.
      Returns:
      A Mono that issues the parsed argument. If the raw value is invalid, it may fail with a InvalidArgumentException. May be empty, in which case the value defers to the default (functionally the same as if the argument was missing, but without causing an error if the parameter is required).
    • 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.
    • rawParser

      public ParserFunction<String,R> rawParser()
      Returns the value of the rawParser record component.
      Returns:
      the value of the rawParser record component
    • valueParser

      public ParserFunction<R,T> valueParser()
      Returns the value of the valueParser record component.
      Returns:
      the value of the valueParser record component