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
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
ParserFunction.PostParser<R extends @NonNull Object,
I extends @NonNull Object, T extends @NonNull Object, P1 extends @NonNull ParserFunction<R, I>, P2 extends @NonNull ParserFunction<I, T>> -
Constructor Summary
ConstructorsConstructorDescriptionStringAdapter
(ParserFunction<String, R> rawParser, ParserFunction<R, T> valueParser) Creates an instance of aStringAdapter
record class. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.parse
(CommandContext context, String raw) Parses the given raw argument from the user into the corresponding value.Returns the value of therawParser
record component.final String
toString()
Returns a string representation of this record class.Returns the value of thevalueParser
record component.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.function.BiFunction
andThen
Methods inherited from interface dev.sympho.modular_commands.api.command.parameter.parse.ParserFunction
apply, then
-
Constructor Details
-
StringAdapter
Creates an instance of aStringAdapter
record class.- Parameters:
rawParser
- the value for therawParser
record componentvalueParser
- the value for thevalueParser
record component
-
-
Method Details
-
parse
Description copied from interface:ParserFunction
Parses the given raw argument from the user into the corresponding value.- Specified by:
parse
in interfaceParserFunction<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 thedefault
(functionally the same as if the argument was missing, but without causing an error if the parameter isrequired
).
-
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)
. -
rawParser
Returns the value of therawParser
record component.- Returns:
- the value of the
rawParser
record component
-
valueParser
Returns the value of thevalueParser
record component.- Returns:
- the value of the
valueParser
record component
-