|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.morph.util.NumberUtils
public abstract class NumberUtils
Various values and utility functions that are useful when working with numbers.
Field Summary | |
---|---|
protected static java.lang.Class[] |
BASE_NUMBER_TYPES
Used by isNumber(Class) . |
static java.math.BigDecimal |
MAX_BYTE
The maximum value a byte can have. |
static java.math.BigDecimal |
MAX_DOUBLE
The maximum value a double can have. |
static java.math.BigDecimal |
MAX_FLOAT
The maximum value a float can have. |
static java.math.BigDecimal |
MAX_INTEGER
The maximum value an integer can have. |
static java.math.BigDecimal |
MAX_LONG
The maximum value a long can have. |
static java.math.BigDecimal |
MAX_SHORT
The maximum value a short can have. |
static java.util.Map |
MAXIMUMS_FOR_TYPES
A Map of BigDecimals keyed by Class that indicate the maximum value that the given (Number) Class may taken on. |
static java.math.BigDecimal |
MIN_BYTE
The minimum value a byte can have. |
static java.math.BigDecimal |
MIN_DOUBLE
The minimum value a double can have. |
static java.math.BigDecimal |
MIN_FLOAT
The minimum value a float can have. |
static java.math.BigDecimal |
MIN_INTEGER
The minimum value an integer can have. |
static java.math.BigDecimal |
MIN_LONG
The minimum value a long can have. |
static java.math.BigDecimal |
MIN_SHORT
The minimum value a short can have. |
static java.util.Map |
MINIMUMS_FOR_TYPES
A Map of BigDecimals keyed by Class that indicate the minimum value that the given (Number) Class may taken on. |
static java.util.Comparator |
NARROWNESS_COMPARATOR
Comparator of class/object type narrowness. |
static java.math.BigDecimal |
ZERO
A BigDecimal containing the value zero (0). |
Constructor Summary | |
---|---|
NumberUtils()
|
Method Summary | |
---|---|
static java.math.BigDecimal |
getMaximumForType(java.lang.Class type)
Returns the maximum allowed value for the given type, which must be a number. |
static java.math.BigDecimal |
getMinimumForType(java.lang.Class type)
Returns the minimum allowed value for the given type, which must be a number. |
static java.lang.Number |
getNumber(java.lang.Class type,
java.lang.String s)
Get a number from a String. |
static java.lang.Class |
getWrapperForPrimitiveType(java.lang.Class type)
Deprecated. for ClassUtils.getPrimitiveWrapper(Class) |
static boolean |
isDecimal(java.lang.Number number)
Returns true if number is capable of
containing a decimal (fractional) component. |
static boolean |
isNumber(java.lang.Class type)
Determines if the given type is a number type. |
protected static boolean |
isOutOfBoundsForType(java.util.Map boundMap,
java.lang.Number number,
java.lang.Class type,
int badCompareToResult)
Implementation of isTooBigForType and isTooSmallForType |
static boolean |
isOutOfBoundsForType(java.lang.Number number,
java.lang.Class type)
Returns true if number has too large an
absolute value to be stored in an instance of the given type . |
static boolean |
isTooBigForType(java.lang.Number number,
java.lang.Class type)
Returns true if number represents a value
too large to be stored in an instance of the given type . |
static boolean |
isTooSmallForType(java.lang.Number number,
java.lang.Class type)
Returns true if number represents a value
too small (i.e. |
static java.math.BigDecimal |
numberToBigDecimal(java.lang.Number number)
Converts the given number to a BigDecimal. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.util.Map MAXIMUMS_FOR_TYPES
public static final java.util.Map MINIMUMS_FOR_TYPES
public static final java.util.Comparator NARROWNESS_COMPARATOR
protected static final java.lang.Class[] BASE_NUMBER_TYPES
isNumber(Class)
.
public static final java.math.BigDecimal MAX_LONG
Long.MAX_VALUE
public static final java.math.BigDecimal MAX_INTEGER
Integer.MAX_VALUE
public static final java.math.BigDecimal MAX_SHORT
Short.MAX_VALUE
public static final java.math.BigDecimal MAX_BYTE
Byte.MAX_VALUE
public static final java.math.BigDecimal MAX_DOUBLE
Double.MAX_VALUE
public static final java.math.BigDecimal MAX_FLOAT
Float.MAX_VALUE
public static final java.math.BigDecimal MIN_LONG
Long.MIN_VALUE
public static final java.math.BigDecimal MIN_INTEGER
Long.MIN_VALUE
public static final java.math.BigDecimal MIN_SHORT
Long.MIN_VALUE
public static final java.math.BigDecimal MIN_BYTE
Long.MIN_VALUE
public static final java.math.BigDecimal MIN_DOUBLE
Long.MIN_VALUE
public static final java.math.BigDecimal MIN_FLOAT
Long.MIN_VALUE
public static final java.math.BigDecimal ZERO
Constructor Detail |
---|
public NumberUtils()
Method Detail |
---|
public static java.math.BigDecimal getMaximumForType(java.lang.Class type)
type
- the type
type
is a number or null
, otherwisepublic static java.math.BigDecimal getMinimumForType(java.lang.Class type)
type
- the type
type
is a number or null
, otherwisepublic static java.math.BigDecimal numberToBigDecimal(java.lang.Number number)
number
- the number to convert
null
, if number is null
or public static boolean isNumber(java.lang.Class type)
java.lang.Number
or is a primitive
number type.
type
- the type to test
true
if the given type is a number type or
false
, otherwisepublic static boolean isDecimal(java.lang.Number number)
true
if number
is capable of
containing a decimal (fractional) component. This method returns
true
for Floats, Doubles, and Longs.
number
- the number to test
false
, if number
is
null
or true
if number
is capable of
containing a decimal (fractional) component or false
, otherwise.protected static boolean isOutOfBoundsForType(java.util.Map boundMap, java.lang.Number number, java.lang.Class type, int badCompareToResult)
public static boolean isTooBigForType(java.lang.Number number, java.lang.Class type)
true
if number
represents a value
too large to be stored in an instance of the given type
.
number
- the number to testthe
- type to test
true
, if number
represents a value
too large to be stored in an instance of the given
type
or false
, otherwise
java.lang.IllegalArgumentException
- if the maximum value cannot be determined for the given typepublic static boolean isTooSmallForType(java.lang.Number number, java.lang.Class type)
true
if number
represents a value
too small (i.e. - with too large a negative absolute value) to be stored
in an instance of the given type
.
number
- the number to testthe
- type to test
true
, if number
represents a value
too small (i.e. - with too large a negative absolute value) to be
stored in an instance of the given type
or false
, otherwise
java.lang.IllegalArgumentException
- if the minimum value cannot be determined for the given typepublic static boolean isOutOfBoundsForType(java.lang.Number number, java.lang.Class type)
true
if number
has too large an
absolute value to be stored in an instance of the given type
.
number
- the number to testthe
- type to test
true
, if number
has too large an
absolute value to be stored in an instance of the given
type
or false
, otherwisepublic static java.lang.Class getWrapperForPrimitiveType(java.lang.Class type)
ClassUtils.getPrimitiveWrapper(Class)
type
-
public static java.lang.Number getNumber(java.lang.Class type, java.lang.String s) throws java.lang.Exception
type
- s
-
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |