Class ConfigFilters
java.lang.Object
io.github.ttno1.configvalidation.ConfigFilters
Utility class with methods that provide common ConfigFilters.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Represents the state of a file on the file system. -
Method Summary
Modifier and TypeMethodDescriptionstatic <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 toStream.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> 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 callString.toUpperCase()
on the input string and replace all spaces (U+0020) with underscores before attempting to callEnum.valueOf(Class, String)
.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 providedConfigFilters.FileState
, and that converts the string to aPath
.static ConfigFilter
<String, URL> Returns a filter that first verifies that the input string is a valid URL using Apache Commons ValidatorUrlValidator.isValid(String)
with the provided schemes, and then attempts to convert the string into aURL
withURL(String)
.
-
Method Details
-
forEach
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 toStream.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
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 callString.toUpperCase()
on the input string and replace all spaces (U+0020) with underscores before attempting to callEnum.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
Returns a filter that first verifies that the input string is a valid URL using Apache Commons ValidatorUrlValidator.isValid(String)
with the provided schemes, and then attempts to convert the string into aURL
withURL(String)
.- Parameters:
schemes
- the schemes to pass into theUrlValidator
(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
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 providedConfigFilters.FileState
, and that converts the string to aPath
.- Parameters:
fileState
- the state of the file that should be required for the filter to pass, seeConfigFilters.FileState
for more info- Returns:
- a filter that converts a string to a
Path
-