Class ArrayFieldSetter
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds/sets a value to the property of the option bean.Returns theAnnotatedElement
by which you can access annotations written on this setter.If this setter encapsulates a field, return the direct access to that field asFieldSetter
.private void
doAddValue
(Object bean, Object value) private void
doSetDefault
(Object bean) getType()
Gets the type of the underlying method/field.Gets the current value of the property.boolean
Whether this setter is intrinsically multi-valued.private void
trySetDefault
(Object bean1) Remember default so we throw away the default when adding user values.
-
Field Details
-
bean
-
f
-
defaultArray
-
-
Constructor Details
-
ArrayFieldSetter
-
-
Method Details
-
trySetDefault
Remember default so we throw away the default when adding user values.- Throws:
IllegalAccessError
-
doSetDefault
- Throws:
IllegalAccessException
-
asFieldSetter
Description copied from interface:Setter
If this setter encapsulates a field, return the direct access to that field asFieldSetter
. This method serves two purposes:- This lets
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. - The other is to retrieve the current value of the field (via
FieldSetter.getValueList()
).
- Specified by:
asFieldSetter
in interfaceSetter
- Returns:
null
if this setter wraps a method.
- This lets
-
asAnnotatedElement
Description copied from interface:Setter
Returns theAnnotatedElement
by which you can access annotations written on this setter. This is the sameAnnotatedElement
that hadOption
/Argument
.This enables
OptionHandler
to further tweak its behavior based on additional annotations.- Specified by:
asAnnotatedElement
in interfaceSetter
-
isMultiValued
public boolean isMultiValued()Description copied from interface:Setter
Whether this setter is intrinsically multi-valued.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.
- Specified by:
isMultiValued
in interfaceSetter
-
getType
Description copied from interface:Setter
Gets the type of the underlying method/field. -
addValue
Description copied from interface:Setter
Adds/sets a value to the property of the option bean.A
Setter
object has an implicit knowledge about the property it's setting, and the instance of the option bean. -
doAddValue
- Throws:
IllegalAccessException
-
getValueList
Description copied from interface:Getter
Gets the current value of the property.A
Getter
object has an implicit knowledge about the property it's getting, and the instance of the option bean.- Specified by:
getValueList
in interfaceGetter
- Returns:
- empty list or null if there's no current value.
-