Package adams.data.gps
Class AbstractGPS
- java.lang.Object
-
- adams.data.gps.AbstractGPS
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<AbstractGPS>
- Direct Known Subclasses:
GPSDecimalDegrees
,GPSDecimalMinutes
,GPSDecimalSeconds
public abstract class AbstractGPS extends Object implements Serializable, Comparable<AbstractGPS>, Cloneable
Ancestor for GPS objects.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz), dale (dale at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Coordinate
m_Latitude
latitudeprotected Coordinate
m_Longitude
longitudestatic int
NUM_DECIMALS
the number of decimals to user.
-
Constructor Summary
Constructors Constructor Description AbstractGPS()
Default constructor.AbstractGPS(double lat, double lon)
Initialize GPS with latitude and longitude (in decimal notation).AbstractGPS(AbstractGPS gps)
Initialize GPS with latitude and longitude from the specified object.AbstractGPS(Coordinate lat, Coordinate lon)
Initialize GPS with latitude and longitude.AbstractGPS(String s)
Initialize GPS with latitude and longitude in string representation.AbstractGPS(String s, boolean swapped)
Initialize GPS with latitude and longitude in string representation.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract AbstractGPS
clone()
Creates a copy of itself.int
compareTo(AbstractGPS o)
Compares this object with the specified object for order.boolean
equals(Object o)
Returns whether the two objects are the same.void
fromString(String s)
Parses the string to get the long/lat values from.void
fromString(String s, boolean swapped)
Parses the string to get the long/lat values from.Coordinate
getLatitude()
Returns the latitude.Coordinate
getLongitude()
Returns the longitude.boolean
isValid(String s)
Checks whether the string can be parsed.boolean
isValid(String s, boolean swapped)
Checks whether the string can be parsed.protected Coordinate[]
parse(String s)
Parses the string.protected abstract Coordinate[]
parse(String s, boolean swapped)
Parses the string.protected String
preprocess(String s)
Removes the parentheses and comma in the string: "(north, west)" becomes "north west"abstract String
toString()
Turns the GPS object back into its string representation.
-
-
-
Field Detail
-
NUM_DECIMALS
public static final int NUM_DECIMALS
the number of decimals to user.- See Also:
- Constant Field Values
-
m_Longitude
protected Coordinate m_Longitude
longitude
-
m_Latitude
protected Coordinate m_Latitude
latitude
-
-
Constructor Detail
-
AbstractGPS
public AbstractGPS()
Default constructor.
-
AbstractGPS
public AbstractGPS(String s)
Initialize GPS with latitude and longitude in string representation.- Parameters:
s
- the string representation to parse- See Also:
fromString(String)
-
AbstractGPS
public AbstractGPS(String s, boolean swapped)
Initialize GPS with latitude and longitude in string representation.- Parameters:
s
- the string representation to parseswapped
- whether format is 'long lat' instead of 'lat long'- See Also:
fromString(String)
-
AbstractGPS
public AbstractGPS(AbstractGPS gps)
Initialize GPS with latitude and longitude from the specified object.- Parameters:
gps
- the GPS object to use the lat/lon from
-
AbstractGPS
public AbstractGPS(double lat, double lon)
Initialize GPS with latitude and longitude (in decimal notation).- Parameters:
lat
- latitudelon
- longitude
-
AbstractGPS
public AbstractGPS(Coordinate lat, Coordinate lon)
Initialize GPS with latitude and longitude.- Parameters:
lat
- latitudelon
- longitude
-
-
Method Detail
-
getLongitude
public Coordinate getLongitude()
Returns the longitude.- Returns:
- the coordinate
-
getLatitude
public Coordinate getLatitude()
Returns the latitude.- Returns:
- the coordinate
-
clone
protected abstract AbstractGPS clone()
Creates a copy of itself.
-
compareTo
public int compareTo(AbstractGPS o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareTo
in interfaceComparable<AbstractGPS>
- Parameters:
o
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- Throws:
ClassCastException
- if the specified object's type prevents it from being compared to this object.
-
equals
public boolean equals(Object o)
Returns whether the two objects are the same.
-
preprocess
protected String preprocess(String s)
Removes the parentheses and comma in the string: "(north, west)" becomes "north west"
-
parse
protected abstract Coordinate[] parse(String s, boolean swapped)
Parses the string.- Parameters:
s
- the string to parseswapped
- "long lat" instead of "lat long"- Returns:
- the coordinates (lat/long), null if failed to parse
-
parse
protected Coordinate[] parse(String s)
Parses the string.- Parameters:
s
- the string to parse- Returns:
- the coordinates (lat/long), null if failed to parse
-
isValid
public boolean isValid(String s)
Checks whether the string can be parsed.- Parameters:
s
- the string to check- Returns:
- true if successfully parsed
-
isValid
public boolean isValid(String s, boolean swapped)
Checks whether the string can be parsed.- Parameters:
s
- the string to checkswapped
- "long lat" instead of "lat long"- Returns:
- true if successfully parsed
-
fromString
public void fromString(String s)
Parses the string to get the long/lat values from. If failed to parse, default coordinates are used.- Parameters:
s
- the string to parse
-
fromString
public void fromString(String s, boolean swapped)
Parses the string to get the long/lat values from. If failed to parse, default coordinates are used.- Parameters:
s
- the string to parseswapped
- "long lat" instead of "lat long"
-
-