T
- the target type of the conversion.public abstract class AbstractBaseConverter<T> extends com.beust.jcommander.converters.BaseConverter<T>
Modifier and Type | Field and Description |
---|---|
protected boolean |
failOnNull
Whether or not a null conversion failure throws a ParameterException.
|
protected Class<T> |
targetClass
The target class to convert strings.
|
Constructor and Description |
---|
AbstractBaseConverter(String optionName,
Class<T> targetClass)
Constructs a new instance for the given option and target class.
|
AbstractBaseConverter(String optionName,
Class<T> targetClass,
boolean failOnNull)
Constructs a new instance for the given option, target class and fail-on-null.
|
Modifier and Type | Method and Description |
---|---|
T |
convert(String value)
Converts the given value or throws a
ParameterException . |
protected abstract T |
convertImpl(String value)
Converts a value.
|
protected String |
getErrorString(String value)
Builds an error message for the given value in error
|
protected boolean |
isSingle(String[] split)
Returns true if the array is of size 1, false otherwise.
|
protected com.beust.jcommander.ParameterException |
newParameterException(String value)
Creates a new
ParameterException for the given value. |
protected com.beust.jcommander.ParameterException |
newParameterException(String value,
Throwable t)
Creates a new
ParameterException for the given value and throwable |
protected String[] |
split(String value)
Splits the given string using
ConverterConstants.VALUE_SEPARATOR as the boundary. |
protected int |
toInt(String optionName,
String value)
Converts the given value to an int for the given option.
|
protected URI |
toURI(String optionName,
String value)
Converts the given string into a URI
|
protected final Class<T> targetClass
protected final boolean failOnNull
public AbstractBaseConverter(String optionName, Class<T> targetClass)
optionName
- The option name, may be null.targetClass
- must not be nullpublic AbstractBaseConverter(String optionName, Class<T> targetClass, boolean failOnNull)
optionName
- may be nulltargetClass
- must not be nullfailOnNull
- if true, the converter fails when the conversion results in a null valuepublic T convert(String value)
ParameterException
. Delegates the actual conversion to subclasses with
convertImpl(String)
.value
- the value to convert.com.beust.jcommander.ParameterException
- for a conversion problemprotected abstract T convertImpl(String value) throws Exception
value
- the value to convertException
- subclasses can throw any Exceptionprotected String getErrorString(String value)
value
- the value that cause the errorprotected boolean isSingle(String[] split)
split
- an arrayprotected com.beust.jcommander.ParameterException newParameterException(String value)
ParameterException
for the given value.value
- the value in errorprotected com.beust.jcommander.ParameterException newParameterException(String value, Throwable t)
ParameterException
for the given value and throwablevalue
- the value in errort
- the throwableprotected String[] split(String value)
ConverterConstants.VALUE_SEPARATOR
as the boundary.value
- the string to splitprotected int toInt(String optionName, String value)
optionName
- the option namevalue
- the value to parseCopyright © 2016-2016 Gary Gregory. All Rights Reserved.
Use is subject to The Apache Software License, Version 2.0