| Modifier and Type | Field and Description |
|---|---|
| private final T | |
| private final OptionType |
| Access | Constructor and Description |
|---|---|
| public | |
| public | OptionKey(T defaultValue, OptionType<T> type)
Constructs a new option key given a default value and option key. |
| Modifier and Type | Method and Description |
|---|---|
| public T | |
| public OptionType | |
| public T | |
| public boolean | hasBeenSet(OptionValues values)
Returns |
| public static <V> OptionKey |
| defaultValue | back to summary |
|---|---|
| private final T defaultValue | |
| type | back to summary |
|---|---|
| private final OptionType<T> type | |
| OptionKey | back to summary |
|---|---|
| public OptionKey(T defaultValue) Constructs a new option key given a default value. Throws
| |
| OptionKey | back to summary |
|---|---|
| public OptionKey(T defaultValue, OptionType<T> type) Constructs a new option key given a default value and option key.
| |
| getDefaultValue | back to summary |
|---|---|
| public T getDefaultValue() Returns the default value for this option.
| |
| getType | back to summary |
|---|---|
| public OptionType Returns the option type of this key.
| |
| getValue | back to summary |
|---|---|
| public T getValue(OptionValues values) Returns the value of this key given the
| |
| hasBeenSet | back to summary |
|---|---|
| public boolean hasBeenSet(OptionValues values) Returns
| |
| mapOf | back to summary |
|---|---|
| public static <V> OptionKey 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
@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.
| |