public class OptionValue<T> extends Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
OptionValue.MultipleOverridesScope |
static class |
OptionValue.OverrideScope
An object whose
OptionValue.OverrideScope.close() method reverts the option value overriding initiated by
override(OptionValue, Object) or override(Map) . |
(package private) static class |
OptionValue.SingleOverrideScope |
Modifier and Type | Field and Description |
---|---|
private static Object |
DEFAULT |
private T |
defaultValue |
private OptionDescriptor |
descriptor |
private static OptionValue<?> |
head |
private OptionValue<?> |
next |
private static ThreadLocal<OptionValue.OverrideScope> |
overrideScopeTL |
private long |
reads |
private static boolean |
ShowReadsHistogram |
private static Object |
UNINITIALIZED |
protected T |
value
The raw option value.
|
Modifier | Constructor and Description |
---|---|
protected |
OptionValue()
Creates an uninitialized option value for a subclass that initializes itself
lazily . |
|
OptionValue(T value) |
Modifier and Type | Method and Description |
---|---|
private static void |
addToHistogram(OptionValue<?> option) |
protected T |
defaultValue()
Lazy initialization of default value.
|
T |
getDefaultValue()
The initial value specified in source code.
|
OptionDescriptor |
getDescriptor()
Returns the descriptor for this option, if it has been set by
setDescriptor(OptionDescriptor) . |
String |
getName()
Gets the name of this option.
|
protected static OptionValue.OverrideScope |
getOverrideScope() |
T |
getValue()
Gets the value of this option.
|
Collection<T> |
getValues(Collection<T> c)
Gets the values of this option including overridden values.
|
boolean |
hasDefaultValue()
Returns true if the option has the same value that was set in the source code.
|
static OptionValue.OverrideScope |
override(Map<OptionValue<?>,Object> overrides)
Temporarily changes the values for a set of options.
|
static OptionValue.OverrideScope |
override(Object... overrides)
Temporarily changes the values for a set of options.
|
static OptionValue.OverrideScope |
override(OptionValue<?> option,
Object value)
Temporarily changes the value for an option.
|
void |
setDescriptor(OptionDescriptor descriptor)
Sets the descriptor for this option.
|
protected static void |
setOverrideScope(OptionValue.OverrideScope overrideScope) |
void |
setValue(Object v)
Sets the value of this option.
|
String |
toString() |
private static final ThreadLocal<OptionValue.OverrideScope> overrideScopeTL
private T defaultValue
private OptionDescriptor descriptor
private long reads
private OptionValue<?> next
private static OptionValue<?> head
private static final boolean ShowReadsHistogram
private static final Object UNINITIALIZED
public OptionValue(T value)
protected OptionValue()
lazily
.public static OptionValue.OverrideScope override(OptionValue<?> option, Object value)
option
is set to value
until OptionValue.OverrideScope.close()
is called on the
object returned by this method.
Since the returned object is AutoCloseable
the try-with-resource construct can be
used:
try (OverrideScope s = OptionValue.override(myOption, myValue) { // code that depends on myOption == myValue }
public static OptionValue.OverrideScope override(Map<OptionValue<?>,Object> overrides)
option
in overrides
is set to the corresponding value
in overrides
until OptionValue.OverrideScope.close()
is called on the object returned by
this method.
Since the returned object is AutoCloseable
the try-with-resource construct can be
used:
Map<OptionValue, Object> overrides = new HashMap<>(); overrides.put(myOption1, myValue1); overrides.put(myOption2, myValue2); try (OverrideScope s = OptionValue.override(overrides) { // code that depends on myOption == myValue }
public static OptionValue.OverrideScope override(Object... overrides)
option
in overrides
is set to the corresponding value
in overrides
until OptionValue.OverrideScope.close()
is called on the object returned by
this method.
Since the returned object is AutoCloseable
the try-with-resource construct can be
used:
try (OverrideScope s = OptionValue.override(myOption1, myValue1, myOption2, myValue2) { // code that depends on myOption == myValue }
overrides
- overrides in the form [option1, override1, option2, override2, ...]
protected static OptionValue.OverrideScope getOverrideScope()
protected static void setOverrideScope(OptionValue.OverrideScope overrideScope)
private static void addToHistogram(OptionValue<?> option)
protected T defaultValue()
public void setDescriptor(OptionDescriptor descriptor)
public OptionDescriptor getDescriptor()
setDescriptor(OptionDescriptor)
.public String getName()
Object.toString()
.public T getDefaultValue()
setValue(Object)
or registering OptionValue.OverrideScope
s. Therefore, it is also not
affected by options set on the command line.public boolean hasDefaultValue()
public Collection<T> getValues(Collection<T> c)
c
- the collection to which the values are added. If null, one is allocated.