|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.pcauto.util.Quantity
Quantity objects used to hold quantity information.
Objects can only be instantiated using the QuantityFormat class.
A Quantity 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
Quantity objects will be printed using
the overrided toString() method.
A set of arithmetic operations have been included to compare, add, subtract,
divide and multiply quantity objects. All arithmetic operations have
been designed to be null safe.
| Field Summary | |
protected double |
quantity
|
protected Units |
unit
|
| Constructor Summary | |
protected |
Quantity()
Creates new Quantity with an initial value
double value and int unit. |
protected |
Quantity(double quantity,
Units n_unit)
Creates new Quantity with an initial
value double value and int unit. |
| Method Summary | |
protected Quantity |
add(Quantity quant)
Adds this Quantity to the supplied
Quantity. |
protected static Quantity |
add(Quantity a,
Quantity b)
Adds supplied Quantity to other supplied
Quantity. |
protected static boolean |
areEqual(Quantity firstVal,
Quantity secondVal)
Determines if two Quantity objects passed
to the fuction are equal. |
abstract java.lang.Object |
clone()
Creates new Quantity with an initial
value double value and int unit. |
int |
compareTo(java.lang.Object obj)
Compares this Quantity
with the specified
Quantity. |
protected int |
compareTo(Quantity quant)
Compares this Quantity
with the specified
Quantity. |
protected java.math.BigDecimal |
divide(Quantity quant)
Divides this Quantity by supplied
Quantity. |
boolean |
equals(java.lang.Object obj)
|
protected boolean |
equals(Quantity quant)
Compares this Quantity to the specified
Quantity. |
protected double |
getQuantity()
Gets raw numeric value of stored quantity. |
protected Units |
getUnit()
Gets unit of this Quantity. |
protected boolean |
greaterThan(Quantity quant)
Compares this Quantity to the specified
Quantity. |
protected boolean |
lessThan(Quantity quant)
Compares this Quantity to the specified
Quantity. |
protected Quantity |
myDivide(java.math.BigDecimal divisor)
Divides this Quantity by supplied
BigDecimal. |
protected Quantity |
myMultiply(java.math.BigDecimal multiplier)
Multiplies this Quantity by supplied
BigDecimal. |
protected void |
setQuantity(double quantity)
Sets quantity of this quantity to numeric value
contained by supplied double. |
protected void |
setUnit(Units unit)
Sets unit of this Quantity. |
protected static void |
setZERO(Quantity n_zero)
Sets specific Quantity ZERO
implementation for internal use |
protected Quantity |
subtract(Quantity quant)
Subtracts supplied Quantity from
this Quantity. |
| Methods inherited from class java.lang.Object |
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected double quantity
protected Units unit
| Constructor Detail |
protected Quantity()
Quantity with an initial value
double value and int unit.
protected Quantity(double quantity,
Units n_unit)
Quantity with an initial
value double value and int unit.
quantity - double quantity
& @param unit Units| Method Detail |
public abstract java.lang.Object clone()
Quantity with an initial
value double value and int unit.
Quantity objectprotected static void setZERO(Quantity n_zero)
Quantity ZERO
implementation for internal use
protected double getQuantity()
double numeric quantity value in base unitsprotected void setQuantity(double quantity)
this quantity to numeric value
contained by supplied double.
protected Units getUnit()
this Quantity.
Unitsprotected void setUnit(Units unit)
this Quantity.
unit - Units for
this Quantityprotected boolean equals(Quantity quant)
this Quantity to the specified
Quantity.
The result is true if and only if the argument is not
null and is a Quantity object that
has the same value. null parameter returns false.
quant - Quantity with which to compare
true if AbstractQuantities are equivalent;
false othewise.public boolean equals(java.lang.Object obj)
public int compareTo(java.lang.Object obj)
this Quantity
with the specified
Quantity. null parameter returns 1.
compareTo in interface java.lang.Comparableobj - object (must be an Quantity) with which to compare.
this
Quantity is larger
-1 if this Quantity is smaller.protected int compareTo(Quantity quant)
this Quantity
with the specified
Quantity. null parameter returns 1.
quant - Quantity object with which to compare.
this
Quantity is larger
-1 if this Quantity is smaller.protected boolean greaterThan(Quantity quant)
this Quantity to the specified
Quantity.
quant - Quantity object with which to compare.
true if this is greater
than quant;
false otherwiseprotected boolean lessThan(Quantity quant)
this Quantity to the specified
Quantity.
quant - Quantity object with which to compare.
true if this is less
than quant; false otherwise
protected static boolean areEqual(Quantity firstVal,
Quantity secondVal)
Quantity objects passed
to the fuction are equal. Two null are considered equal.
protected Quantity add(Quantity quant)
this Quantity to the supplied
Quantity.
null parameter is considered equal
to Quantity with ZERO quantity.
quant - Quantity object to add
Quantity object resulting
from addition operation
protected static Quantity add(Quantity a,
Quantity b)
Quantity to other supplied
Quantity. null parameter(s) is
considered to be equal to ZERO quantity.
a - first Quantity objectb - second Quantity object
Quantity object resulting from addition of a
and b in Quantity a's unitprotected Quantity subtract(Quantity quant)
Quantity from
this Quantity.
null parameter is considered equal
to Quantity with zero quantity
quant - Quantity object to subtract
Quantity object resulting from subtraction
operation in Units unitprotected java.math.BigDecimal divide(Quantity quant)
this Quantity by supplied
Quantity.
quant - Quantity object to divide by
BigDecimal object resulting from division operation
ArithmeticException - on the attempt to divide
by null or zeroprotected Quantity myMultiply(java.math.BigDecimal multiplier)
this Quantity by supplied
BigDecimal.
Quantity object
resulting from multiplication operation
ArithmeticException - on the attempt
to multiply by nullprotected Quantity myDivide(java.math.BigDecimal divisor)
this Quantity by supplied
BigDecimal.
Quantity object
resulting from division operation
ArithmeticException - on the attempt
to divide by null or zero
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||