Interface DatabaseInputFunction<D>

All Superinterfaces:
java.util.function.BiFunction<java.lang.String,​java.lang.Long,​reactor.core.publisher.Mono<D>>

public interface DatabaseInputFunction<D>
extends java.util.function.BiFunction<java.lang.String,​java.lang.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<java.lang.String> asIs()
    Forwards the input value to the database as is, without any modification or check.
    static <D> DatabaseInputFunction<D> of​(java.util.function.BiFunction<java.lang.String,​java.lang.Long,​reactor.core.publisher.Mono<D>> function)
    Encapsulates a regular BiFunction into an instance of DatabaseInputFunction.
    static <D> DatabaseInputFunction<D> to​(java.util.function.Function<? super java.lang.String,​D> converter)
    Converts the input using the supplied conversion function.
    static DatabaseInputFunction<java.lang.Long> toChannelId​(Bot bot, java.lang.Class<? extends discord4j.core.object.entity.GuildChannel> channelType)
    Converts the input into a channel and forwards its ID to the database.
    static DatabaseInputFunction<java.lang.Long> toRoleId​(Bot bot)
    Converts the input into a role and forwards its ID to the database.
    static DatabaseInputFunction<java.lang.Long> toUserId​(Bot bot)
    Converts the input into a user and forwards its ID to the database.
    default DatabaseInputFunction<D> withInputCheck​(java.util.function.Predicate<java.lang.String> inputCheck, java.lang.String errorMessage)
    Adds a check on the user input before this function is executed.
    default DatabaseInputFunction<D> withValueCheck​(java.util.function.Predicate<D> valueCheck, java.lang.String errorMessage)
    Adds a check on the value produced by this function, after the user input was process by this function.

    Methods inherited from interface java.util.function.BiFunction

    andThen, apply
  • Method Details

    • withInputCheck

      default DatabaseInputFunction<D> withInputCheck​(java.util.function.Predicate<java.lang.String> inputCheck, java.lang.String errorMessage)
      Adds a check on the user input before this function is executed. If the check is not fulfilled, the Mono returned will emit IllegalArgumentException instead of the produced value.
      Parameters:
      inputCheck - the predicate to check the input
      errorMessage - the error message that the IllegalArgumentException should carry
      Returns:
      a database input function identical to this one if the check passes, or turns it into an error otherwise
    • withValueCheck

      default DatabaseInputFunction<D> withValueCheck​(java.util.function.Predicate<D> valueCheck, java.lang.String errorMessage)
      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 emit IllegalArgumentException instead of the produced value.
      Parameters:
      valueCheck - the predicate to check the input
      errorMessage - the error message that the IllegalArgumentException should carry
      Returns:
      a database input function identical to this one if the check passes, or turns it into an error otherwise
    • asIs

      static DatabaseInputFunction<java.lang.String> 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​(java.util.function.BiFunction<java.lang.String,​java.lang.Long,​reactor.core.publisher.Mono<D>> function)
      Encapsulates a regular BiFunction into an instance of DatabaseInputFunction.
      Type Parameters:
      D - the target database type
      Parameters:
      function - the function to encapsulate
      Returns:
      a database input function wrapping the given function
    • to

      static <D> DatabaseInputFunction<D> to​(java.util.function.Function<? super java.lang.String,​D> converter)
      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

      static DatabaseInputFunction<java.lang.Long> toRoleId​(Bot bot)
      Converts the input into a role and forwards its ID to the database. If no role is found, an IllegalArgumentException 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

      static DatabaseInputFunction<java.lang.Long> toUserId​(Bot bot)
      Converts the input into a user and forwards its ID to the database. If no user is found, an IllegalArgumentException 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<java.lang.Long> toChannelId​(Bot bot, java.lang.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, an IllegalArgumentException is thrown.
      Parameters:
      bot - the bot instance to use in order to fetch channels
      channelType - the accepted type of channel
      Returns:
      a database input function transforming the output to a channel ID