com.pcauto.util
Class Volume

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

public class Volume
extends Quantity

Volume objects used to hold volume information. Objects Volume can only be instantiated using the VolumeFormat class. A Volume 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 Volume objects will be printed using the overrided toString() method.

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

See Also:
Serialized Form

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

ZERO

public static final Volume ZERO
Instance of Volume with zero value.

Constructor Detail

Volume

protected Volume(double quantity,
                 VolumeUnits unit)
Creates new Volume with an initial value double value and VolumeUnits unit.

Parameters:
quantity - double volume
unit - VolumeUnits
Method Detail

getBaseUnit

public static VolumeUnits getBaseUnit()
Gets base unit with which this volume is printed.

Returns:
VolumeUnits unit with which volumes are printed.

setBaseUnit

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


clone

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

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

equals

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

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

compareTo

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

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

greaterThan

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

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

lessThan

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

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

areEqual

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

Returns:
true if equal, false otherwise

add

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

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

add

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

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

subtract

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

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

divide

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

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

multiply

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

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

divide

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

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