org.codehaus.groovy.syntax
Class Numbers

Helper class for processing Groovy numeric literals.

author:
Brian Larson
author:
Chris Poirier
version:
$Id: Numbers.java 6778 2007-07-02 10:40:33Z glaforge $

Field Summary
 BigDecimal MAX_DOUBLE
           
 BigDecimal MAX_FLOAT
           
 BigInteger MAX_INTEGER
           
 BigInteger MAX_LONG
           
 BigDecimal MIN_DOUBLE
           
 BigDecimal MIN_FLOAT
           
 BigInteger MIN_INTEGER
           
 BigInteger MIN_LONG
           
 
Constructor Summary
Numbers()
           
 
Method Summary
static boolean isDigit(char c)
           Returns true if the specified character is a base-10 digit.
static boolean isHexDigit(char c)
           Returns true if the specified character is a base-16 digit.
static boolean isNumericTypeSpecifier(char c, boolean isDecimal)
           Returns true if the specified character is a valid type specifier for a numeric value.
static boolean isOctalDigit(char c)
           Returns true if the specific character is a base-8 digit.
static Number parseDecimal(String text)
           Builds a Number from the given decimal descriptor.
static Number parseInteger(String text)
           Builds a Number from the given integer descriptor.
 

Constructor Detail

Numbers

Numbers()


Method Detail

isDigit

public static boolean isDigit(char c)
Returns true if the specified character is a base-10 digit.


isHexDigit

public static boolean isHexDigit(char c)
Returns true if the specified character is a base-16 digit.


isNumericTypeSpecifier

public static boolean isNumericTypeSpecifier(char c, boolean isDecimal)
Returns true if the specified character is a valid type specifier for a numeric value.


isOctalDigit

public static boolean isOctalDigit(char c)
Returns true if the specific character is a base-8 digit.


parseDecimal

public static Number parseDecimal(String text)
Builds a Number from the given decimal descriptor. Uses BigDecimal, unless, Double or Float is requested.
param:
text literal text to parse
return:
instantiated Number object
throws:
NumberFormatException if the number does not fit within the type
requested by the type specifier suffix (invalid numbers don't make it here)


parseInteger

public static Number parseInteger(String text)
Builds a Number from the given integer descriptor. Creates the narrowest type possible, or a specific type, if specified.
param:
text literal text to parse
return:
instantiated Number object
throws:
NumberFormatException if the number does not fit within the type
requested by the type specifier suffix (invalid numbers don't make it here)