Interface ArgumentParser<T>
-
- Type Parameters:
T
- the value type
- All Known Implementing Classes:
MaterialParser
,MaterialParser
,OfflinePlayerParser
,OfflinePlayerParser
,PlayerExactParser
,PlayerExactParser
,PlayerParser
,PlayerParser
,ProxiedPlayerParser
,SoundParser
,SoundParser
,UUIDParser
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ArgumentParser<T>
Parses an argument from a String
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default IllegalArgumentException
generateException(@NotNull Argument argument)
Generates an exception that throws when the parsing fails.default IllegalArgumentException
generateException(@NotNull Argument argument, @Nullable Throwable exception)
Generates an exception that throws when the parsing fails.static <R> ArgumentParser<R>
of(@NotNull Function<Argument,R> function)
Creates an instance of the parser fromFunction
.T
parse(@NotNull Argument argument)
Parses anArgument
to a specified type and returns it.default Optional<T>
parseOptional(@NotNull Argument argument)
Parses anArgument
to a specified type and returns it.default T
parseOrDefault(@NotNull Argument argument, T def)
Parses anArgument
to a specified type and returns it.default T
parseOrThrow(@NotNull Argument argument)
Parses anArgument
to a specified type and returns it.
-
-
-
Method Detail
-
of
static <R> ArgumentParser<R> of(@NotNull @NotNull Function<Argument,R> function)
Creates an instance of the parser fromFunction
.- Type Parameters:
R
- the value type- Parameters:
function
- theFunction
to parseArgument
to a specific type.- Returns:
- the
ArgumentParser
instance
-
parse
@Nullable T parse(@NotNull @NotNull Argument argument)
Parses anArgument
to a specified type and returns it.- Parameters:
argument
- the argument to be parsed- Returns:
- the value to be parsed, or
null
if the parsing fails
-
parseOptional
default Optional<T> parseOptional(@NotNull @NotNull Argument argument)
Parses anArgument
to a specified type and returns it.- Parameters:
argument
- the argument to be parsed- Returns:
- the
Optional
value
-
parseOrDefault
@NotNull default T parseOrDefault(@NotNull @NotNull Argument argument, @NotNull T def)
Parses anArgument
to a specified type and returns it.- Parameters:
argument
- the argument to be parseddef
- the default value to be returned if the parsing fails- Returns:
- the value to be parsed, or default value if the parsing fails
-
parseOrThrow
@NotNull default T parseOrThrow(@NotNull @NotNull Argument argument) throws IllegalArgumentException
Parses anArgument
to a specified type and returns it.Depending on the implementation, it is possible to use
Throwable.getCause()
to get the exception that caused the conversion to fail.- Parameters:
argument
- the argument to be parsed- Returns:
- the value to be parsed, or
null
if the parsing fails - Throws:
IllegalArgumentException
- if the parsing fails
-
generateException
default IllegalArgumentException generateException(@NotNull @NotNull Argument argument)
Generates an exception that throws when the parsing fails.- Parameters:
argument
- the argument that failed to be parsed- Returns:
- the generated exception
-
generateException
default IllegalArgumentException generateException(@NotNull @NotNull Argument argument, @Nullable @Nullable Throwable exception)
Generates an exception that throws when the parsing fails.- Parameters:
argument
- the argument that failed to be parsedexception
- the exception that caused the parsing to fail- Returns:
- the generated exception
-
-