Interface DatabaseInputFunction<D>
- All Superinterfaces:
BiFunction<String,Long,reactor.core.publisher.Mono<D>>
public interface DatabaseInputFunction<D> extends BiFunction<String,Long,reactor.core.publisher.Mono<D>>
Function that determines the value to save to the database after reading the user input as String.
-
Method Summary
Modifier and Type Method Description static DatabaseInputFunction<String>
asIs()
Forwards the input value to the database as is, without any modification or check.static <D> DatabaseInputFunction<D>
of(BiFunction<String,Long,reactor.core.publisher.Mono<D>> function)
Encapsulates a regular BiFunction into an instance ofDatabaseInputFunction
.static <D> DatabaseInputFunction<D>
to(Function<? super String,D> converter)
Converts the input using the supplied conversion function.static DatabaseInputFunction<Long>
toChannelId(Bot bot, Class<? extends discord4j.core.object.entity.GuildChannel> channelType)
Converts the input into a channel and forwards its ID to the database.static DatabaseInputFunction<Long>
toRoleId(Bot bot)
Converts the input into a role and forwards its ID to the database.static DatabaseInputFunction<Long>
toUserId(Bot bot)
Converts the input into a user and forwards its ID to the database.default DatabaseInputFunction<D>
withInputCheck(Predicate<String> inputCheck, String errorMessage)
Adds a check on the user input before this function is executed.default DatabaseInputFunction<D>
withValueCheck(Predicate<D> valueCheck, String errorMessage)
Adds a check on the value produced by this function, after the user input was process by this function.
-
Method Details
-
withInputCheck
Adds a check on the user input before this function is executed. If the check is not fulfilled, the Mono returned will emitIllegalArgumentException
instead of the produced value.- Parameters:
inputCheck
- the predicate to check the inputerrorMessage
- the error message that theIllegalArgumentException
should carry- Returns:
- a database input function identical to this one if the check passes, or turns it into an error otherwise
-
withValueCheck
Adds a check on the value produced by this function, after the user input was process by this function. If the check is not fulfilled, the Mono returned will emitIllegalArgumentException
instead of the produced value.- Parameters:
valueCheck
- the predicate to check the inputerrorMessage
- the error message that theIllegalArgumentException
should carry- Returns:
- a database input function identical to this one if the check passes, or turns it into an error otherwise
-
asIs
Forwards the input value to the database as is, without any modification or check.- Returns:
- a database input function
-
of
static <D> DatabaseInputFunction<D> of(BiFunction<String,Long,reactor.core.publisher.Mono<D>> function)Encapsulates a regular BiFunction into an instance ofDatabaseInputFunction
.- Type Parameters:
D
- the target database type- Parameters:
function
- the function to encapsulate- Returns:
- a database input function wrapping the given function
-
to
Converts the input using the supplied conversion function.- Type Parameters:
D
- the target database type- Parameters:
converter
- the conversion function- Returns:
- a database input function transforming the output to a target type
-
toRoleId
Converts the input into a role and forwards its ID to the database. If no role is found, anIllegalArgumentException
is thrown.- Parameters:
bot
- the bot instance to use in order to fetch roles- Returns:
- a database input function transforming the output to a role ID
-
toUserId
Converts the input into a user and forwards its ID to the database. If no user is found, anIllegalArgumentException
is thrown.- Parameters:
bot
- the bot instance to use in order to fetch users- Returns:
- a database input function transforming the output to a user ID
-
toChannelId
static DatabaseInputFunction<Long> toChannelId(Bot bot, Class<? extends discord4j.core.object.entity.GuildChannel> channelType)Converts the input into a channel and forwards its ID to the database. If no channel is found, anIllegalArgumentException
is thrown.- Parameters:
bot
- the bot instance to use in order to fetch channelschannelType
- the accepted type of channel- Returns:
- a database input function transforming the output to a channel ID
-