com.pcauto.util
Class Temperature

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

public class Temperature
extends Quantity

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

ZERO

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

Constructor Detail

Temperature

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

Parameters:
quantity - double temperature
unit - TemperatureUnits
Method Detail

getBaseUnit

public static TemperatureUnits getBaseUnit()
Gets base unit with this temperature is printed.

Returns:
TemperatureUnits unit with which temperatures are stored.

setBaseUnit

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


clone

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

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

equals

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

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

compareTo

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

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

greaterThan

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

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

lessThan

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

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

areEqual

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

Returns:
true if equal, false otherwise

add

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

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

add

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

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

subtract

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

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

divide

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

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

multiply

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

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

divide

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

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