faa.tg.units
Class Longitude

java.lang.Object
  extended by faa.tg.units.AMeasure
      extended by faa.tg.units.Angle
          extended by faa.tg.units.Longitude
All Implemented Interfaces:
HasText, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<AMeasure>

public class Longitude
extends Angle
implements java.lang.Cloneable

 Longitude represents the object for measuring units of Longitude.
 
When parsing an input string, if the longitude direction is not specified, then the longitude is assumed to be in the western hemisphere (negative). This is for compatibility with NAS longitude imports.

Eastern hemisphere longitudes can be specified by preceding the longitude string with a "+" OR by appending a directional indicator of "E" to the longitude string.

See section 5.6 of the Detailed Design Document for a discussion of design issues. See the source: Longitude.java

Version:
$Id: Longitude.java,v 3.7 2008/12/09 23:16:43 danaw Exp $
Author:
Tim Kimmet (modeled after Robert G. Oliver's Units Classes)
See Also:
AUnits, AMeasure, Angle, Latitude, Serialized Form

Field Summary
static java.lang.String CVS_VERSION_ID
          The CVS Version ID
static Longitude MAX
           
static Longitude MIN
           
(package private) static long serialVersionUID
           
static Longitude ZERO
           
 
Fields inherited from class faa.tg.units.Angle
D180_DIV_PI, DEG_1, DEG_180, DEG_270, DEG_30, DEG_330, DEG_5, DEG_60, DEG_90, DEG_NEG180, DEG_NEG270, DEG_NEG30, DEG_NEG5, DEG_NEG90, DEG_PER_RAD, NEG_NINETY_DEG, NEG_ONEEIGHTY_DEG, NINETY_DEG, ONEEIGHTY_DEG, PI, PI_DIV_180, PI_DIV_2, PI_DIV_4, PI_MUL_2, PI_MUL_4, RAD_PER_DEG, THIRTY_DEG, THREETHIRTY_DEG, TWOSEVENTY_DEG
 
Fields inherited from class faa.tg.units.AMeasure
DEC0, DEC0_, DEC00, DEC000, DEC1, DEC1_, DEC12, DEC12_, DEC1L, DEC1L_, DEC2, DEC2_, DEC3, DEC3_, DEC4, DEC4_, DEC5, DEC5_, DEC6, DEC6_, DEC7, DEC7_, DEC9, DEC9_, itsValue, TIME_FRACTION
 
Constructor Summary
Longitude(DMSString dms)
          Constructor for the Longitude class that takes a DMSString.
Longitude(double theValue, AngleUnits theUnits)
          Constructor for the Longitude class: normalizes the range if outside the normal longitude range.
Longitude(Longitude origLon, LongitudeRate rate, Time timeToTravel)
          Constructor for the Longitude class that uses a reference longitude, a longitude rate and a time interval to travel at the specified rate.
Longitude(java.lang.String dms)
          Constructor for the Longitude class that takes a string with degrees or degrees-minutes-seconds in DD-MM-SS[.SSS] (and a few other formats).
 
Method Summary
 Longitude add(Longitude addend)
          This summation method adds a value with like units.
 Longitude average(Longitude lon2)
          This method returns the average of this and another Longitude.
private static double avg(double deg1, double deg2)
          Component average used by average() for angles in [0,360] range.
static java.lang.String convertIfNasStandard(java.lang.String lonString)
          Converts an unsigned, non-directional value to a negative value.
 boolean eq(Longitude theMeasure)
          This method provides a test for equality.
 boolean ge(Longitude theMeasure)
          This method provides a test for greater than / equal to.
 boolean gt(Longitude theMeasure)
          This method provides a test for greater than.
 boolean le(Longitude theMeasure)
          This method provides a test for less than / equal to.
 boolean lt(Longitude theMeasure)
          This method provides a test for less than.
static void main(java.lang.String[] args)
          Test case for Longitude that displays parsed parameter as degrees, as a DDD-MM-SS string, and as radians.
static double normalizeRange(double value, AUnits units)
          Normalizes the Longitude to be in the range: -180 < value <= 180.
 double ratio(Longitude val)
          This division method produces a dimensionless ratio of like measures.
 Longitude sub(Longitude subtrahend)
          Returns the difference of this value and the parameter's value.
 java.lang.String toDmsString()
          Converts Longitude to String of form DDD-MM-SS.SSSd (~0.1 ft precision).
private static double toPositive(double deg)
          Converts angles in [-180,+180] range to [0,360] range.
 java.lang.String toString()
          returns the String representation of this object in the form with which it was created.
 java.lang.String toXpvdString()
          Converts Longitude to a string of the format used as XPVD input: DDDMMSS.
 
Methods inherited from class faa.tg.units.Angle
abs, add, aeq, as, average, cos, diff, eq, ge, gt, isBetween, le, lt, parseDmsString, ratio, reciprocalAngle, removeDelimiters, sin, sub, tan, toRadialString, toText
 
Methods inherited from class faa.tg.units.AMeasure
absoluteValue, add, as, as, clone, compareTo, debug, div, eq, equals, ge, getAUnit, getCanonicalUnit, getCanonicalValue, getInitialUnit, getUnitClass, gt, hashCode, isBetween, le, lt, mul, ratio, sub, toAMeasure, toString, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

CVS_VERSION_ID

public static final java.lang.String CVS_VERSION_ID
The CVS Version ID

See Also:
Constant Field Values

ZERO

public static final Longitude ZERO

MAX

public static final Longitude MAX

MIN

public static final Longitude MIN
Constructor Detail

Longitude

public Longitude(double theValue,
                 AngleUnits theUnits)
Constructor for the Longitude class: normalizes the range if outside the normal longitude range.

Parameters:
theValue - The magnitude of Longitude as a double.
theUnits - The units of the value that will be stored (ex: km).
See Also:
Units

Longitude

public Longitude(java.lang.String dms)
          throws java.lang.NumberFormatException
Constructor for the Longitude class that takes a string with degrees or degrees-minutes-seconds in DD-MM-SS[.SSS] (and a few other formats).

This assumes that if the input is an unsigned, non-directional value then the longitude is in the western hemisphere (negative). The string must specify positive or "E" for a longitude in the eastern hemisphere.

Parameters:
dms - A String containing a DMS string.
Throws:
java.lang.NumberFormatException
See Also:
for parsable String formats.

Longitude

public Longitude(DMSString dms)
          throws java.lang.NumberFormatException
Constructor for the Longitude class that takes a DMSString. This assumes that if the input is an unsigned, non-directional value then the longitude is in the western hemisphere (negative). The string must specify positive or "E" for a longitude in the eastern hemisphere.

Parameters:
dms - A string of type DMSString.
Throws:
java.lang.NumberFormatException

Longitude

public Longitude(Longitude origLon,
                 LongitudeRate rate,
                 Time timeToTravel)
Constructor for the Longitude class that uses a reference longitude, a longitude rate and a time interval to travel at the specified rate.

Parameters:
origLon - The reference longitude to travel from.
rate - The rate of change of the longitude.
timeToTravel - The time interval to travel at the specified rate.
Method Detail

convertIfNasStandard

public static java.lang.String convertIfNasStandard(java.lang.String lonString)
                                             throws java.lang.NumberFormatException,
                                                    java.lang.NullPointerException
Converts an unsigned, non-directional value to a negative value. This assumes that if the input does not specify a direction then the longitude is in the western hemisphere (negative). This is used for NAS longitude imports. Does not validate longitude input string.

Parameters:
lonString - A string of type String.
Throws:
java.lang.NullPointerException - Null text string.
java.lang.NumberFormatException - Empty text string.

add

public Longitude add(Longitude addend)
This summation method adds a value with like units. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Parameters:
addend - The unit of measure to add to this measure.
Returns:
A new Longitude equal to this value plus the parameter value.

sub

public Longitude sub(Longitude subtrahend)
Returns the difference of this value and the parameter's value. This subtraction method subtracts a value with like units. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Parameters:
subtrahend - The longitude to subtract from this measure.
Returns:
A new Longitude equal to this value minus the parameter value.

average

public Longitude average(Longitude lon2)
This method returns the average of this and another Longitude. This takes into account crossing the -180/180 longitude boundary by using the smaller angle between the meridians when finding the center.

Returns:
Closest Longitude between this and the given Longitude.

toPositive

private static double toPositive(double deg)
Converts angles in [-180,+180] range to [0,360] range.


avg

private static double avg(double deg1,
                          double deg2)
Component average used by average() for angles in [0,360] range.


ratio

public double ratio(Longitude val)
This division method produces a dimensionless ratio of like measures.

Returns:
The ratio of the two measures.

eq

public boolean eq(Longitude theMeasure)
This method provides a test for equality. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns boolean indicating whether values are equal.

lt

public boolean lt(Longitude theMeasure)
This method provides a test for less than. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns whether this value is less than the given value.

gt

public boolean gt(Longitude theMeasure)
This method provides a test for greater than. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns whether this value is greater than the given value.

ge

public boolean ge(Longitude theMeasure)
This method provides a test for greater than / equal to. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns result of test for less than or equal to.

le

public boolean le(Longitude theMeasure)
This method provides a test for less than / equal to. It overrides the method in the superclass and checks for like AMeasures as well as doing the cast for you.

Returns:
Returns result of test for greater than or equal to.

normalizeRange

public static double normalizeRange(double value,
                                    AUnits units)
Normalizes the Longitude to be in the range: -180 < value <= 180. The next degree increment after 180 is -179, and the degree decrement after -180 is 179.


toDmsString

public java.lang.String toDmsString()
Converts Longitude to String of form DDD-MM-SS.SSSd (~0.1 ft precision).

Overrides:
toDmsString in class Angle
Returns:
String formatted as "DDD-MM-SS.SSS[W|E]" (~0.1 ft precision).

toString

public java.lang.String toString()
returns the String representation of this object in the form with which it was created.

Overrides:
toString in class Angle
Returns:
A String representing the measure in the canonical unit.
See Also:
Units

toXpvdString

public java.lang.String toXpvdString()
Converts Longitude to a string of the format used as XPVD input: DDDMMSS.

Returns:
String formatted in the XPVD format "DDDMMSS".

main

public static void main(java.lang.String[] args)
Test case for Longitude that displays parsed parameter as degrees, as a DDD-MM-SS string, and as radians.