public void addValue ( String value , boolean isDefault ) { p ( "Adding " + ( isDefault ? "default " : "" ) + "value:" + value + " to parameter:" + m_field . getName ( ) ) ; String name = m_wrappedParameter . names ( ) [ 0 ] ; if ( m_assigned && ! isMultiOption ( ) ) { throw new ParameterException ( "Can only specify option " + name + " once." ) ; } validateParameter ( name , value ) ; Class < ? > type = m_field . getType ( ) ; Object convertedValue = m_jCommander . convertValue ( this , value ) ; boolean isCollection = Collection . class . isAssignableFrom ( type ) ; try { if ( isCollection ) { @ SuppressWarnings ( "unchecked" ) Collection < Object > l = ( Collection < Object > ) m_field . get ( m_object ) ; if ( l == null || fieldIsSetForTheFirstTime ( isDefault ) ) { l = newCollection ( type ) ; m_field . set ( m_object , l ) ; } if ( convertedValue instanceof Collection ) { l . addAll ( ( Collection ) convertedValue ) ; } else { // if (isMainParameter || m_parameterAnnotation.arity() > 1) { l . add ( convertedValue ) ; // } else { // l. } } else { m_wrappedParameter . addValue ( m_field , m_object , convertedValue ) ; } if ( ! isDefault ) m_assigned = true ; } catch ( IllegalAccessException ex ) { ex . printStackTrace ( ) ; } }
Add the specified value to the field . First validate the value if a validator was specified . Then look up any field converter then any type converter and if we can t find any throw an exception .