net.sf.mmm.util.math.api
Interface MathUtil

All Known Implementing Classes:
MathUtilImpl

@ComponentSpecification
public interface MathUtil

This is the interface for a collection of utility functions to deal with Numbers.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Method Summary
 NumberType<? extends Number> getNumberType(Class<?> numericType)
          This method gets the NumberType for the given numericType.
<NUMBER extends Number>
NumberType<NUMBER>
getNumberTypeGeneric(Class<NUMBER> numericType)
          This method gets the NumberType for the given numericType.
 Number toSimplestNumber(Number value)
          This method converts the given value to the simplest suitable number-type.
 

Method Detail

getNumberType

NumberType<? extends Number> getNumberType(Class<?> numericType)
This method gets the NumberType for the given numericType.

Parameters:
numericType - is the class reflecting a Number. It may be primitive (such as int.class). The signature is NOT bound to Number to make it easy for the caller (e.g. Number.class.isAssignableFrom(int.class) is false).
Returns:
the NumberType representing the given numericType or null if the given numericType is no Number or is NOT known (you may extend this MathUtil in such case).
See Also:
getNumberTypeGeneric(Class)

getNumberTypeGeneric

<NUMBER extends Number> NumberType<NUMBER> getNumberTypeGeneric(Class<NUMBER> numericType)
This method gets the NumberType for the given numericType.

Type Parameters:
NUMBER - is the generic type of the numericType.
Parameters:
numericType - is the class reflecting a Number. It may be primitive (such as int.class).
Returns:
the NumberType representing the given numericType or null if the given numericType is NOT known (you may extend this MathUtil in such case).

toSimplestNumber

Number toSimplestNumber(Number value)
This method converts the given value to the simplest suitable number-type. The ordering implied by "simplest" is Byte < Short < Integer < Long < Float < Double.
Please note that a decimal Double is only converted to Float if the result is exactly the same. Be aware that 0.2F - 0.2 is NOT 0.0 (but 2.980232227667301E-9).

Parameters:
value - is the value to convert.
Returns:
a number with the same Number.doubleValue() as the given value and the simplest possible type.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.