Class Distance
java.lang.Object
rgu.transport.geospatial.Distance
- All Implemented Interfaces:
Comparable<Distance>
Represents a physical distance.
- Author:
- Lee A. Christie
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the distance as kilometers.doubleasMeters()Returns the distance as meters.doubleasMiles()Returns the distance as miles.intCompares this distance to another distance.booleanChecks if the other object represents the same distance.inthashCode()Returns a hash code for this object.static DistanceofKilometers(double kilometers) Returns an distance specified by kilometers.static DistanceofMeters(double meters) Returns an distance specified by meters.static DistanceofMiles(double miles) Returns an distance specified by miles.Returns the sum of this distance and another distance.static DistanceReads a distance from the specified input stream.toString()Returns a string representation of the distance as meters.voidwrite(ObjectOutputStream out) Writes this distance to the specified output stream.
-
Field Details
-
ZERO
A distance of 0.
-
-
Method Details
-
ofMeters
Returns an distance specified by meters.- Parameters:
meters- the distance- Returns:
- a distance
-
ofKilometers
Returns an distance specified by kilometers.- Parameters:
kilometers- the distance- Returns:
- a distance
-
ofMiles
Returns an distance specified by miles.- Parameters:
miles- the distance- Returns:
- a distance
-
asMeters
public double asMeters()Returns the distance as meters.- Returns:
- the distance
-
asKilometers
public double asKilometers()Returns the distance as kilometers.- Returns:
- the distance
-
asMiles
public double asMiles()Returns the distance as miles.- Returns:
- the distance
-
toString
-
compareTo
Compares this distance to another distance.- Specified by:
compareToin interfaceComparable<Distance>- Parameters:
other- the other distance, not null- Returns:
- 0, -1, or 1 based on Comparable definition
-
hashCode
-
equals
-
plus
-
write
Writes this distance to the specified output stream.- Parameters:
out- the output stream, not null- Throws:
IOException- if an exception occurred writing
-
read
Reads a distance from the specified input stream.- Parameters:
in- the input stream, not null- Returns:
- the read distance
- Throws:
IOException- if an exception occurred reading
-