Top Description Inners Fields Constructors Methods
org.graalvm.options

public final Class OptionType<T>

extends Object
Class Inheritance
Imports
java.util.HashMap, .Map, .Objects, java.util.function.Consumer, .Function

Represents a type of an option that allows to convert string values to Java values.
Since
19.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface

Field Summary

Modifier and TypeField and Description
private final OptionType.Converter<T>
private static final Map<Class<?>, OptionType<?>>
private static final Consumer<?>
private final boolean
private final boolean
private final String
private final Consumer<T>

Constructor Summary

AccessConstructor and Description
public
OptionType(String
the name of the type.
name
,
Function<String, T>
a function that converts a string value to the option value. Can throw IllegalArgumentException to indicate an invalid string.
stringConverter
,
Consumer<T>
used for validating the option value. Throws IllegalArgumentException if the value is invalid.
validator
)

Constructs a new option type with name and function that allows to convert a string to the option type and validator of the option values.

private
OptionType(String name, OptionType.Converter<T> converter, Consumer<T> validator, boolean isOptionMap, boolean isDefaultType)

private
OptionType(String name, Function<String, T> stringConverter, boolean isDefaultType)

public
OptionType(String
the name of the type.
name
,
Function<String, T>
a function that converts a string value to the option value. Can throw IllegalArgumentException to indicate an invalid string.
stringConverter
)

Constructs a new option type with name and function that allows to convert a string to the option type.

public
OptionType(String name, T defaultValue, Function<String, T> stringConverter, Consumer<T> validator)
Deprecated since 19.0. Use OptionType(String, Function, Consumer)

public
OptionType(String name, T defaultValue, Function<String, T> stringConverter)
Deprecated since 19.0. Use OptionType(String, Function)

Method Summary

Modifier and TypeMethod and Description
public T
convert(String value)

Converts a string value, validates it, and converts it to an object of this type.

public T
convert(Object
the previous value holded by option.
previousValue
,
String
the key for prefix options.
nameSuffix
,
String value)

Converts a string value, validates it, and converts it to an object of this type.

private static <T> OptionType<T>
public static <T> OptionType<T>
defaultType(T value)

Returns the default option type for a given value.

public static <T> OptionType<T>
defaultType(Class<T> clazz)

Returns the default option type for a class.

public T
getDefaultValue()
Deprecated since 19.0.

public String
getName()

Returns the name of this type.

pack-priv boolean
pack-priv boolean
pack-priv static <V> OptionType<OptionMap<V>>
mapOf(Class<V> valueClass)

Returns the default option type for option maps for the given value class.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
validate(T value)

Validates an option value and throws an IllegalArgumentException if the value is invalid.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

converterback to summary
private final OptionType.Converter<T> converter
DEFAULTTYPESback to summary
private static final Map<Class<?>, OptionType<?>> DEFAULTTYPES
EMPTY_VALIDATORback to summary
private static final Consumer<?> EMPTY_VALIDATOR
isDefaultTypeback to summary
private final boolean isDefaultType
isOptionMapback to summary
private final boolean isOptionMap
nameback to summary
private final String name
validatorback to summary
private final Consumer<T> validator

Constructor Detail

OptionTypeback to summary
public OptionType(String name, Function<String, T> stringConverter, Consumer<T> validator)

Constructs 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
name:String

the name of the type.

stringConverter:Function<String, T>

a function that converts a string value to the option value. Can throw IllegalArgumentException to indicate an invalid string.

validator:Consumer<T>

used for validating the option value. Throws IllegalArgumentException if the value is invalid.

Since
19.0
OptionTypeback to summary
private OptionType(String name, OptionType.Converter<T> converter, Consumer<T> validator, boolean isOptionMap, boolean isDefaultType)
OptionTypeback to summary
private OptionType(String name, Function<String, T> stringConverter, boolean isDefaultType)
Annotations
@SuppressWarnings:unchecked
OptionTypeback to summary
public OptionType(String name, Function<String, T> stringConverter)

Constructs a new option type with name and function that allows to convert a string to the option type.

Parameters
name:String

the name of the type.

stringConverter:Function<String, T>

a function that converts a string value to the option value. Can throw IllegalArgumentException to indicate an invalid string.

Annotations
@SuppressWarnings:unchecked
Since
19.0
OptionTypeback to summary
public OptionType(String name, T defaultValue, Function<String, T> stringConverter, Consumer<T> validator)

Deprecated

since 19.0.

Use OptionType(String, Function, Consumer)

Annotations
@Deprecated
since:19.0
@SuppressWarnings:unused
Since
19.0
OptionTypeback to summary
public OptionType(String name, T defaultValue, Function<String, T> stringConverter)

Deprecated

since 19.0.

Use OptionType(String, Function)

Annotations
@Deprecated
since:19.0
@SuppressWarnings:unused
Since
19.0

Method Detail

convertback to summary
public T convert(String value)

Converts a string value, validates it, and converts it to an object of this type.

Exceptions
IllegalArgumentException:
if the value is invalid or cannot be converted.
Since
19.0
convertback to summary
public T convert(Object previousValue, String nameSuffix, String value)

Converts 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
previousValue:Object

the previous value holded by option.

nameSuffix:String

the key for prefix options.

Annotations
@SuppressWarnings:unchecked
Exceptions
IllegalArgumentException:
if the value is invalid or cannot be converted.
Since
19.2
defaultEnumTypeback to summary
private static <T> OptionType<T> defaultEnumType(Class<T> clazz)
Annotations
@SuppressWarnings:unchecked
defaultTypeback to summary
public 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.

Annotations
@SuppressWarnings:unchecked
Since
19.0
defaultTypeback to summary
public 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.

Annotations
@SuppressWarnings:unchecked
Since
19.0
getDefaultValueback to summary
public T getDefaultValue()

Deprecated

since 19.0.

Annotations
@Deprecated
since:19.0
Since
19.0
getNameback to summary
public String getName()

Returns the name of this type.

Since
19.0
isDefaultTypeback to summary
pack-priv boolean isDefaultType()
isOptionMapback to summary
pack-priv boolean isOptionMap()
mapOfback to summary
pack-priv static <V> OptionType<OptionMap<V>> mapOf(Class<V> valueClass)

Returns the default option type for option maps for the given value class. Returns null if no default option type is available for the value class.

Annotations
@SuppressWarnings:unchecked
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
Since
19.0
validateback to summary
public void validate(T value)

Validates an option value and throws an IllegalArgumentException if the value is invalid.

Exceptions
IllegalArgumentException:
if the value is invalid or cannot be converted.
Since
19.0
org.graalvm.options back to summary

private Interface OptionType.Converter<T>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public T
convert(T previousValue, String key, String value)

Method Detail

convertback to summary
public T convert(T previousValue, String key, String value)