main
Class Position

java.lang.Object
  extended by main.Position
Direct Known Subclasses:
City

public class Position
extends java.lang.Object

The Position class represents coordinates given in latitude/longitude pairs.


Field Summary
private  java.lang.Double latitude
           
private  java.lang.Double longitude
           
private  double RADIUS_EARTH
           
 
Constructor Summary
Position()
          Constructs a new Position with the value of null to indicate that the values are not known.
Position(java.lang.Double latitude, java.lang.Double longitude)
          Constructs a new Position with the position indicated by the arguments.
Position(Position p)
          Constructs a new Position that represents the same position as the argument; in other words, the newly created position is a copy of the argument position.
 
Method Summary
 double coordinateDistanceTo(Position position)
          Finds the square of the distance between two positions, treating them as points on a flat plane.
 double distanceTo(Position position)
          Finds the distance in meters between two positions on earth.
 boolean equals(Position other)
          is other object equal to this one?
 java.lang.Double getLatitude()
          Returns the latitude.
 java.lang.Double getLongitude()
          Returns the longitude.
 boolean isDefined()
          Returns true if both latitude and longitude are not null and false otherwise.
 void setLatitude(java.lang.Double latitude)
          Sets the latitude.
 void setLongitude(java.lang.Double longitude)
          Sets the longitude.
 java.lang.String toString()
          Returns a string representation of this Position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

latitude

private java.lang.Double latitude

longitude

private java.lang.Double longitude

RADIUS_EARTH

private final double RADIUS_EARTH
See Also:
Constant Field Values
Constructor Detail

Position

public Position(java.lang.Double latitude,
                java.lang.Double longitude)
Constructs a new Position with the position indicated by the arguments. The arguments can be null if the values are not known.

Parameters:
latitude - a Double
longitude - a Double

Position

public Position()
Constructs a new Position with the value of null to indicate that the values are not known.


Position

public Position(Position p)
Constructs a new Position that represents the same position as the argument; in other words, the newly created position is a copy of the argument position.

Parameters:
p - a Position
Method Detail

getLatitude

public java.lang.Double getLatitude()
Returns the latitude.

Returns:
the latitude

getLongitude

public java.lang.Double getLongitude()
Returns the longitude.

Returns:
the longitude

setLatitude

public void setLatitude(java.lang.Double latitude)
Sets the latitude.

Parameters:
latitude - a Double

setLongitude

public void setLongitude(java.lang.Double longitude)
Sets the longitude.

Parameters:
longitude - a Double

distanceTo

public double distanceTo(Position position)
Finds the distance in meters between two positions on earth.

Parameters:
position - a Position
Returns:
the distance between two positions

coordinateDistanceTo

public double coordinateDistanceTo(Position position)
Finds the square of the distance between two positions, treating them as points on a flat plane.

Parameters:
position - a Position
Returns:
the distance between two positions treated as points on a flat plane

isDefined

public boolean isDefined()
Returns true if both latitude and longitude are not null and false otherwise.

Returns:
whether the position is defined

toString

public java.lang.String toString()
Returns a string representation of this Position. This is for debugging purposes only.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this Position

equals

public boolean equals(Position other)
is other object equal to this one?

Parameters:
other -
Returns:
true if they are equal