Class ParseUtils
java.lang.Object
dev.sympho.modular_commands.utils.parse.ParseUtils
Convenience functions for common parsers.
- Since:
- 1.0
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ParserFunction<String,
Boolean> Parser for booleans from strings.static final ParserFunction<String,
Snowflake> Parser for channel IDs from strings.static final ParserFunction<String,
Double> Parser for floats from strings.static final ParserFunction<String,
Long> Parser for integers from strings.static final MessageParser
Parser for messages from strings.static final ParserFunction<String,
Snowflake> Parser for message IDs from strings.static final MessageRefParser
Parser for message references from strings.static final RoleParser
Parser for roles from strings.static final ParserFunction<String,
Snowflake> Parser for role IDs from strings.static final RoleRefParser
Parser for role references from strings.static final ParserFunction<String,
Snowflake> Parser for snowflakes from strings.static final UserParser
Parser for users from strings.static final ParserFunction<String,
Snowflake> Parser for user IDs from strings.static final UserRefParser
Parser for user references from strings. -
Method Summary
Modifier and TypeMethodDescriptionstatic <C extends Channel,
T extends @NonNull Object>
ParserFunction<String,T> adaptChannel
(ParserFunction<C, T> parser, Class<C> type) Creates an adapter for a channel parser to be used with string values.static <T extends @NonNull Object>
ParserFunction<String,T> adaptFloat
(ParserFunction<Double, T> parser) Creates an adapter for an float parser to be used with string values.static <T extends @NonNull Object>
ParserFunction<String,T> adaptInteger
(ParserFunction<Long, T> parser) Creates an adapter for an integer parser to be used with string values.static <T extends @NonNull Object>
ParserFunction<String,T> adaptMessage
(ParserFunction<Message, T> parser) Creates an adapter for a message parser to be used with string values.static <T extends @NonNull Object>
ParserFunction<String,T> adaptRole
(ParserFunction<Role, T> parser) Creates an adapter for a role parser to be used with string values.static <T extends @NonNull Object>
ParserFunction<String,T> adaptSnowflake
(ParserFunction<Snowflake, T> parser) Creates an adapter for a snowflake parser to be used with string values.static <T extends @NonNull Object>
ParserFunction<String,T> adaptUser
(ParserFunction<User, T> parser) Creates an adapter for an user parser to be used with string values.static <C extends @NonNull Channel>
ChannelParser<C>Creates a parser for channels of the given type.static <C extends @NonNull Channel>
ChannelRefParser<C>channelRef
(Class<C> type) Creates a parser for channel references of the given type.static <C extends Channel>
ListParser<C>A parser that parses a list of channels.static ListParser<Double>
floats()
A parser that parses a list of floats.static <T extends @NonNull Object>
StringParser<Flux<T>>flux
(ParserFunction<String, Mono<T>> parser) A parser that generates a flux by using the defaultlist parser
to split the raw argument, then the given item parser to convert each item into a mono, which are then merged.static ListParser<Long>
integers()
A parser that parses a list of integers.static ListParser<Message>
messages()
A parser that parses a list of messages.static ListParser<Role>
roles()
A parser that parses a list of roles.static ListParser<Snowflake>
A parser that parses a list of snowflake IDs.static ListParser<User>
users()
A parser that parses a list of users.
-
Field Details
-
BOOLEAN
Parser for booleans from strings. -
INTEGER
Parser for integers from strings. -
FLOAT
Parser for floats from strings. -
SNOWFLAKE
Parser for snowflakes from strings. -
MESSAGE
Parser for messages from strings. -
USER
Parser for users from strings. -
ROLE
Parser for roles from strings. -
MESSAGE_REF
Parser for message references from strings. -
USER_REF
Parser for user references from strings. -
ROLE_REF
Parser for role references from strings. -
MESSAGE_ID
Parser for message IDs from strings. -
USER_ID
Parser for user IDs from strings. -
ROLE_ID
Parser for role IDs from strings. -
CHANNEL_ID
Parser for channel IDs from strings.
-
-
Method Details
-
channel
Creates a parser for channels of the given type.- Type Parameters:
C
- The channel type.- Parameters:
type
- The type.- Returns:
- The parser.
-
channelRef
@SideEffectFree public static <C extends @NonNull Channel> ChannelRefParser<C> channelRef(Class<C> type) Creates a parser for channel references of the given type.- Type Parameters:
C
- The channel type.- Parameters:
type
- The type.- Returns:
- The parser.
-
adaptInteger
@SideEffectFree public static <T extends @NonNull Object> ParserFunction<String,T> adaptInteger(ParserFunction<Long, T> parser) Creates an adapter for an integer parser to be used with string values.- Type Parameters:
T
- The parsed value type.- Parameters:
parser
- The parser to use.- Returns:
- The adapter parser.
-
adaptFloat
@SideEffectFree public static <T extends @NonNull Object> ParserFunction<String,T> adaptFloat(ParserFunction<Double, T> parser) Creates an adapter for an float parser to be used with string values.- Type Parameters:
T
- The parsed value type.- Parameters:
parser
- The parser to use.- Returns:
- The adapter parser.
-
adaptSnowflake
@SideEffectFree public static <T extends @NonNull Object> ParserFunction<String,T> adaptSnowflake(ParserFunction<Snowflake, T> parser) Creates an adapter for a snowflake parser to be used with string values.- Type Parameters:
T
- The parsed value type.- Parameters:
parser
- The parser to use.- Returns:
- The adapter parser.
-
adaptMessage
@SideEffectFree public static <T extends @NonNull Object> ParserFunction<String,T> adaptMessage(ParserFunction<Message, T> parser) Creates an adapter for a message parser to be used with string values.- Type Parameters:
T
- The parsed value type.- Parameters:
parser
- The parser to use.- Returns:
- The adapter parser.
-
adaptUser
@SideEffectFree public static <T extends @NonNull Object> ParserFunction<String,T> adaptUser(ParserFunction<User, T> parser) Creates an adapter for an user parser to be used with string values.- Type Parameters:
T
- The parsed value type.- Parameters:
parser
- The parser to use.- Returns:
- The adapter parser.
-
adaptRole
@SideEffectFree public static <T extends @NonNull Object> ParserFunction<String,T> adaptRole(ParserFunction<Role, T> parser) Creates an adapter for a role parser to be used with string values.- Type Parameters:
T
- The parsed value type.- Parameters:
parser
- The parser to use.- Returns:
- The adapter parser.
-
adaptChannel
@SideEffectFree public static <C extends Channel,T extends @NonNull Object> ParserFunction<String,T> adaptChannel(ParserFunction<C, T> parser, Class<C> type) Creates an adapter for a channel parser to be used with string values.- Type Parameters:
C
- The channel type.T
- The parsed value type.- Parameters:
parser
- The parser to use.type
- The channel type.- Returns:
- The adapter parser.
-
flux
@SideEffectFree public static <T extends @NonNull Object> StringParser<Flux<T>> flux(ParserFunction<String, Mono<T>> parser) A parser that generates a flux by using the defaultlist parser
to split the raw argument, then the given item parser to convert each item into a mono, which are then merged.- Type Parameters:
T
- The item type.- Parameters:
parser
- The parser that creates monos for each item to be parsed.- Returns:
- The parser.
-
integers
A parser that parses a list of integers.Values are separated by whitespace.
- Returns:
- The parser.
-
floats
A parser that parses a list of floats.Values are separated by whitespace.
- Returns:
- The parser.
-
snowflakes
A parser that parses a list of snowflake IDs.IDs are separated by whitespace.
- Returns:
- The parser.
-
messages
A parser that parses a list of messages.Messages are separated by whitespace.
- Returns:
- The parser.
-
users
A parser that parses a list of users.Users are separated by whitespace.
- Returns:
- The parser.
-
roles
A parser that parses a list of roles.Roles are separated by whitespace.
- Returns:
- The parser.
-
channels
A parser that parses a list of channels.Channels are separated by whitespace.
- Type Parameters:
C
- The channel type.- Parameters:
type
- The channel type.- Returns:
- The parser.
-