Interface ConfigFilter<T,U>

Type Parameters:
T - The input type
U - The output type
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 ConfigFilter<T,U>
A functional interface for functions that validate config input and optionally convert it to a new output type.
ConfigFilters are intended to be chained together with withFilter(ConfigFilter).
See ConfigFilterResult for information on the return type of this function.
  • Method Summary

    Modifier and Type
    Method
    Description
    filter(T input)
    Checks that the input is valid and optionally converts it to a new type.
    static <X> ConfigFilter<X,X>
    A "null" filter that does nothing.
    static <X> ConfigFilter<X,X>
    run(Consumer<X> consumer)
    Returns a ConfigFilter that runs the provided Consumer and passes.
    default ConfigFilter<T,U>
    thenRun(Consumer<U> consumer)
    Runs a Consumer with the output of this filter.
    Useful for retrieving the value of a filter.
    default <V> ConfigFilter<T,V>
    Returns a filter that takes in the input of this and returns the output of the supplied filter.
    Useful for chaining multiple filters together into one filter.
  • Method Details

    • filter

      ConfigFilterResult<U> filter(T input)
      Checks that the input is valid and optionally converts it to a new type.
      Parameters:
      input - the input to filter
      Returns:
      a ConfigFilterResult containing whether this filter passed and the new type it was converted to
    • withFilter

      default <V> ConfigFilter<T,V> withFilter(ConfigFilter<U,V> filter)
      Returns a filter that takes in the input of this and returns the output of the supplied filter.
      Useful for chaining multiple filters together into one filter.
      Type Parameters:
      V - the type that the new filter returns
      Parameters:
      filter - a filter that takes the output of this and returns a new type
      Returns:
      a filter that takes the input of this and returns the output of the supplied filter
      Throws:
      NullPointerException - if filter is null
    • thenRun

      default ConfigFilter<T,U> thenRun(Consumer<U> consumer)
      Runs a Consumer with the output of this filter.
      Useful for retrieving the value of a filter.
      Parameters:
      consumer - the consumer to be run
      Returns:
      a filter that outputs the same value as this after running the supplied Consumer
    • run

      static <X> ConfigFilter<X,X> run(Consumer<X> consumer)
      Returns a ConfigFilter that runs the provided Consumer and passes.
      Parameters:
      consumer - the consumer to be run
      Returns:
      a filter that outputs its input after running the supplied Consumer
    • nullFilter

      static <X> ConfigFilter<X,X> nullFilter()
      A "null" filter that does nothing. It will always pass with its input as its output.
      Type Parameters:
      X - the type of the filter input and output
      Returns:
      a filter that passes with its input as its output