net.lessy.util
Class NumberUtil

java.lang.Object
  extended by net.lessy.util.NumberUtil

public class NumberUtil
extends Object

Author:
Hans Lesmeister

Constructor Summary
NumberUtil()
           
 
Method Summary
static BigDecimal checkNumber(Object value)
          Checks if the passed value is a number
static int convertToInt(Integer value, int defaultValue)
          Converts a (big) Integer to a small int.
static Long convertToLong(Number number)
          Converts a Number to (big) Long
static Number convertToNumber(Amount amount)
          Converts an Amount to its associated Number (usually a BigDecimal)
static Number convertToNumber(Amount amount, Number defaultValue)
          Converts an Amount to its associated Number (usually a BigDecimal)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberUtil

public NumberUtil()
Method Detail

convertToLong

public static Long convertToLong(Number number)
Converts a Number to (big) Long

Parameters:
number - Nmber to convert
Returns:
The Long-Value or null if number is null

convertToInt

public static int convertToInt(Integer value,
                               int defaultValue)
Converts a (big) Integer to a small int. If the value is null then the defaultvalue is returned

Parameters:
value - The Integer to convert
defaultValue - Return if value is null
Returns:
int-Value

convertToNumber

public static Number convertToNumber(Amount amount)
Converts an Amount to its associated Number (usually a BigDecimal)

Parameters:
amount - Amount to convert
Returns:
Number-Representation or null if the passed amount is null

convertToNumber

public static Number convertToNumber(Amount amount,
                                     Number defaultValue)
Converts an Amount to its associated Number (usually a BigDecimal)

Parameters:
amount - Amount to convert
defaultValue - Value to return if the passed amount is null
Returns:
Number-Representation or the defaultValue if the passed amount is null

checkNumber

public static BigDecimal checkNumber(Object value)
Checks if the passed value is a number

Parameters:
value - Value to be tested. Can be any type. Tested will be the toString()-result.
Returns:
BigInteger if the value is a number, otherwise null (An Exception is never thrown)


Copyright © 2012. All Rights Reserved.