OptionType
public final class OptionType< T>- Inheritance
ObjectOptionType
Represents a type of an option that allows to convert string values to Java values.
Constructors4
OptionType(String, Function<String, T>, Consumer<T>)
OptionType
since 19.0Constructs a new option type with name and function that allows to convert a string to the option type and validator of the option values.
Parameters
nameString- the name of the type.
stringConverterFunction<String, T> - a function that converts a string value to the option value. Can throw
IllegalArgumentExceptionto indicate an invalid string. validatorConsumer<T> - used for validating the option value. Throws
IllegalArgumentExceptionif the value is invalid.
OptionType(String, Function<String, T>)
OptionType
since 19.0Constructs a new option type with name and function that allows to convert a string to the option type.
Parameters
nameString- the name of the type.
stringConverterFunction<String, T> - a function that converts a string value to the option value. Can throw
IllegalArgumentExceptionto indicate an invalid string.
OptionType(String, T, Function<String, T>, Consumer<T>)No description.deprecated
OptionType
since 19.0@Deprecated(since = "19.0")
public OptionType(
String name,
T defaultValue,
Function< String, T> stringConverter,
Consumer< T> validator
)Deprecated since 19.0
No description.
OptionType(String, T, Function<String, T>)No description.deprecated
OptionType
since 19.0@Deprecated(since = "19.0")
public OptionType(String name, T defaultValue, Function< String, T> stringConverter)Deprecated since 19.0
No description.
Methods8
T getDefaultValue()No description.deprecated
getDefaultValue
since 19.0@Deprecated(since = "19.0")
public T getDefaultValue()Deprecated since 19.0
No description.
Returns
T- No description.
String getName()
T convert(String)
convert
since 19.0public T convert(String value)Converts a string value, validates it, and converts it to an object of this type.
Parameters
valueString- No description.
Returns
T- No description.
Throws
IllegalArgumentExceptionunchecked- if the value is invalid or cannot be converted.
T convert(Object, String, String)
convert
since 19.2Converts a string value, validates it, and converts it to an object of this type. For option maps includes the previous map stored for the option and the key.
Parameters
Returns
T- No description.
Throws
IllegalArgumentExceptionunchecked- if the value is invalid or cannot be converted.
void validate(T)
validate
since 19.0public void validate(T value)Validates an option value and throws an IllegalArgumentException if the value is invalid.
Parameters
valueT- No description.
Throws
IllegalArgumentExceptionunchecked- if the value is invalid or cannot be converted.
String toString()Described in toString().
static OptionType<T> defaultType(T)
defaultType
staticsince 19.0public static < T> OptionType< T> defaultType(T value)Returns the default option type for a given value. Returns null if no default option type is available for the Java type of this value.
Parameters
valueT- No description.
Returns
OptionType<T> - No description.
static OptionType<T> defaultType(Class<T>)
defaultType
staticsince 19.0public static < T> OptionType< T> defaultType(Class< T> clazz)Returns the default option type for a class. Returns null if no default option type is available for this Java type.
Parameters
clazzClass<T> - No description.
Returns
OptionType<T> - No description.