Class Distance

java.lang.Object
rgu.transport.geospatial.Distance
All Implemented Interfaces:
Comparable<Distance>

public final class Distance extends Object implements Comparable<Distance>
Represents a physical distance.
Author:
Lee A. Christie
  • Field Details

    • ZERO

      public static Distance ZERO
      A distance of 0.
  • Method Details

    • ofMeters

      public static Distance ofMeters(double meters)
      Returns an distance specified by meters.
      Parameters:
      meters - the distance
      Returns:
      a distance
    • ofKilometers

      public static Distance ofKilometers(double kilometers)
      Returns an distance specified by kilometers.
      Parameters:
      kilometers - the distance
      Returns:
      a distance
    • ofMiles

      public static Distance ofMiles(double miles)
      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

      public String toString()
      Returns a string representation of the distance as meters.
      Overrides:
      toString in class Object
      Returns:
      a string representation
    • compareTo

      public int compareTo(Distance other)
      Compares this distance to another distance.
      Specified by:
      compareTo in interface Comparable<Distance>
      Parameters:
      other - the other distance, not null
      Returns:
      0, -1, or 1 based on Comparable definition
    • hashCode

      public int hashCode()
      Returns a hash code for this object.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code
    • equals

      public boolean equals(Object other)
      Checks if the other object represents the same distance.
      Overrides:
      equals in class Object
      Parameters:
      other - another object
      Returns:
      true if equal, false otherwise
    • plus

      public Distance plus(Distance other)
      Returns the sum of this distance and another distance.
      Parameters:
      other - the other distance
      Returns:
      the sum
    • write

      public void write(ObjectOutputStream out) throws IOException
      Writes this distance to the specified output stream.
      Parameters:
      out - the output stream, not null
      Throws:
      IOException - if an exception occurred writing
    • read

      public static Distance read(ObjectInputStream in) throws IOException
      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