|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.pcauto.util.Quantity com.pcauto.util.Distance
Distance
objects used to hold distance information. Objects
can only be instantiated using the DistanceFormat
class.
A Distance
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 Distance
objects will be printed using the overrided toString() method.
A set of arithmetic operations have been included to compare, add,
subtract, divide and multiply distance objects. Arithmetic operations have
been designed to be null
safe.
Field Summary | |
protected static DistanceUnits |
baseUnit
|
static Distance |
ZERO
Instance of Distance with zero value. |
Fields inherited from class com.pcauto.util.Quantity |
quantity, unit |
Constructor Summary | |
protected |
Distance(double quantity,
DistanceUnits unit)
Creates new Distance with initial value double
value and DistanceUnits unit. |
Method Summary | |
Distance |
add(Distance quant)
Adds this Distance to the supplied
Distance . |
static Distance |
add(Distance a,
Distance b)
Adds supplied Distance to other supplied
Distance . |
static boolean |
areEqual(Distance quant1,
Distance quant2)
Determines if two Distance objects passed
to the fuction are equal. |
java.lang.Object |
clone()
Creates new Distance identical to this
Distance . |
int |
compareTo(Distance quant)
Compares this Distance with the specified
Distance . |
Distance |
divide(java.math.BigDecimal divisor)
Divides this Distance by supplied
BigDecimal . |
java.math.BigDecimal |
divide(Distance quant)
Divides this Distance by supplied
Distance . |
boolean |
equals(Distance quant)
Compares this Distance to the specified
Distance . |
static DistanceUnits |
getBaseUnit()
Gets base unit with which this Distance
is printed. |
boolean |
greaterThan(Distance quant)
Compares this Distance to the specified
Distance . |
boolean |
lessThan(Distance quant)
Compares this Distance to the specified
Distance . |
Distance |
multiply(java.math.BigDecimal multiplier)
Multiplies this Distance by supplied
BigDecimal . |
static void |
setBaseUnit(DistanceUnits unit)
Sets the "toString" representation of any Distance objects
to be of type unit . |
Distance |
subtract(Distance quant)
Subtracts supplied Distance from
this Distance . |
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 |
protected static DistanceUnits baseUnit
public static final Distance ZERO
Distance
with zero value.
Constructor Detail |
protected Distance(double quantity, DistanceUnits unit)
Distance
with initial value double
value and DistanceUnits
unit.
quantity
- double
weightunit
- DistanceUnits
Method Detail |
public static DistanceUnits getBaseUnit()
this
Distance
is printed.
DistanceUnits
unit with which Distance
objects are printed.public static void setBaseUnit(DistanceUnits unit)
Distance
objects
to be of type unit
.
public java.lang.Object clone()
Distance
identical to this
Distance
.
clone
in class Quantity
Distance
objectpublic boolean equals(Distance quant)
this
Distance
to the specified
Distance
.
The result is true
if and only if the argument is not
null
and is a Distance
object that has
the same value. null
parameter returns false.
quant
- Distance
with which to compare
true
if Distances
are equivalent;
false
othewise.public int compareTo(Distance quant)
this
Distance
with the specified
Distance
. null
parameter returns 1.
quant
- Distance
object with which to compare.
this
Distance
is larger.
-1 if this
Distance
is smaller.public boolean greaterThan(Distance quant)
this
Distance
to the specified
Distance
.
quant
- Distance
object with which to compare.
true
if this
is greater
than quant
;
false
otherwisepublic boolean lessThan(Distance quant)
this
Distance
to the specified
Distance
.
quant
- Distance
object with which to compare.
true
if this
is less
than quant
; false
otherwisepublic static boolean areEqual(Distance quant1, Distance quant2)
Distance
objects passed
to the fuction are equal. Two null
are considered equal.
public Distance add(Distance quant)
this
Distance
to the supplied
Distance
.
null
parameter is considered equal to Distance
with ZERO quantity.
quant
- Distance
object to add
Distance
object resulting from addition operationpublic static Distance add(Distance a, Distance b)
Distance
to other supplied
Distance
. null
parameter(s) is considered
to be equal to ZERO quantity.
a
- first Distance
objectb
- second Distance
object
Distance
object resulting from addition of a
and b in Distance
a's unitpublic Distance subtract(Distance quant)
Distance
from
this
Distance
.
null
parameter is considered equal to Distance
with zero quantity
quant
- Distance
object to subtract
Distance
object resulting from subtraction
operation in this
unitpublic java.math.BigDecimal divide(Distance quant)
this
Distance
by supplied
Distance
.
quant
- Distance
object to divide by
BigDecimal
object resulting from division operation
ArithmeticException
- on the attempt
to divide by null
or zeropublic Distance multiply(java.math.BigDecimal multiplier)
this
Distance
by supplied
BigDecimal
.
Distance
object resulting
from multiplication operation
ArithmeticException
- on the
attempt to multiply by null
public Distance divide(java.math.BigDecimal divisor)
this
Distance
by supplied
BigDecimal
.
Distance
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 |