ezvcard.util
Class GeoUri

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

public class GeoUri
extends Object

Represents a "geo" URI.

Example geo URI: geo:12.341,56.784

Author:
Michael Angstadt
See Also:
RFC 5870

Field Summary
protected  Double coordA
           
protected  Double coordB
           
protected  Double coordC
           
protected  String crs
           
static String CRS_WGS84
          The coordinate reference system used by GPS (the default).
protected static Pattern hexPattern
          Finds hex values in a parameter value.
protected static String PARAM_CRS
           
protected static String PARAM_UNCERTAINTY
           
protected  Map<String,String> parameters
           
protected  Double uncertainty
           
protected static char[] validParamValueChars
          The non-alphanumeric characters which are allowed to exist inside of a parameter value.
 
Constructor Summary
GeoUri()
           
GeoUri(Double coordA, Double coordB, Double coordC, String crs, Double uncertainty)
           
GeoUri(String uri)
          Parses a geo URI string.
 
Method Summary
 void addParameter(String name, String value)
          Adds a parameter.
protected  NumberFormat buildNumberFormat(int decimals)
           
protected  String decodeParamValue(String value)
           
protected  String encodeParamValue(String value)
           
 boolean equals(Object obj)
           
 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).
protected  boolean isLabelText(String text)
           
 boolean isValid()
          Determines if the geo URI is valid or not (i.e.
 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, 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

validParamValueChars

protected static final char[] validParamValueChars
The non-alphanumeric characters which are allowed to exist inside of a parameter value.


hexPattern

protected static final Pattern hexPattern
Finds hex values in a parameter value.


PARAM_CRS

protected static final String PARAM_CRS
See Also:
Constant Field Values

PARAM_UNCERTAINTY

protected static final String PARAM_UNCERTAINTY
See Also:
Constant Field Values

coordA

protected Double coordA

coordB

protected Double coordB

coordC

protected Double coordC

crs

protected String crs

uncertainty

protected Double uncertainty

parameters

protected Map<String,String> parameters
Constructor Detail

GeoUri

public GeoUri()

GeoUri

public GeoUri(Double coordA,
              Double coordB,
              Double coordC,
              String crs,
              Double uncertainty)
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 (i.e. if both an A and B coordinate is 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

isLabelText

protected boolean isLabelText(String text)

encodeParamValue

protected String encodeParamValue(String value)

decodeParamValue

protected String decodeParamValue(String value)

buildNumberFormat

protected NumberFormat buildNumberFormat(int decimals)

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2012-2013. All Rights Reserved.