ezvcard.util
Class GeoUri

java.lang.Object
  extended by ezvcard.util.GeoUri

public class GeoUri
extends Object

Represents a URI for encoding a geographical position.

Example: geo:12.341,56.784

Author:
Michael Angstadt
See Also:
RFC 5870

Field Summary
static String CRS_WGS84
          The coordinate reference system used by GPS (the default).
 
Constructor Summary
GeoUri()
          Creates an empty geo URI.
GeoUri(Double coordA, Double coordB, Double coordC, String crs, Double uncertainty)
          Creates a geo URI.
GeoUri(String uri)
          Parses a geo URI string.
 
Method Summary
 void addParameter(String name, String value)
          Adds a parameter.
static NumberFormat buildNumberFormat(int decimals)
          Builds a number formatter object for displaying latitudes/longitudes as strings.
 Double getCoordA()
          Gets the first coordinate (latitude).
 Double getCoordB()
          Gets the second coordinate (longitude).
 Double getCoordC()
          Gets the third coordinate (altitude).
 String getCrs()
          Gets the coordinate reference system.
 String getParameter(String name)
          Gets a parameter value.
 Map<String,String> getParameters()
          Gets all the parameters.
 Double getUncertainty()
          Gets the uncertainty (how accurate the coordinates are).
 boolean isValid()
          Determines if the geo URI is valid or not (in other words, if both the A and B coordinates are present).
 void removeParameter(String name)
          Removes a parameter.
 void setCoordA(Double coordA)
          Sets the first coordinate (latitude).
 void setCoordB(Double coordB)
          Sets the second coordinate (longitude).
 void setCoordC(Double coordC)
          Sets the third coordinate (altitude).
 void setCrs(String crs)
          Sets the coordinate reference system.
 void setUncertainty(Double uncertainty)
          Sets the uncertainty (how accurate the coordinates are).
 String toString()
          Converts this geo URI to its string representation.
 String toString(int decimals)
          Converts this geo URI to its string representation.
 URI toUri()
          Creates a URI object from this geo URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CRS_WGS84

public static final String CRS_WGS84
The coordinate reference system used by GPS (the default).

See Also:
Constant Field Values
Constructor Detail

GeoUri

public GeoUri()
Creates an empty geo URI.


GeoUri

public GeoUri(Double coordA,
              Double coordB,
              Double coordC,
              String crs,
              Double uncertainty)
Creates a geo URI.

Parameters:
coordA - the first coordinate (latitude, required)
coordB - the second coordinate (longitude, required)
coordC - the third coordinate (altitude, optional)
crs - the coordinate system (optional, defaults to WGS-84)
uncertainty - the accuracy of the coordinates (in meters, optional)

GeoUri

public GeoUri(String uri)
Parses a geo URI string.

Parameters:
uri - the URI string
Throws:
IllegalArgumentException - if the string is not a valid geo URI
Method Detail

getCoordA

public Double getCoordA()
Gets the first coordinate (latitude).

Returns:
the first coordinate or null if there is none

setCoordA

public void setCoordA(Double coordA)
Sets the first coordinate (latitude).

Parameters:
coordA - the first coordinate

getCoordB

public Double getCoordB()
Gets the second coordinate (longitude).

Returns:
the second coordinate or null if there is none

setCoordB

public void setCoordB(Double coordB)
Sets the second coordinate (longitude).

Parameters:
coordB - the second coordinate

getCoordC

public Double getCoordC()
Gets the third coordinate (altitude).

Returns:
the third coordinate or null if there is none

setCoordC

public void setCoordC(Double coordC)
Sets the third coordinate (altitude).

Parameters:
coordC - the third coordinate or null to remove

getCrs

public String getCrs()
Gets the coordinate reference system.

Returns:
the coordinate reference system or null if using the default (WGS-84)

setCrs

public void setCrs(String crs)
Sets the coordinate reference system.

Parameters:
crs - the coordinate reference system (can only contain letters, numbers, and hyphens) or null to use the default (WGS-84)
Throws:
IllegalArgumentException - if the CRS name contains invalid characters

getUncertainty

public Double getUncertainty()
Gets the uncertainty (how accurate the coordinates are).

Returns:
the uncertainty (in meters) or null if not set

setUncertainty

public void setUncertainty(Double uncertainty)
Sets the uncertainty (how accurate the coordinates are).

Parameters:
uncertainty - the uncertainty (in meters) or null to remove

addParameter

public void addParameter(String name,
                         String value)
Adds a parameter.

Parameters:
name - the parameter name (can only contain letters, numbers, and hyphens)
value - the parameter value
Throws:
IllegalArgumentException - if the parameter name contains invalid characters

removeParameter

public void removeParameter(String name)
Removes a parameter.

Parameters:
name - the name of the parameter to remove

getParameter

public String getParameter(String name)
Gets a parameter value.

Parameters:
name - the parameter name
Returns:
the parameter value or null if not found

getParameters

public Map<String,String> getParameters()
Gets all the parameters.

Returns:
all the parameters

toUri

public URI toUri()
Creates a URI object from this geo URI.

Returns:
the URI object

isValid

public boolean isValid()
Determines if the geo URI is valid or not (in other words, if both the A and B coordinates are present).

Returns:
true if it is valid, false if not

toString

public String toString()
Converts this geo URI to its string representation.

Overrides:
toString in class Object
Returns:
the geo URI's string representation

toString

public String toString(int decimals)
Converts this geo URI to its string representation.

Parameters:
decimals - the number of decimals to display for floating point values
Returns:
the geo URI's string representation

buildNumberFormat

public static NumberFormat buildNumberFormat(int decimals)
Builds a number formatter object for displaying latitudes/longitudes as strings.

Parameters:
decimals - the number of decimals to display
Returns:
the number formatter


Copyright © 2012-2013 Michael Angstadt. All Rights Reserved.