MPXJ: Microsoft Project Exchange

net.sf.mpxj.utility
Class NumberUtility

java.lang.Object
  extended by net.sf.mpxj.utility.NumberUtility

public final class NumberUtility
extends java.lang.Object

This class contains utility methods for handling Number objects and numeric primitives.


Field Summary
static java.lang.Double DOUBLE_ZERO
           
 
Constructor Summary
NumberUtility()
           
 
Method Summary
static boolean equals(double lhs, double rhs, double delta)
          Compares two doubles for equality, within an allowable range of difference.
static boolean equals(java.lang.Number lhs, java.lang.Number rhs)
          This method is used to compare two numbers.
static java.math.BigInteger getBigInteger(java.lang.Number value)
          Utility method used to convert a Number into a BigInteger.
static java.lang.Double getDouble(double value)
          Utility method used to convert a double into a Double.
static double getDouble(java.lang.Number value)
          Utility method used to convert a Number into a double.
static int getInt(java.lang.Number value)
          This method retrieves an int value from a Number instance.
static int getInt(java.lang.String value)
          This method retrieves an int value from a String instance.
static java.lang.Integer getInteger(java.lang.Number value)
          Utility method used to convert an arbitrary Number into an Integer.
static java.lang.Integer getInteger(java.lang.String value)
          Converts a string representation of an integer into an Integer object.
static java.lang.Integer parseInteger(java.lang.String value)
          Utility method to convert a String to an Integer, and handles null values.
static double truncate(double value, double precision)
          Utility method used to truncate a double to the given precision.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOUBLE_ZERO

public static final java.lang.Double DOUBLE_ZERO
Constructor Detail

NumberUtility

public NumberUtility()
Method Detail

getInt

public static final int getInt(java.lang.Number value)
This method retrieves an int value from a Number instance. It returns zero by default if a null value is supplied.

Parameters:
value - Number instance
Returns:
int value

getInt

public static final int getInt(java.lang.String value)
This method retrieves an int value from a String instance. It returns zero by default if a null value or an empty string is supplied.

Parameters:
value - string representation of an integer
Returns:
int value

getInteger

public static final java.lang.Integer getInteger(java.lang.Number value)
Utility method used to convert an arbitrary Number into an Integer.

Parameters:
value - Number instance
Returns:
Integer instance

getInteger

public static final java.lang.Integer getInteger(java.lang.String value)
Converts a string representation of an integer into an Integer object. Silently ignores any parse exceptions and returns null.

Parameters:
value - String representation of an integer
Returns:
Integer instance

getBigInteger

public static final java.math.BigInteger getBigInteger(java.lang.Number value)
Utility method used to convert a Number into a BigInteger.

Parameters:
value - Number instance
Returns:
BigInteger instance

getDouble

public static final double getDouble(java.lang.Number value)
Utility method used to convert a Number into a double. This has been implemented to allow a singleton to be used to represent zero. This makes a considerable saving in memory utilisation.

Parameters:
value - Number instance
Returns:
double value

getDouble

public static final java.lang.Double getDouble(double value)
Utility method used to convert a double into a Double. This has been implemented to allow a singleton to be used to represent zero. This makes a considerable saving in memory utilisation. NOTE: as of Java 1.5 the Double.valueOf method is supposed to implement caching. The current JDK 1.5 implementation doesn't appear to do this, so we'll leave this method alone for now. We can look at replacing this when we move to 1.6.

Parameters:
value - Number instance
Returns:
double value

truncate

public static final double truncate(double value,
                                    double precision)
Utility method used to truncate a double to the given precision.

Parameters:
value - value to truncate
precision - Number of decimals to truncate to.
Returns:
double value

parseInteger

public static final java.lang.Integer parseInteger(java.lang.String value)
Utility method to convert a String to an Integer, and handles null values.

Parameters:
value - string representation of an integer
Returns:
int value

equals

public static boolean equals(java.lang.Number lhs,
                             java.lang.Number rhs)
This method is used to compare two numbers. The unusual point about this method is that it takes account of null values. If the two number objects are both null, these are taken to be equal, if one is null and the other is not null, these are taken to be different. Finally, if we have two valid number objects, these are compared in the normal manner to determine equality.

Parameters:
lhs - left hand argument
rhs - right hand argument
Returns:
result of equality test

equals

public static boolean equals(double lhs,
                             double rhs,
                             double delta)
Compares two doubles for equality, within an allowable range of difference.

Parameters:
lhs - value to test
rhs - value to test
delta - allowable difference
Returns:
boolean value


Copyright © 2000-2014 Packwood Software. All Rights Reserved.