Class ConfigFilters

java.lang.Object
io.github.ttno1.configvalidation.ConfigFilters

public final class ConfigFilters extends Object
Utility class with methods that provide common ConfigFilters.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Represents the state of a file on the file system.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T,U> ConfigFilter<List<T>,List<U>>
    forEach(ConfigFilter<T,U> filter)
    Returns a filter that applies the provided filter to a list of elements of the provided filter's input type and returns a list of elements of the provided filter's output type.
    Similar to Stream.map(java.util.function.Function).
    Note that in the event of a failure, the returned filter will continue to apply the supplied filter to the remaining elements in the list and the fail message will contain the fail message of all failed list items.
    static <T extends Enum<T>>
    ConfigFilter<String,T>
    validEnum(Class<T> enumClass)
    Returns a filter that attempts to convert the input string into a value of the provided enum type and fails if the input string is not a valid enum type.
    The filter will call String.toUpperCase() on the input string and replace all spaces (U+0020) with underscores before attempting to call Enum.valueOf(Class, String).
    Returns a filter that verifies that the input string is a valid file path, and optionally that the file meets the conditions specified by the provided ConfigFilters.FileState, and that converts the string to a Path.
    validURL(String... schemes)
    Returns a filter that first verifies that the input string is a valid URL using Apache Commons Validator UrlValidator.isValid(String) with the provided schemes, and then attempts to convert the string into a URL with URL(String).

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • forEach

      public static <T,U> ConfigFilter<List<T>,List<U>> forEach(ConfigFilter<T,U> filter)
      Returns a filter that applies the provided filter to a list of elements of the provided filter's input type and returns a list of elements of the provided filter's output type.
      Similar to Stream.map(java.util.function.Function).
      Note that in the event of a failure, the returned filter will continue to apply the supplied filter to the remaining elements in the list and the fail message will contain the fail message of all failed list items.
      Type Parameters:
      T -
      U -
      Parameters:
      filter -
      Returns:
      a filter that maps the provided filter to a list
    • validEnum

      public static <T extends Enum<T>> ConfigFilter<String,T> validEnum(Class<T> enumClass)
      Returns a filter that attempts to convert the input string into a value of the provided enum type and fails if the input string is not a valid enum type.
      The filter will call String.toUpperCase() on the input string and replace all spaces (U+0020) with underscores before attempting to call Enum.valueOf(Class, String).
      Type Parameters:
      T -
      Parameters:
      enumClass - the enum type to convert to
      Returns:
      a filter that attempts to convert the input string into a value of the provided enum type
    • validURL

      public static ConfigFilter<String,URL> validURL(String... schemes)
      Returns a filter that first verifies that the input string is a valid URL using Apache Commons Validator UrlValidator.isValid(String) with the provided schemes, and then attempts to convert the string into a URL with URL(String).
      Parameters:
      schemes - the schemes to pass into the UrlValidator (e.g. "http", "https", "ftp") or none to use the default {"http", "https"}
      Returns:
      a filter that converts a string into a URL if valid
    • validPath

      public static ConfigFilter<String,Path> validPath(ConfigFilters.FileState fileState)
      Returns a filter that verifies that the input string is a valid file path, and optionally that the file meets the conditions specified by the provided ConfigFilters.FileState, and that converts the string to a Path.
      Parameters:
      fileState - the state of the file that should be required for the filter to pass, see ConfigFilters.FileState for more info
      Returns:
      a filter that converts a string to a Path