Top Description Fields Constructors Methods
org.graalvm.options

public final Class OptionKey<T>

extends Object
Class Inheritance
Imports
java.util.Objects

Represents the option key for an option specification.
Since
19.0

Field Summary

Modifier and TypeField and Description
private final T
private final OptionType<T>

Constructor Summary

AccessConstructor and Description
public
OptionKey(T defaultValue)

Constructs a new option key given a default value.

public
OptionKey(T defaultValue, OptionType<T> type)

Constructs a new option key given a default value and option key.

Method Summary

Modifier and TypeMethod and Description
public T
getDefaultValue()

Returns the default value for this option.

public OptionType<T>
getType()

Returns the option type of this key.

public T
getValue(OptionValues values)

Returns the value of this key given the values.

public boolean
hasBeenSet(OptionValues values)

Returns true if a value for this key has been set for the given option values or false if no value has been set.

public static <V> OptionKey<OptionMap<V>>
mapOf(Class<V> valueClass)

Constructs a new option key to group/accumulate options with common prefixes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultValueback to summary
private final T defaultValue
typeback to summary
private final OptionType<T> type

Constructor Detail

OptionKeyback to summary
public OptionKey(T defaultValue)

Constructs a new option key given a default value. Throws IllegalArgumentException if no default OptionType could be resolved for the given type. The default value must not be null.

Since
19.0
OptionKeyback to summary
public OptionKey(T defaultValue, OptionType<T> type)

Constructs a new option key given a default value and option key.

Since
19.0

Method Detail

getDefaultValueback to summary
public T getDefaultValue()

Returns the default value for this option.

Since
19.0
getTypeback to summary
public OptionType<T> getType()

Returns the option type of this key.

Since
19.0
getValueback to summary
public T getValue(OptionValues values)

Returns the value of this key given the values.

Since
19.0
hasBeenSetback to summary
public boolean hasBeenSet(OptionValues values)

Returns true if a value for this key has been set for the given option values or false if no value has been set.

Since
19.0
mapOfback to summary
public static <V> OptionKey<OptionMap<V>> mapOf(Class<V> valueClass)

Constructs a new option key to group/accumulate options with common prefixes. This type of options allow to collect key=value pairs whose keys are unknown beforehand e.g. user defined properties. See OptionMap. Example usage:

@Option.Group("mylang")
public class MiscOptions {
    @Option(help = "User-defined properties", category = OptionCategory.USER) //
    public static final OptionKey<OptionMap<String>> Properties = OptionKey.mapOf(String.class);

    ...
}
Properties can be set using the mylang.Properties prefix.
Context context = Context.newBuilder() //
                .option("mylang.Properties.key", "value") //
                .option("mylang.Properties.user.name", "guest") //
                .build();
The option map can be consumed as follows:
OptionMap<String> properties = getOptions().get(MiscOptions.Properties);
properties.get("key");       // value
properties.get("user.name"); // guest
properties.get("undefined"); // null
Throws IllegalArgumentException if no default OptionType could be resolved for the value type.
Since
19.2