Package xal.tools.text
Class NumericParser
java.lang.Object
xal.tools.text.NumericParser
NumericParser parses a string value into an instance of a specified Number
subclass. It also maintains a static directory of the numeric parsers. It is
useful when one wants to create a generic component for entering values that
could be assigned dynamically a number and a numeric type (Integer, Double,
etc.).
- Author:
- tap
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Number
getNumericValue
(String stringValue) Parse the string value as a numberstatic Number
getNumericValue
(String stringValue, Class<? extends Number> numericType) Parse the string value as a number of the specified numeric type.
-
Constructor Details
-
NumericParser
public NumericParser()
-
-
Method Details
-
getNumericValue
public static Number getNumericValue(String stringValue, Class<? extends Number> numericType) throws NumberFormatException, IllegalArgumentException Parse the string value as a number of the specified numeric type.- Parameters:
stringValue
- String representation of a numbernumericType
- The type of number to instantiate- Returns:
- numeric value of the string value
- Throws:
NumberFormatException
- if the string cannot be parsed into a numberIllegalArgumentException
- if the numeric type specified is unsupported
-
getNumericValue
Parse the string value as a number- Parameters:
stringValue
- String representation of a number- Returns:
- numeric value of the string value
- Throws:
NumberFormatException
- if the string cannot be parsed into a number
-