Class NumericParser

java.lang.Object
xal.tools.text.NumericParser

public abstract class NumericParser extends Object
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 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 number
      numericType - The type of number to instantiate
      Returns:
      numeric value of the string value
      Throws:
      NumberFormatException - if the string cannot be parsed into a number
      IllegalArgumentException - if the numeric type specified is unsupported
    • getNumericValue

      public abstract Number getNumericValue(String stringValue) throws NumberFormatException
      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