|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.morph.transform.transformers.BaseTransformer net.sf.morph.transform.converters.TextToNumberConverter
public class TextToNumberConverter
Converts basic text types into primitive numbers or Number
objects.
Field Summary | |
---|---|
static int |
CURRENCY_IGNORE
Constant indicating currency symbols should be ignored when converting text to numbers. |
static int |
CURRENCY_REJECT
Constant indicating the presence of currency symbols in text should prevent conversion of the text into a number (i.e. |
static int |
PARENTHESES_IGNORE
Constant indicating parentheses should be ignored when converting text to numbers. |
static int |
PARENTHESES_NEGATE
Constant indicating parentheses enclosing a number should cause the text to be treated as a negative number. |
static int |
PARENTHESES_REJECT
Constant indicating the presence of parentheses in text should prevent conversion of the text into a number (i.e. |
static int |
PERCENTAGE_CONVERT_TO_DECIMAL
Constant indicating a percentage symbol at the end of text should cause the text to be treated as a percentage and converted into a corresponding decimal number. |
static int |
PERCENTAGE_IGNORE
Constant indicating percentage symbols should be ignored when converting text to numbers. |
static int |
PERCENTAGE_REJECT
Constant indicating the presence of percentage symbols in text should prevent conversion of the text into a number (i.e. |
static int |
WHITESPACE_IGNORE
Constant indicating whitespace characters should be ignored when converting text to numbers. |
static int |
WHITESPACE_REJECT
Constant indicating the presence of whitespace characters in text should prevent conversion of the text into a number (i.e. |
Fields inherited from class net.sf.morph.transform.transformers.BaseTransformer |
---|
destinationClasses, log, sourceClasses |
Fields inherited from interface net.sf.morph.transform.Transformer |
---|
TRANSFORMATION_TYPE_CONVERT, TRANSFORMATION_TYPE_COPY |
Fields inherited from interface net.sf.morph.transform.Transformer |
---|
TRANSFORMATION_TYPE_CONVERT, TRANSFORMATION_TYPE_COPY |
Constructor Summary | |
---|---|
TextToNumberConverter()
|
Method Summary | |
---|---|
protected java.lang.Object |
convertImpl(java.lang.Class destinationClass,
java.lang.Object source,
java.util.Locale locale)
The implementation of the convert method, which may omit
the invalid argument checks already performed by this base class. |
int |
getCurrencyHandling()
Retrieves the configuration option indicating how currencies should be treated by this converter. |
protected java.lang.Class[] |
getDestinationClassesImpl()
Transformer.getDestinationClasses() implementation template method. |
Converter |
getNumberConverter()
Sets the converter used to convert text types from one type to another. |
int |
getParenthesesHandling()
Retrieves the configuration option indicating how parantheses should be treated by this converter. |
int |
getPercentageHandling()
Gets the configuration option indicating how percentages should be treated by this converter. |
protected java.lang.Class[] |
getSourceClassesImpl()
Transformer.getSourceClasses() implementation template method. |
Converter |
getTextConverter()
Gets the converter used to convert text types from one type to another. |
int |
getWhitespaceHandling()
Gets the configuration option indicating how whitespace should be treated by this converter. |
protected boolean |
isParseSuccessful(java.lang.String stringWithoutIgnoredSymbolsStr,
java.text.ParsePosition position)
Learn whether the entire string was consumed. |
protected boolean |
isWrappingRuntimeExceptions()
Indicates whether runtime exceptions should be wrapped as TransformationException s. |
void |
setCurrencyHandling(int currencyHandling)
Sets the configuration option indicating how currencies should be treated by this converter. |
void |
setNumberConverter(Converter numberConverter)
Sets the converter used to convert text types from one type to another. |
void |
setParenthesesHandling(int parenthesesHandling)
Sets the configuration option indicating how parantheses should be treated by this converter. |
void |
setPercentageHandling(int percentageHandling)
Sets the configuration option indicating how percentages should be treated by this converter. |
void |
setTextConverter(Converter textConverter)
Sets the converter used to convert text types from one type to another. |
void |
setWhitespaceHandling(int whitespaceHandling)
Sets the configuration option indicating how whitespace should be treated by this converter. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface net.sf.morph.transform.DecoratedConverter |
---|
convert, equals, equals |
Methods inherited from interface net.sf.morph.transform.Converter |
---|
convert |
Methods inherited from interface net.sf.morph.transform.Transformer |
---|
getDestinationClasses, getSourceClasses |
Methods inherited from interface net.sf.morph.transform.Transformer |
---|
getDestinationClasses, getSourceClasses |
Methods inherited from interface net.sf.morph.transform.ExplicitTransformer |
---|
isTransformable |
Field Detail |
---|
public static final int WHITESPACE_IGNORE
public static final int WHITESPACE_REJECT
public static final int CURRENCY_IGNORE
public static final int CURRENCY_REJECT
public static final int PERCENTAGE_IGNORE
public static final int PERCENTAGE_REJECT
public static final int PERCENTAGE_CONVERT_TO_DECIMAL
public static final int PARENTHESES_IGNORE
public static final int PARENTHESES_REJECT
public static final int PARENTHESES_NEGATE
Constructor Detail |
---|
public TextToNumberConverter()
Method Detail |
---|
protected java.lang.Object convertImpl(java.lang.Class destinationClass, java.lang.Object source, java.util.Locale locale) throws java.lang.Exception
convert
method, which may omit
the invalid argument checks already performed by this base class. By
default, this method creates a new instance of the destinationClass and
copies information from the source to the destination. This
implementation should be fine as-is for Copiers, but Converters will need
to implement this method since they will not be implementing the copy
method.
convertImpl
in class BaseTransformer
locale
- the locale in which the conversion should take place. for
converters that are not locale-aware, the local argument can
simply be ignored
java.lang.Exception
protected boolean isParseSuccessful(java.lang.String stringWithoutIgnoredSymbolsStr, java.text.ParsePosition position)
stringWithoutIgnoredSymbolsStr
- position
-
protected boolean isWrappingRuntimeExceptions()
TransformationException
s. By default, this method returns
true
.
Simple transformers in Morph that operate on JDK types like Numbers and
Strings will usually set this value to true
so that they
throw TransformationExceptions if problems occur. More complex
transformers that operate on graphs of objects are encouraged to set this
value to false
so that runtime exceptions are not wrapped.
This way, problems accessing data will be expressed by the native API of
a user's domain objects and avoid the need to catch Morph-specific
exceptions (assuming the use of runtime exceptions in said domain
objects).
isWrappingRuntimeExceptions
in class BaseTransformer
true
protected java.lang.Class[] getSourceClassesImpl() throws java.lang.Exception
Transformer.getSourceClasses()
implementation template method.
getSourceClassesImpl
in class BaseTransformer
java.lang.Exception
protected java.lang.Class[] getDestinationClassesImpl() throws java.lang.Exception
Transformer.getDestinationClasses()
implementation template method.
getDestinationClassesImpl
in class BaseTransformer
java.lang.Exception
public Converter getNumberConverter()
public void setNumberConverter(Converter numberConverter)
numberConverter
- the converter used to convert text types from one type to
anotherpublic Converter getTextConverter()
public void setTextConverter(Converter textConverter)
textConverter
- the converter used to convert text types from one type to
anotherpublic int getCurrencyHandling()
CURRENCY_IGNORE
.
public void setCurrencyHandling(int currencyHandling)
CURRENCY_IGNORE
.
currencyHandling
- the configuration option indicating how currencies should be
treated by this converter. Default is CURRENCY_IGNORE
.public int getParenthesesHandling()
PARENTHESES_NEGATE
.
PARENTHESES_NEGATE
.public void setParenthesesHandling(int parenthesesHandling)
PARENTHESES_NEGATE
.
parenthesesHandling
- the configuration option indicating how parantheses should be
treated by this converter. Default is
PARENTHESES_NEGATE
.public int getPercentageHandling()
PERCENTAGE_CONVERT_TO_DECIMAL
.
PERCENTAGE_CONVERT_TO_DECIMAL
.public void setPercentageHandling(int percentageHandling)
PERCENTAGE_CONVERT_TO_DECIMAL
.
percentageHandling
- the configuration option indicating how percentages should be
treated by this converter. Default is
PERCENTAGE_CONVERT_TO_DECIMAL
.public int getWhitespaceHandling()
WHITESPACE_IGNORE
.
WHITESPACE_IGNORE
.public void setWhitespaceHandling(int whitespaceHandling)
WHITESPACE_IGNORE
.
whitespaceHandling
- the configuration option indicating how whitespace should be
treated by this converter. Default is
WHITESPACE_IGNORE
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |