com.pcauto.util
Class Density

java.lang.Object
  extended bycom.pcauto.util.Quantity
      extended bycom.pcauto.util.Density
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class Density
extends Quantity

Density objects used to hold density information. Objects can only be instantiated using the DensityFormat class. A Density object's concept of unit is hidden from class users, and instead inferred from the formatter class at instantiation.

The baseUnit is used to store the unit with which Density objects will be printed using the overrided toString() method.

A set of arithmetic operations have been included to compare, add, subtract, divide and multiply currency objects. Arithmetic operations have been designed to be null safe.

See Also:
Serialized Form

Field Summary
protected static DensityUnits baseUnit
           
static Density ZERO
          Instance of Currency with zero value.
 
Fields inherited from class com.pcauto.util.Quantity
quantity, unit
 
Constructor Summary
protected Density()
          Castor needs this, unfortunately
protected Density(double quantity, DensityUnits unit)
          Creates new Density with an initial double value and int unit.
 
Method Summary
 Density add(Density quant)
          Adds this Density to the supplied Density.
static Density add(Density a, Density b)
          Adds supplied Density to other supplied Density.
static boolean areEqual(Density quant1, Density quant2)
          Determines if two Density objects passed to the fuction are equal.
 java.lang.Object clone()
          Creates new Density identical to this Density
 int compareTo(Density quant)
          Compares this Density with the specified Density.
 Density divide(java.math.BigDecimal divisor)
          Divides this Density by supplied BigDecimal.
 java.math.BigDecimal divide(Density quant)
          Divides this Density by supplied Density.
 boolean equals(Density quant)
          Compares this Density to the specified Density.
static DensityUnits getBaseUnit()
          Gets base unit with which this density is printed.
 boolean greaterThan(Density quant)
          Compares this Density to the specified Density.
 boolean lessThan(Density quant)
          Compares this Density to the specified Density.
 Density multiply(java.math.BigDecimal multiplier)
          Multiplies this Density by supplied BigDecimal.
static void setBaseUnit(DensityUnits unit)
          Sets the "toString" representation of any Density objects to be of type unit.
 Density subtract(Density quant)
          Subtracts supplied Density from this Density.
 
Methods inherited from class com.pcauto.util.Quantity
add, add, areEqual, compareTo, compareTo, divide, equals, equals, getQuantity, getUnit, greaterThan, lessThan, myDivide, myMultiply, setQuantity, setUnit, setZERO, subtract
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseUnit

protected static DensityUnits baseUnit

ZERO

public static final Density ZERO
Instance of Currency with zero value.

Constructor Detail

Density

protected Density()
Castor needs this, unfortunately


Density

protected Density(double quantity,
                  DensityUnits unit)
Creates new Density with an initial double value and int unit.

Parameters:
quantity - double density
unit - DensityUnits
Method Detail

getBaseUnit

public static DensityUnits getBaseUnit()
Gets base unit with which this density is printed.

Returns:
DensityUnits unit with which densities are stored.

setBaseUnit

public static void setBaseUnit(DensityUnits unit)
Sets the "toString" representation of any Density objects to be of type unit.


clone

public java.lang.Object clone()
Creates new Density identical to this Density

Specified by:
clone in class Quantity
Returns:
new Density object

equals

public boolean equals(Density quant)
Compares this Density to the specified Density. The result is true if and only if the argument is not null and is a Density object that has the same value. Null parameter returns false.

Parameters:
quant - Density with which to compare
Returns:
true if Densitys are equivalent; false othewise.

compareTo

public int compareTo(Density quant)
Compares this Density with the specified Density. Null parameter returns 1.

Parameters:
quant - Density object with which to compare.
Returns:
0 if they are equal. 1 if this Density is larger. -1 if this Density is smaller.

greaterThan

public boolean greaterThan(Density quant)
Compares this Density to the specified Density.

Parameters:
quant - Density object with which to compare.
Returns:
true if this is greater than quant; false otherwise

lessThan

public boolean lessThan(Density quant)
Compares this Density to the specified Density.

Parameters:
quant - Density object with which to compare.
Returns:
true if this is less than quant; false otherwise

areEqual

public static boolean areEqual(Density quant1,
                               Density quant2)
Determines if two Density objects passed to the fuction are equal. Two null are considered equal.

Returns:
true if equal, false otherwise

add

public Density add(Density quant)
Adds this Density to the supplied Density. Null parameter is considered equal to Density with ZERO quantity.

Parameters:
quant - Density object to add
Returns:
Density object resulting from addition operation

add

public static Density add(Density a,
                          Density b)
Adds supplied Density to other supplied Density. Null parameter(s) is considered to be equal to ZERO quantity.

Parameters:
a - first Density object
b - second Density object
Returns:
Density object resulting from addition of a and b in Density a's unit

subtract

public Density subtract(Density quant)
Subtracts supplied Density from this Density. Null parameter is considered equal to Density with zero quantity

Parameters:
quant - Density object to subtract
Returns:
Density object resulting from subtraction operation in this unit

divide

public java.math.BigDecimal divide(Density quant)
Divides this Density by supplied Density.

Parameters:
quant - Density object to divide by
Returns:
BigDecimal object resulting from division operation
Throws:
ArithmeticException - on the attempt to divide by null or zero

multiply

public Density multiply(java.math.BigDecimal multiplier)
Multiplies this Density by supplied BigDecimal.

Returns:
Density object resulting from multiplication operation
Throws:
ArithmeticException - on the attempt to multiply by null

divide

public Density divide(java.math.BigDecimal divisor)
Divides this Density by supplied BigDecimal.

Returns:
Density object resulting from division operation
Throws:
ArithmeticException - on the attempt to divide by null or zero