|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.mmm.util.math.base.NumberTypeImpl<NUMBER>
NUMBER - is the generic type of the represented number-class.public abstract class NumberTypeImpl<NUMBER extends Number>
This is the implementation of the NumberType interface.
MathUtilImpl.getNumberType(Class)| Field Summary | |
|---|---|
static NumberTypeImpl<AtomicInteger> |
ATOMIC_INTEGER
The NumberTypeImpl for AtomicInteger. |
static NumberTypeImpl<AtomicLong> |
ATOMIC_LONG
The NumberTypeImpl for AtomicLong. |
static NumberTypeImpl<BigDecimal> |
BIG_DECIMAL
The NumberTypeImpl for BigDecimal. |
static NumberTypeImpl<BigInteger> |
BIG_INTEGER
The NumberTypeImpl for BigInteger. |
static NumberTypeImpl<Byte> |
BYTE
The NumberTypeImpl for Byte. |
static NumberTypeImpl<Double> |
DOUBLE
The NumberTypeImpl for Double. |
private int |
exactness
|
static NumberTypeImpl<Float> |
FLOAT
The NumberTypeImpl for Float. |
static NumberTypeImpl<Integer> |
INTEGER
The NumberTypeImpl for Integer. |
static NumberTypeImpl<Long> |
LONG
The NumberTypeImpl for Long. |
private static double |
REQUIRED_PRECISION
The maximum delta allowed for valueOf(Number, boolean). |
static NumberTypeImpl<Short> |
SHORT
The NumberTypeImpl for Short. |
| Constructor Summary | |
|---|---|
NumberTypeImpl(int exactness)
The constructor. |
|
| Method Summary | |
|---|---|
protected abstract NUMBER |
convert(Number number)
This method converts the given number to the
number-class represented by this object. |
int |
getExactnessDifference(NumberType<?> otherType)
This method gets the difference of the exactness of this NumberTypeImpl and the given otherType. |
protected abstract NUMBER |
parse(String number)
This method gets an instance of the represented
number-class with the numeric value identified by the given string
number. |
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface net.sf.mmm.util.math.api.NumberType |
|---|
getNumberClass, isDecimal |
| Field Detail |
|---|
private static final double REQUIRED_PRECISION
valueOf(Number, boolean).
public static final NumberTypeImpl<Byte> BYTE
NumberTypeImpl for Byte.
public static final NumberTypeImpl<Short> SHORT
NumberTypeImpl for Short.
public static final NumberTypeImpl<Integer> INTEGER
NumberTypeImpl for Integer.
public static final NumberTypeImpl<AtomicInteger> ATOMIC_INTEGER
NumberTypeImpl for AtomicInteger.
public static final NumberTypeImpl<Long> LONG
NumberTypeImpl for Long.
public static final NumberTypeImpl<AtomicLong> ATOMIC_LONG
NumberTypeImpl for AtomicLong.
public static final NumberTypeImpl<Float> FLOAT
NumberTypeImpl for Float.
public static final NumberTypeImpl<Double> DOUBLE
NumberTypeImpl for Double.
public static final NumberTypeImpl<BigInteger> BIG_INTEGER
NumberTypeImpl for BigInteger.
public static final NumberTypeImpl<BigDecimal> BIG_DECIMAL
NumberTypeImpl for BigDecimal.
private final int exactness
getExactnessDifference(NumberType)| Constructor Detail |
|---|
NumberTypeImpl(int exactness)
exactness - is the internal exactness level for
getExactnessDifference(NumberType).| Method Detail |
|---|
protected abstract NUMBER convert(Number number)
number to the
number-class represented by this object. Like a
cast this operation may loose precision (e.g. when converting a
Double to Integer) without warning. Use
valueOf(Number, boolean) instead to avoid this.
number - is the number to convert.
public NUMBER valueOf(Number number,
boolean failIfUnprecise)
throws NumberConversionException
represented
number-class with the numeric value given by number.
valueOf in interface NumberType<NUMBER extends 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)
public NUMBER valueOf(String number)
throws NumberConversionException
represented
number-class with the numeric value identified by the given string
number.
valueOf in interface NumberType<NUMBER extends Number>number - is the string to be parsed as number.
NumberConversionException - if the given number has an
illegal format.
protected abstract NUMBER parse(String number)
throws NumberConversionException,
NumberFormatException
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.
NumberFormatException - if the given number has an
illegal format. This exception will be converted to a
NumberConversionException.public int getExactnessDifference(NumberType<?> otherType)
NumberTypeImpl 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:
getExactnessDifference in interface NumberType<NUMBER extends Number>otherType - is the NumberTypeImpl to compare with.
0 if this
NumberTypeImpl is equal to otherType, positive
if this NumberTypeImpl 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 | |||||||||