|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
NUMBER - is the generic type of the represented number-class.public interface NumberType<NUMBER extends Number>
This class represents the type reflecting a specific
Number. It allows to check attributes like isDecimal() or to
compare NumberTypes.
Further it acts as factory to create according numbers
from string or
by converting an given number.
This is a class and NOT an Enum to be extensible.
MathUtilImpl.getNumberType(Class)| Method Summary | |
|---|---|
int |
getExactnessDifference(NumberType<?> otherType)
This method gets the difference of the exactness of this NumberType
and the given otherType. |
Class<NUMBER> |
getNumberClass()
This method gets the Class reflecting the Number
represented by this NumberType. |
boolean |
isDecimal()
This method determines if the represented Number
is a decimal value. |
NUMBER |
valueOf(Number number,
boolean failIfUnprecise)
This method gets an instance of the represented
number-class with the numeric value given by number. |
NUMBER |
valueOf(String number)
This method gets an instance of the represented
number-class with the numeric value identified by the given string
number. |
| Method Detail |
|---|
NUMBER valueOf(Number number,
boolean failIfUnprecise)
throws NumberConversionException
represented
number-class with the numeric value given by number.
number - is the numeric value to convert.failIfUnprecise - - if true and conversion causes
precision loss, a NumberConversionException is thrown, if
false this method acts like a primitive cast and
conversion is always successfully.
Number instance of the represented number-class with the value of the given
number. This will be the same instance as
number if it is an instance of the represented number-class
.
NumberConversionException - if the conversion will loose precision
(e.g. when converting a decimal Double to Integer)
NUMBER valueOf(String number)
throws NumberConversionException
represented
number-class with the numeric value identified by the given string
number.
number - is the string to be parsed as number.
NumberConversionException - if the given number has an
illegal format.Class<NUMBER> getNumberClass()
Class reflecting the Number
represented by this NumberType.
boolean isDecimal()
Number
is a decimal value.Double, Float, or BigDecimal
represent decimal values while Integer or Long are NOT
decimal.
true if the represented Number is a decimal value.int getExactnessDifference(NumberType<?> otherType)
NumberType
and the given otherType.Double and BigInteger are NOT
really comparable so the exactness difference might only make sense if the
compared types are both decimal or
both non-decimal (mathematical integers). However the
order of typical types is:
otherType - is the NumberType to compare with.
0 if this
NumberType is equal to otherType, positive if
this NumberType is more exact (later in the examples above)
and negative if otherType is more exact.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||