com.pcauto.util
Class Dimension

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

public class Dimension
extends Quantity

Dimension objects used to hold dimension information. Objects can only be instantiated using the DimensionFormat class. A Dimension 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 Dimension 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 DimensionUnits baseUnit
           
static Dimension ZERO
          Instance of Currency with zero value.
 
Fields inherited from class com.pcauto.util.Quantity
quantity, unit
 
Constructor Summary
protected Dimension()
          Castor needs this, unfortunately
protected Dimension(double quantity, DimensionUnits unit)
          Creates new Dimension with an initial double value and int unit.
 
Method Summary
 Dimension add(Dimension quant)
          Adds this Dimension to the supplied Dimension.
static Dimension add(Dimension a, Dimension b)
          Adds supplied Dimension to other supplied Dimension.
static boolean areEqual(Dimension quant1, Dimension quant2)
          Determines if two Dimension objects passed to the fuction are equal.
 java.lang.Object clone()
          Creates new Dimension identical to this Dimension
 int compareTo(Dimension quant)
          Compares this Dimension with the specified Dimension.
 Dimension divide(java.math.BigDecimal divisor)
          Divides this Dimension by supplied BigDecimal.
 java.math.BigDecimal divide(Dimension quant)
          Divides this Dimension by supplied Dimension.
 boolean equals(Dimension quant)
          Compares this Dimension to the specified Dimension.
static DimensionUnits getBaseUnit()
          Gets base unit with which this dimension is printed.
 boolean greaterThan(Dimension quant)
          Compares this Dimension to the specified Dimension.
 boolean lessThan(Dimension quant)
          Compares this Dimension to the specified Dimension.
 Dimension multiply(java.math.BigDecimal multiplier)
          Multiplies this Dimension by supplied BigDecimal.
static void setBaseUnit(DimensionUnits unit)
          Sets the "toString" representation of any Dimension objects to be of type unit.
 Dimension subtract(Dimension quant)
          Subtracts supplied Dimension from this Dimension.
 
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 DimensionUnits baseUnit

ZERO

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

Constructor Detail

Dimension

protected Dimension()
Castor needs this, unfortunately


Dimension

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

Parameters:
quantity - double dimension
unit - DimensionUnits
Method Detail

getBaseUnit

public static DimensionUnits getBaseUnit()
Gets base unit with which this dimension is printed.

Returns:
DimensionUnits unit with which dimensions are stored.

setBaseUnit

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


clone

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

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

equals

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

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

compareTo

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

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

greaterThan

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

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

lessThan

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

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

areEqual

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

Returns:
true if equal, false otherwise

add

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

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

add

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

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

subtract

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

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

divide

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

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

multiply

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

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

divide

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

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