Package io.smallrye.config
Class Converters
- java.lang.Object
-
- io.smallrye.config.Converters
-
public final class Converters extends Object
General converter utilities and constants.- Author:
- Jeff Mesnil (c) 2017 Red Hat inc.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static TypegetConverterType(Class<?> clazz)Get the type of the converter specified byclazz.static <T> org.eclipse.microprofile.config.spi.Converter<T>getImplicitConverter(Class<? extends T> type)Get the implicit converter for the given type class, if any.static <T> org.eclipse.microprofile.config.spi.Converter<T>maximumValueConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T maximumValue, boolean inclusive)Get a wrapping converter which verifies that the configuration value is less than, or optionally equal to, the given maximum value.static <T extends Comparable<T>>
org.eclipse.microprofile.config.spi.Converter<T>maximumValueConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T maximumValue, boolean inclusive)Get a wrapping converter which verifies that the configuration value is less than, or optionally equal to, the given maximum value.static <T> org.eclipse.microprofile.config.spi.Converter<T>maximumValueStringConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String maximumValue, boolean inclusive)Get a wrapping converter which verifies that the configuration value is less than, or optionally equal to, the given maximum value (in string form).static <T extends Comparable<T>>
org.eclipse.microprofile.config.spi.Converter<T>maximumValueStringConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String maximumValue, boolean inclusive)Get a wrapping converter which verifies that the configuration value is less than, or optionally equal to, the given maximum value (in string form).static <T> org.eclipse.microprofile.config.spi.Converter<T>minimumValueConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T minimumValue, boolean inclusive)Get a wrapping converter which verifies that the configuration value is greater than, or optionally equal to, the given minimum value.static <T extends Comparable<T>>
org.eclipse.microprofile.config.spi.Converter<T>minimumValueConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T minimumValue, boolean inclusive)Get a wrapping converter which verifies that the configuration value is greater than, or optionally equal to, the given minimum value.static <T> org.eclipse.microprofile.config.spi.Converter<T>minimumValueStringConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String minimumValue, boolean inclusive)Get a wrapping converter which verifies that the configuration value is greater than, or optionally equal to, the given minimum value (in string form).static <T extends Comparable<T>>
org.eclipse.microprofile.config.spi.Converter<T>minimumValueStringConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String minimumValue, boolean inclusive)Get a wrapping converter which verifies that the configuration value is greater than, or optionally equal to, the given minimum value (in string form).static <A,T>
org.eclipse.microprofile.config.spi.Converter<A>newArrayConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> itemConverter, Class<A> arrayType)Get a converter that converts a comma-separated string into an array of converted items.static <T,C extends Collection<T>>
org.eclipse.microprofile.config.spi.Converter<C>newCollectionConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> itemConverter, IntFunction<C> collectionFactory)Get a converter that converts a comma-separated string into a list of converted items.static <T> org.eclipse.microprofile.config.spi.Converter<T>newEmptyValueConverter(org.eclipse.microprofile.config.spi.Converter<T> delegateConverter)Get a converter which wraps another converter and handles empty values correctly.static <T> org.eclipse.microprofile.config.spi.Converter<T>newEmptyValueConverter(org.eclipse.microprofile.config.spi.Converter<T> delegateConverter, T emptyValue)Get a converter which wraps another converter and returns a special value to represent empty.static <K,V>
org.eclipse.microprofile.config.spi.Converter<Map<K,V>>newMapConverter(org.eclipse.microprofile.config.spi.Converter<? extends K> keyConverter, org.eclipse.microprofile.config.spi.Converter<? extends V> valueConverter)Get a converter that converts content of type<key1>=<value1>;<key2>=<value2>...into aMap<K, V>using the given key and value converters.static <T> org.eclipse.microprofile.config.spi.Converter<Optional<T>>newOptionalConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegateConverter)Get a converter which wraps another converter's result into anOptional.static org.eclipse.microprofile.config.spi.Converter<OptionalDouble>newOptionalDoubleConverter(org.eclipse.microprofile.config.spi.Converter<Double> delegateConverter)Get a converter which wraps another converter's result into anOptionalDouble.static org.eclipse.microprofile.config.spi.Converter<OptionalInt>newOptionalIntConverter(org.eclipse.microprofile.config.spi.Converter<Integer> delegateConverter)Get a converter which wraps another converter's result into anOptionalInt.static org.eclipse.microprofile.config.spi.Converter<OptionalLong>newOptionalLongConverter(org.eclipse.microprofile.config.spi.Converter<Long> delegateConverter)Get a converter which wraps another converter's result into anOptionalLong.static <T> org.eclipse.microprofile.config.spi.Converter<T>newTrimmingConverter(org.eclipse.microprofile.config.spi.Converter<T> delegateConverter)Get a converter which trims the string input before passing it on to the delegate converter.static <T> org.eclipse.microprofile.config.spi.Converter<T>patternValidatingConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String pattern)Get a wrapping converter which verifies that the configuration value matches the given pattern.static <T> org.eclipse.microprofile.config.spi.Converter<T>patternValidatingConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, Pattern pattern)Get a wrapping converter which verifies that the configuration value matches the given pattern.static <T> org.eclipse.microprofile.config.spi.Converter<T>rangeValueConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T minimumValue, boolean minInclusive, T maximumValue, boolean maxInclusive)Get a wrapping converter which verifies that the configuration value is within the given range.static <T extends Comparable<T>>
org.eclipse.microprofile.config.spi.Converter<T>rangeValueConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T minimumValue, boolean minInclusive, T maximumValue, boolean maxInclusive)Get a wrapping converter which verifies that the configuration value is within the given range.static <T> org.eclipse.microprofile.config.spi.Converter<T>rangeValueStringConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String minimumValue, boolean minInclusive, String maximumValue, boolean maxInclusive)Get a wrapping converter which verifies that the configuration value is within the given range (in string form).static <T extends Comparable<T>>
org.eclipse.microprofile.config.spi.Converter<T>rangeValueStringConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String minimumValue, boolean minInclusive, String maximumValue, boolean maxInclusive)Get a wrapping converter which verifies that the configuration value is within the given range (in string form).
-
-
-
Method Detail
-
getConverterType
public static Type getConverterType(Class<?> clazz)
Get the type of the converter specified byclazz. If the given class is not a valid converter, thennullis returned.- Parameters:
clazz- the converter class (must not benull)- Returns:
- the converter target type, or
nullif the class does not represent a valid configuration - Throws:
IllegalStateException- if the given converter class is not properly parameterized
-
getImplicitConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> getImplicitConverter(Class<? extends T> type)
Get the implicit converter for the given type class, if any.- Type Parameters:
T- the type- Parameters:
type- the type class- Returns:
- the implicit converter for the given type class, or
nullif none exists
-
newCollectionConverter
public static <T,C extends Collection<T>> org.eclipse.microprofile.config.spi.Converter<C> newCollectionConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> itemConverter, IntFunction<C> collectionFactory)
Get a converter that converts a comma-separated string into a list of converted items.- Type Parameters:
T- the item typeC- the collection type- Parameters:
itemConverter- the item converter (must not benull)collectionFactory- the collection factory (must not benull)- Returns:
- the new converter (not
null)
-
newArrayConverter
public static <A,T> org.eclipse.microprofile.config.spi.Converter<A> newArrayConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> itemConverter, Class<A> arrayType)Get a converter that converts a comma-separated string into an array of converted items.- Type Parameters:
T- the item typeA- the array type- Parameters:
itemConverter- the item converter (must not benull)arrayType- the array type class (must not benull)- Returns:
- the new converter (not
null)
-
newMapConverter
public static <K,V> org.eclipse.microprofile.config.spi.Converter<Map<K,V>> newMapConverter(org.eclipse.microprofile.config.spi.Converter<? extends K> keyConverter, org.eclipse.microprofile.config.spi.Converter<? extends V> valueConverter)
Get a converter that converts content of type<key1>=<value1>;<key2>=<value2>...into aMap<K, V>using the given key and value converters.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
keyConverter- the converter used to convert the keysvalueConverter- the converter used to convert the values- Returns:
- the new converter (not
null)
-
newOptionalConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<Optional<T>> newOptionalConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegateConverter)
Get a converter which wraps another converter's result into anOptional. If the delegate converter returnsnull, this converter returnsOptional.empty().- Type Parameters:
T- the item type- Parameters:
delegateConverter- the delegate converter (must not benull)- Returns:
- the new converter (not
null)
-
newOptionalIntConverter
public static org.eclipse.microprofile.config.spi.Converter<OptionalInt> newOptionalIntConverter(org.eclipse.microprofile.config.spi.Converter<Integer> delegateConverter)
Get a converter which wraps another converter's result into anOptionalInt. If the delegate converter returnsnull, this converter returnsOptional.empty().- Parameters:
delegateConverter- the delegate converter (must not benull)- Returns:
- the new converter (not
null)
-
newOptionalLongConverter
public static org.eclipse.microprofile.config.spi.Converter<OptionalLong> newOptionalLongConverter(org.eclipse.microprofile.config.spi.Converter<Long> delegateConverter)
Get a converter which wraps another converter's result into anOptionalLong. If the delegate converter returnsnull, this converter returnsOptional.empty().- Parameters:
delegateConverter- the delegate converter (must not benull)- Returns:
- the new converter (not
null)
-
newOptionalDoubleConverter
public static org.eclipse.microprofile.config.spi.Converter<OptionalDouble> newOptionalDoubleConverter(org.eclipse.microprofile.config.spi.Converter<Double> delegateConverter)
Get a converter which wraps another converter's result into anOptionalDouble. If the delegate converter returnsnull, this converter returnsOptional.empty().- Parameters:
delegateConverter- the delegate converter (must not benull)- Returns:
- the new converter (not
null)
-
newEmptyValueConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> newEmptyValueConverter(org.eclipse.microprofile.config.spi.Converter<T> delegateConverter, T emptyValue)Get a converter which wraps another converter and returns a special value to represent empty.- Type Parameters:
T- the value type- Parameters:
delegateConverter- the converter to delegate to (must not benull)emptyValue- the empty value to return- Returns:
- the converter
-
newEmptyValueConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> newEmptyValueConverter(org.eclipse.microprofile.config.spi.Converter<T> delegateConverter)
Get a converter which wraps another converter and handles empty values correctly. This allows the delegate converter to assume that the value being converted will not benullor empty.- Type Parameters:
T- the value type- Parameters:
delegateConverter- the converter to delegate to (must not benull)- Returns:
- the converter
-
newTrimmingConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> newTrimmingConverter(org.eclipse.microprofile.config.spi.Converter<T> delegateConverter)
Get a converter which trims the string input before passing it on to the delegate converter.- Type Parameters:
T- the value type- Parameters:
delegateConverter- the converter to delegate to (must not benull)- Returns:
- the converter
-
minimumValueConverter
public static <T extends Comparable<T>> org.eclipse.microprofile.config.spi.Converter<T> minimumValueConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T minimumValue, boolean inclusive)
Get a wrapping converter which verifies that the configuration value is greater than, or optionally equal to, the given minimum value.- Type Parameters:
T- the converter target type- Parameters:
delegate- the delegate converter (must not benull)minimumValue- the minimum value (must not benull)inclusive-trueif the minimum value is inclusive,falseotherwise- Returns:
- a range-validating converter
-
minimumValueConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> minimumValueConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T minimumValue, boolean inclusive)
Get a wrapping converter which verifies that the configuration value is greater than, or optionally equal to, the given minimum value.- Type Parameters:
T- the converter target type- Parameters:
comparator- the comparator to use (must not benull)delegate- the delegate converter (must not benull)minimumValue- the minimum value (must not benull)inclusive-trueif the minimum value is inclusive,falseotherwise- Returns:
- a range-validating converter
-
minimumValueStringConverter
public static <T extends Comparable<T>> org.eclipse.microprofile.config.spi.Converter<T> minimumValueStringConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String minimumValue, boolean inclusive)
Get a wrapping converter which verifies that the configuration value is greater than, or optionally equal to, the given minimum value (in string form).- Type Parameters:
T- the converter target type- Parameters:
delegate- the delegate converter (must not benull)minimumValue- the minimum value (must not benull)inclusive-trueif the minimum value is inclusive,falseotherwise- Returns:
- a range-validating converter
- Throws:
IllegalArgumentException- if the given minimum value fails conversion
-
minimumValueStringConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> minimumValueStringConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String minimumValue, boolean inclusive)
Get a wrapping converter which verifies that the configuration value is greater than, or optionally equal to, the given minimum value (in string form).- Type Parameters:
T- the converter target type- Parameters:
comparator- the comparator to use (must not benull)delegate- the delegate converter (must not benull)minimumValue- the minimum value (must not benull)inclusive-trueif the minimum value is inclusive,falseotherwise- Returns:
- a range-validating converter
- Throws:
IllegalArgumentException- if the given minimum value fails conversion
-
maximumValueConverter
public static <T extends Comparable<T>> org.eclipse.microprofile.config.spi.Converter<T> maximumValueConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T maximumValue, boolean inclusive)
Get a wrapping converter which verifies that the configuration value is less than, or optionally equal to, the given maximum value.- Type Parameters:
T- the converter target type- Parameters:
delegate- the delegate converter (must not benull)maximumValue- the maximum value (must not benull)inclusive-trueif the maximum value is inclusive,falseotherwise- Returns:
- a range-validating converter
-
maximumValueConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> maximumValueConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T maximumValue, boolean inclusive)
Get a wrapping converter which verifies that the configuration value is less than, or optionally equal to, the given maximum value.- Type Parameters:
T- the converter target type- Parameters:
comparator- the comparator to use (must not benull)delegate- the delegate converter (must not benull)maximumValue- the maximum value (must not benull)inclusive-trueif the maximum value is inclusive,falseotherwise- Returns:
- a range-validating converter
-
maximumValueStringConverter
public static <T extends Comparable<T>> org.eclipse.microprofile.config.spi.Converter<T> maximumValueStringConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String maximumValue, boolean inclusive)
Get a wrapping converter which verifies that the configuration value is less than, or optionally equal to, the given maximum value (in string form).- Type Parameters:
T- the converter target type- Parameters:
delegate- the delegate converter (must not benull)maximumValue- the maximum value (must not benull)inclusive-trueif the maximum value is inclusive,falseotherwise- Returns:
- a range-validating converter
- Throws:
IllegalArgumentException- if the given maximum value fails conversion
-
maximumValueStringConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> maximumValueStringConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String maximumValue, boolean inclusive)
Get a wrapping converter which verifies that the configuration value is less than, or optionally equal to, the given maximum value (in string form).- Type Parameters:
T- the converter target type- Parameters:
comparator- the comparator to use (must not benull)delegate- the delegate converter (must not benull)maximumValue- the maximum value (must not benull)inclusive-trueif the maximum value is inclusive,falseotherwise- Returns:
- a range-validating converter
- Throws:
IllegalArgumentException- if the given maximum value fails conversion
-
rangeValueConverter
public static <T extends Comparable<T>> org.eclipse.microprofile.config.spi.Converter<T> rangeValueConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T minimumValue, boolean minInclusive, T maximumValue, boolean maxInclusive)
Get a wrapping converter which verifies that the configuration value is within the given range.- Type Parameters:
T- the converter target type- Parameters:
delegate- the delegate converter (must not benull)maximumValue- the maximum value (must not benull)maxInclusive-trueif the maximum value is inclusive,falseotherwise- Returns:
- a range-validating converter
-
rangeValueConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> rangeValueConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, T minimumValue, boolean minInclusive, T maximumValue, boolean maxInclusive)
Get a wrapping converter which verifies that the configuration value is within the given range.- Type Parameters:
T- the converter target type- Parameters:
comparator- the comparator to use (must not benull)delegate- the delegate converter (must not benull)maximumValue- the maximum value (must not benull)maxInclusive-trueif the maximum value is inclusive,falseotherwise- Returns:
- a range-validating converter
-
rangeValueStringConverter
public static <T extends Comparable<T>> org.eclipse.microprofile.config.spi.Converter<T> rangeValueStringConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String minimumValue, boolean minInclusive, String maximumValue, boolean maxInclusive)
Get a wrapping converter which verifies that the configuration value is within the given range (in string form).- Type Parameters:
T- the converter target type- Parameters:
delegate- the delegate converter (must not benull)maximumValue- the maximum value (must not benull)maxInclusive-trueif the maximum value is inclusive,falseotherwise- Returns:
- a range-validating converter
- Throws:
IllegalArgumentException- if the given minimum or maximum value fails conversion
-
rangeValueStringConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> rangeValueStringConverter(Comparator<? super T> comparator, org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String minimumValue, boolean minInclusive, String maximumValue, boolean maxInclusive)
Get a wrapping converter which verifies that the configuration value is within the given range (in string form).- Type Parameters:
T- the converter target type- Parameters:
comparator- the comparator to use (must not benull)delegate- the delegate converter (must not benull)maximumValue- the maximum value (must not benull)maxInclusive-trueif the maximum value is inclusive,falseotherwise- Returns:
- a range-validating converter
- Throws:
IllegalArgumentException- if the given minimum or maximum value fails conversion
-
patternValidatingConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> patternValidatingConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, Pattern pattern)Get a wrapping converter which verifies that the configuration value matches the given pattern.- Type Parameters:
T- the converter target type- Parameters:
delegate- the delegate converter (must not benull)pattern- the pattern to match (must not benull)- Returns:
- a pattern-validating converter
-
patternValidatingConverter
public static <T> org.eclipse.microprofile.config.spi.Converter<T> patternValidatingConverter(org.eclipse.microprofile.config.spi.Converter<? extends T> delegate, String pattern)Get a wrapping converter which verifies that the configuration value matches the given pattern.- Type Parameters:
T- the converter target type- Parameters:
delegate- the delegate converter (must not benull)pattern- the pattern string to match (must not benull)- Returns:
- a pattern-validating converter
- Throws:
PatternSyntaxException- if the given pattern has invalid syntax
-
-