final class ArrayFieldSetter extends java.lang.Object implements Getter, Setter
Setter
that allows multiple values to be stored into one array field.
Because of the CmdLineParser
abstractions of allowing incremental parsing of options,
this implementation creates a whole new array each time a new value is found.
This is also why we don't support a setter method that takes list/array as arguments.
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
bean |
private java.lang.Object |
defaultArray |
private java.lang.reflect.Field |
f |
Constructor and Description |
---|
ArrayFieldSetter(java.lang.Object bean,
java.lang.reflect.Field f) |
Modifier and Type | Method and Description |
---|---|
void |
addValue(java.lang.Object value)
Adds/sets a value to the property of the option bean.
|
java.lang.reflect.AnnotatedElement |
asAnnotatedElement()
Returns the
AnnotatedElement by which you can access annotations written on this setter. |
FieldSetter |
asFieldSetter()
If this setter encapsulates a field, return the direct access to that field as
FieldSetter . |
private void |
doAddValue(java.lang.Object bean,
java.lang.Object value) |
private void |
doSetDefault(java.lang.Object bean) |
java.lang.Class |
getType()
Gets the type of the underlying method/field.
|
java.util.List<java.lang.Object> |
getValueList()
Gets the current value of the property.
|
boolean |
isMultiValued()
Whether this setter is intrinsically multi-valued.
|
private void |
trySetDefault(java.lang.Object bean1)
Remember default so we throw away the default when adding user values.
|
private final java.lang.Object bean
private final java.lang.reflect.Field f
private java.lang.Object defaultArray
public ArrayFieldSetter(java.lang.Object bean, java.lang.reflect.Field f)
private void trySetDefault(java.lang.Object bean1) throws java.lang.IllegalAccessError
java.lang.IllegalAccessError
private void doSetDefault(java.lang.Object bean) throws java.lang.IllegalAccessException
java.lang.IllegalAccessException
public FieldSetter asFieldSetter()
Setter
FieldSetter
. This method serves two purposes:
OptionHandler
s bypass the collection/array handling of fields.
This is useful if you're defining an option handler that produces array or collection
from a single argument.FieldSetter.getValueList()
).asFieldSetter
in interface Setter
null
if this setter wraps a method.public java.lang.reflect.AnnotatedElement asAnnotatedElement()
Setter
AnnotatedElement
by which you can access annotations written on this setter.
This is the same AnnotatedElement
that had Option
/Argument
.
This enables OptionHandler
to further tweak its behavior based on additional annotations.
asAnnotatedElement
in interface Setter
public boolean isMultiValued()
Setter
When parsing arguments (instead of options), intrinsically multi-valued setters consume
all the remaining arguments. So, if the setter can store multiple values,
this method should return true
.
This characteristics of a setter doesn't affect option parsing at all; any options can be specified multiple times. In many cases, this is a no-op--but when your shell script expands multiple environment variables (each of which may contain options), tolerating such redundant options can be useful.
isMultiValued
in interface Setter
public java.lang.Class getType()
Setter
public void addValue(java.lang.Object value)
Setter
A Setter
object has an implicit knowledge about the property it's setting,
and the instance of the option bean.
private void doAddValue(java.lang.Object bean, java.lang.Object value) throws java.lang.IllegalAccessException
java.lang.IllegalAccessException
public java.util.List<java.lang.Object> getValueList()
Getter
A Getter
object has an implicit knowledge about the property it's getting,
and the instance of the option bean.
getValueList
in interface Getter