Class ArrayFieldSetter
- java.lang.Object
-
- org.kohsuke.args4j.spi.ArrayFieldSetter
-
final class ArrayFieldSetter extends java.lang.Object implements Getter, Setter
Setterthat allows multiple values to be stored into one array field.Because of the
CmdLineParserabstractions 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 Modifier and Type Field Description private java.lang.Objectbeanprivate java.lang.ObjectdefaultArrayprivate java.lang.reflect.Fieldf
-
Constructor Summary
Constructors Constructor Description ArrayFieldSetter(java.lang.Object bean, java.lang.reflect.Field f)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddValue(java.lang.Object value)Adds/sets a value to the property of the option bean.java.lang.reflect.AnnotatedElementasAnnotatedElement()Returns theAnnotatedElementby which you can access annotations written on this setter.FieldSetterasFieldSetter()If this setter encapsulates a field, return the direct access to that field asFieldSetter.private voiddoAddValue(java.lang.Object bean, java.lang.Object value)private voiddoSetDefault(java.lang.Object bean)java.lang.ClassgetType()Gets the type of the underlying method/field.java.util.List<java.lang.Object>getValueList()Gets the current value of the property.booleanisMultiValued()Whether this setter is intrinsically multi-valued.private voidtrySetDefault(java.lang.Object bean1)Remember default so we throw away the default when adding user values.
-
-
-
Method Detail
-
trySetDefault
private void trySetDefault(java.lang.Object bean1) throws java.lang.IllegalAccessErrorRemember default so we throw away the default when adding user values.- Throws:
java.lang.IllegalAccessError
-
doSetDefault
private void doSetDefault(java.lang.Object bean) throws java.lang.IllegalAccessException- Throws:
java.lang.IllegalAccessException
-
asFieldSetter
public FieldSetter asFieldSetter()
Description copied from interface:SetterIf this setter encapsulates a field, return the direct access to that field asFieldSetter. This method serves two purposes:- This lets
OptionHandlers 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:
asFieldSetterin interfaceSetter- Returns:
nullif this setter wraps a method.
- This lets
-
asAnnotatedElement
public java.lang.reflect.AnnotatedElement asAnnotatedElement()
Description copied from interface:SetterReturns theAnnotatedElementby which you can access annotations written on this setter. This is the sameAnnotatedElementthat hadOption/Argument.This enables
OptionHandlerto further tweak its behavior based on additional annotations.- Specified by:
asAnnotatedElementin interfaceSetter
-
isMultiValued
public boolean isMultiValued()
Description copied from interface:SetterWhether 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:
isMultiValuedin interfaceSetter
-
getType
public java.lang.Class getType()
Description copied from interface:SetterGets the type of the underlying method/field.
-
addValue
public void addValue(java.lang.Object value)
Description copied from interface:SetterAdds/sets a value to the property of the option bean.A
Setterobject has an implicit knowledge about the property it's setting, and the instance of the option bean.
-
doAddValue
private void doAddValue(java.lang.Object bean, java.lang.Object value) throws java.lang.IllegalAccessException- Throws:
java.lang.IllegalAccessException
-
getValueList
public java.util.List<java.lang.Object> getValueList()
Description copied from interface:GetterGets the current value of the property.A
Getterobject has an implicit knowledge about the property it's getting, and the instance of the option bean.- Specified by:
getValueListin interfaceGetter- Returns:
- empty list or null if there's no current value.
-
-