|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.measure.Distance
public class Distance
A measure of distance or length.
Version Info:
$Revision: 1816 $ |
$Date: 2008-12-23 10:21:00 -0700 (Tue, 23 Dec 2008) $ |
$Author: dharland $ |
Constructor Summary | |
---|---|
Distance()
Creates a new distance of zero kilometers. |
|
Distance(BigDecimal kilometers)
Creates a new distance of kilometers kilometers. |
|
Distance(BigDecimal value,
DistanceUnits units)
Creates a new distance with the given magnitude and units. |
|
Distance(String kilometers)
Creates a new distance of kilometers kilometers. |
|
Distance(String value,
DistanceUnits units)
Creates a new distance with the given magnitude and units. |
Method Summary | |
---|---|
Distance |
add(Distance other)
Adds other distance to this one. |
Distance |
clone()
Returns a distance that is equal to this one. |
int |
compareTo(Distance otherDist)
Compares this distance with the otherDist for order. |
Distance |
convertTo(DistanceUnits newUnits)
Converts this measure of distance to the new units. |
boolean |
equals(Object o)
Returns true if o is equal to this distance. |
DistanceUnits |
getUnits()
Returns the units of this distance. |
BigDecimal |
getValue()
Returns the magnitude of this distance. |
int |
hashCode()
Returns a hash code value for this distance. |
boolean |
isInDefaultState()
Returns true if this distance is in its default state, no matter how it got there. |
boolean |
isInfinite()
Returns true if this distance is infinite. |
static Distance |
parse(String distanceString)
Returns a new distance based on distanceString . |
void |
reset()
Resets this distance so that it is equal to a distance created via the no-argument constructor. |
void |
set(BigDecimal value,
DistanceUnits units)
Sets the magnitude and units of this distance. |
void |
set(String distanceString)
Sets the value and units of this distance based on distanceString . |
void |
set(String value,
DistanceUnits units)
Sets the magnitude and units of this distance. |
void |
setUnits(DistanceUnits newUnits)
Sets the units of this distance to newUnits . |
void |
setValue(BigDecimal newValue)
Sets the magnitude of this distance to newValue . |
void |
setValue(String newValue)
Sets the magnitude of this distance to newValue . |
Distance |
subtract(Distance other)
Subtracts other distance from this one. |
String |
toString()
Returns a text representation of this distance. |
String |
toString(int minFracDigits,
int maxFracDigits)
Returns a text representation of this distance. |
BigDecimal |
toUnits(DistanceUnits otherUnits)
Returns the magnitude of this distance in otherUnits . |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Distance()
public Distance(BigDecimal kilometers)
kilometers
kilometers.
See setValue(BigDecimal)
for information
about valid parameter values and exceptions that might
be thrown.
kilometers
- the magnitude of this distance in kilometers.public Distance(String kilometers)
kilometers
kilometers.
See setValue(BigDecimal)
for information
about valid parameter values and exceptions that might
be thrown.
kilometers
- the magnitude of this distance in kilometers.public Distance(BigDecimal value, DistanceUnits units)
set(BigDecimal, DistanceUnits)
for information
about valid parameter values and exceptions that might
be thrown.
value
- the magnitude of this distance.units
- the units in which value
is expressed.public Distance(String value, DistanceUnits units)
set(BigDecimal, DistanceUnits)
for information
about valid parameter values and exceptions that might
be thrown.
value
- the magnitude of this distance.units
- the units in which value
is expressed.Method Detail |
---|
public void reset()
public BigDecimal getValue()
public DistanceUnits getUnits()
public final void set(BigDecimal value, DistanceUnits units)
See setValue(BigDecimal)
for more information on legal
values for value.
value
- the new magnitude of this distance.units
- the units in which value
is expressed.public final void set(String value, DistanceUnits units)
See setValue(String)
for more information on legal
values for value.
value
- the new magnitude of this distance.units
- the units in which value
is expressed.public final void setValue(BigDecimal newValue)
newValue
.
Note that the units of this distance are unaffected by this method.
newValue
- the new magnitude for this distance.
This value may not be null but may be negative or infinite.
NumberFormatException
- if newValue
is null.public final void setValue(String newValue)
newValue
.
Note that the units of this distance are unaffected by this method.
newValue
- the new magnitude for this distance.
This value may not be null but may be negative or infinite.
The allowable representations of infinity are
"infinity", "+infinity", and "-infinity";
these values are not case sensitive.
NumberFormatException
- if newValue
is null.public final void setUnits(DistanceUnits newUnits)
newUnits
.
Note that the value of this distance is unaffected by
this method. Contrast this with convertTo(DistanceUnits)
.
newUnits
- the new units for this distance. If newUnits
is
null it will be replaced with a non-null default
type.public void set(String distanceString)
distanceString
.
See parse(String)
for the expected format of
distanceString
.
If the parsing fails, this distance will be kept in its current state.
distanceString
- a string that will be converted into a distance.
IllegalArgumentException
- if distanceString
is not in the expected form.public boolean isInDefaultState()
A distance is in its default state if both its value and
its units are the same as those of a distance newly created via
the no-argument constructor
.
A distance whose most recent update came via the
reset
method is also in its default state.
public boolean isInfinite()
public Distance convertTo(DistanceUnits newUnits)
After this method is complete this distance will have units of
newUnits
and its value will have been converted
accordingly.
newUnits
- the new units for this distance.
If newUnits
is null an
IllegalArgumentException
will be thrown.
double kilometers =
myDistance.convertTo(DistanceUnits.KILOMETERS).getValue();
public BigDecimal toUnits(DistanceUnits otherUnits)
otherUnits
.
Note that this method does not alter the state of this distance.
Contrast this with convertTo(DistanceUnits)
.
otherUnits
- the units in which to express this distance's magnitude.
otherUnits
.
IllegalArgumentException
- if otherUnits
is null.public Distance add(Distance other)
other
distance to this one.
other
- the distance to be added to this distance.
public Distance subtract(Distance other)
other
distance from this one.
other
- the distance to be subtracted from this distance.
public static Distance parse(String distanceString)
distanceString
.
Valid Formats
Let R be the text representation of a real number.
Let w represent zero or more whitespace characters.
Let S be a valid units
symbol.
Format One: wRw. The given number will be defined to be
in units of kilometers
.
Format Two: wRwSw.
Special Cases
A distanceString
of null or "" (the empty
string) will not result in an IllegalArgumentException
,
but will instead return a distance of zero kilometers.
distanceString
- a string that will be converted into
a distance.
IllegalArgumentException
- if distanceString
is not in
the expected form.public String toString()
toString
in class Object
public String toString(int minFracDigits, int maxFracDigits)
minFracDigits
- the minimum number of places after the decimal point.maxFracDigits
- the maximum number of places after the decimal point.
public Distance clone()
clone
in class Object
public boolean equals(Object o)
o
is equal to this distance.
equals
in class Object
public int hashCode()
hashCode
in class Object
public int compareTo(Distance otherDist)
otherDist
for order.
compareTo
in interface Comparable<Distance>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |