gov.nasa.gsfc.commons.numerics.types
Class Sexagesimal

java.lang.Object
  extended by java.lang.Number
      extended by gov.nasa.gsfc.commons.numerics.types.Sexagesimal
All Implemented Interfaces:
Serializable, Comparable

public class Sexagesimal
extends Number
implements Comparable

The Sexagesimal class stores a representation of a time in hours, minutes, seconds, and tenths of seconds. It accepts a time string in the format HH:MM:SS.S and converts it internally to a numeric representation. It allows the time to be stored, updated, and compared to. The time can also be converted to a string in the above format. TODO: This file needs to be cleaned up. There are a lot of methods (e.g. any compare methods not called compareTo which seem pretty useless.

This code was developed for NASA, Goddard Space Flight Center, Code 580 for the Instrument Remote Control (IRC) project.

Version:
$Date: 2006/12/12 14:09:46 $
Author:
M. Grossman
See Also:
Serialized Form

Field Summary
static int MAX_MINUTES
          This constant represents the Maximum number of minutes allowed in a Sexagesimal object.
static double MAX_SECONDS
          This constant represents the Maximum number of seconds allowed in a Sexagesimal object.
static double MIN
          This constant represents the Minimum number of minutes and seconds allowed in a Sexagesimal object.
static int NEG_SIGN
          Represents a negative value of the sign.
static String NEG_SIGN_STR
           
static int POS_SIGN
          Represents a positive value of the sign.
static String POS_SIGN_STR
           
 
Constructor Summary
Sexagesimal()
          Default class constructor.
Sexagesimal(int sign, int hours, int minutes, double seconds)
          Class constructor
Sexagesimal(String time)
          Class constructor
 
Method Summary
 byte byteValue()
          Convert the time held in this Sexagesimal object to seconds.
 int compareTo(Object o)
          Compare this object with the given object.
static Sexagesimal convertDoubleToSexagesimal(double value)
          converts a double value to a Sexagesimal
 double doubleValue()
          Convert the time held in this Sexagesimal object to seconds.
 boolean equals(Sexagesimal otherTime)
          Test if time value held in the Sexagesimal object passed to this method is equal to the time value held in this object.
 float floatValue()
          Convert the time held in this Sexagesimal object to seconds.
 int getHours()
          Get the number of hours held in this Sexagesimal object.
 int getMinutes()
          Get the number of minutes held in this Sexagesimal object.
 double getSeconds()
          Get the number of seconds held in this Sexagesimal object.
 int getSign()
          Get the sign of this Sexagesimal object.
 boolean greaterThan(Sexagesimal time)
          Test if time value held in the Sexagesimal object passed to this method is greater than the time value held in this object.
 boolean greaterThanOrEqual(Sexagesimal time)
          Test if time value held in the Sexagesimal object passed to this method is equal to the time value held in this object.
 int hashCode()
           
 int intValue()
          Convert the time held in this Sexagesimal object to seconds.
 boolean lessThan(Sexagesimal time)
          Test if time value held in the Sexagesimal object passed to this method is less than the time value held in this object.
 boolean lessThanOrEqual(Sexagesimal time)
          Test if time value held in the Sexagesimal object passed to this method is less than or equal to the time value held in this object.
 long longValue()
          Convert the time held in this Sexagesimal object to seconds.
 void setHours(int hours)
          Set the number of hours held in this Sexagesimal object.
 void setMinutes(int minutes)
          Set the number of minutes held in this Sexagesimal object.
 void setSeconds(double seconds)
          Set the number of seconds held in this Sexagesimal object.
 void setSign(int sign)
          Set the sign of the value.
 void setValue(String newTime)
          Set the time held in the Sexagesimal object.
 short shortValue()
          Convert the time held in this Sexagesimal object to seconds.
 String toString()
          Convert the time held in a Sexagesimal object to a string in the format HH:MM:SS.S.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

POS_SIGN

public static final int POS_SIGN
Represents a positive value of the sign.

See Also:
Constant Field Values

NEG_SIGN

public static final int NEG_SIGN
Represents a negative value of the sign.

See Also:
Constant Field Values

MAX_MINUTES

public static final int MAX_MINUTES
This constant represents the Maximum number of minutes allowed in a Sexagesimal object.

See Also:
Constant Field Values

MAX_SECONDS

public static final double MAX_SECONDS
This constant represents the Maximum number of seconds allowed in a Sexagesimal object.

See Also:
Constant Field Values

MIN

public static final double MIN
This constant represents the Minimum number of minutes and seconds allowed in a Sexagesimal object.

See Also:
Constant Field Values

POS_SIGN_STR

public static final String POS_SIGN_STR
See Also:
Constant Field Values

NEG_SIGN_STR

public static final String NEG_SIGN_STR
See Also:
Constant Field Values
Constructor Detail

Sexagesimal

public Sexagesimal()
Default class constructor. Sets hours, minutes, and seconds to 0.


Sexagesimal

public Sexagesimal(String time)
            throws NumberFormatException
Class constructor

Parameters:
time - Initial time value in the format HH:MM:SS.S
Throws:
NumberFormatException - - if the String argument is not in the correct format or, if the minutes or seconds contained in the argument are larger than their MAX or less than MIN then a NumberFormatException is thrown.

Sexagesimal

public Sexagesimal(int sign,
                   int hours,
                   int minutes,
                   double seconds)
            throws IllegalArgumentException
Class constructor

Parameters:
sign - Sign (positive or negative) of the value, normally set as POS_SIGN or NEG_SIGN
hours - Initial hours value
minutes - Initial minutes value
seconds - Initial seconds value
Throws:
IllegalArgumentException - if the minutes or seconds contained in this Sexagesimal object are larger than their MAX or less than MIN then an exception is thrown.
Method Detail

setValue

public void setValue(String newTime)
              throws NumberFormatException
Set the time held in the Sexagesimal object.

Parameters:
newTime - New time value in the format HH:MM:SS.S
Throws:
NumberFormatException - if the minutes or seconds contained in this Sexagesimal object are larger than their MAX or less than MIN then an exception is thrown.

toString

public String toString()
Convert the time held in a Sexagesimal object to a string in the format HH:MM:SS.S.

Overrides:
toString in class Object
Returns:
String holding the time in HH:MM:SS.S format

setSign

public void setSign(int sign)
Set the sign of the value.

Parameters:
sign - the new sign of the value, normally POS_SIGN or NEG_SIGN

setHours

public void setHours(int hours)
Set the number of hours held in this Sexagesimal object.

Parameters:
hours - New hours value

setMinutes

public void setMinutes(int minutes)
                throws IllegalArgumentException
Set the number of minutes held in this Sexagesimal object.

Parameters:
minutes - New minutes value
Throws:
IllegalArgumentException - - if the minutes passed in are larger than their MAX or less than MIN then an exception is thrown.

setSeconds

public void setSeconds(double seconds)
                throws IllegalArgumentException
Set the number of seconds held in this Sexagesimal object.

Parameters:
seconds - New seconds value
Throws:
IllegalArgumentException - - if the seconds passed in are larger than their MAX or less than MIN then an exception is thrown.

getSign

public int getSign()
Get the sign of this Sexagesimal object.

Returns:
sign of the sexagesimal object, returned as POS_SIGN or NEG_SIGN (sign >=0 or sign < 0, respectively)

getHours

public int getHours()
Get the number of hours held in this Sexagesimal object.

Returns:
Hours value held in this object

getMinutes

public int getMinutes()
Get the number of minutes held in this Sexagesimal object.

Returns:
Minutes value held in this object

getSeconds

public double getSeconds()
Get the number of seconds held in this Sexagesimal object.

Returns:
Seconds value held in this object

equals

public boolean equals(Sexagesimal otherTime)
Test if time value held in the Sexagesimal object passed to this method is equal to the time value held in this object.

Parameters:
otherTime - The Sexagesimal to be tested
Returns:
True if the time values are equal, false otherwise

hashCode

public int hashCode()
Overrides:
hashCode in class Object

lessThan

public boolean lessThan(Sexagesimal time)
Test if time value held in the Sexagesimal object passed to this method is less than the time value held in this object.

Parameters:
otherTime - The Sexagesimal to be tested
Returns:
True if the time value in this object is less than that which is held in the other object, false otherwise

greaterThan

public boolean greaterThan(Sexagesimal time)
Test if time value held in the Sexagesimal object passed to this method is greater than the time value held in this object.

Parameters:
otherTime - The Sexagesimal to be tested
Returns:
True if the time value in this object is greater than that which is held in the other object, false otherwise

lessThanOrEqual

public boolean lessThanOrEqual(Sexagesimal time)
Test if time value held in the Sexagesimal object passed to this method is less than or equal to the time value held in this object.

Parameters:
otherTime - The Sexagesimal to be tested
Returns:
True if the time value in this object is less than or equal to that which is held in the other object, false otherwise

greaterThanOrEqual

public boolean greaterThanOrEqual(Sexagesimal time)
Test if time value held in the Sexagesimal object passed to this method is equal to the time value held in this object.

Parameters:
otherTime - The Sexagesimal to be tested
Returns:
True if the time value in this object is greater than or equal to that which is held in the other object, false otherwise

convertDoubleToSexagesimal

public static Sexagesimal convertDoubleToSexagesimal(double value)
converts a double value to a Sexagesimal

Returns:
Sexagesimal - the Sexagesimal representation of the argument

intValue

public int intValue()
Convert the time held in this Sexagesimal object to seconds. This is a double representation cast to a int Needed to subclass Number

Specified by:
intValue in class Number
Returns:
The time value in seconds

floatValue

public float floatValue()
Convert the time held in this Sexagesimal object to seconds. Needed to subclass Number

Specified by:
floatValue in class Number
Returns:
The time value in seconds

longValue

public long longValue()
Convert the time held in this Sexagesimal object to seconds. This is a double representation cast to a long Needed to subclass Number

Specified by:
longValue in class Number
Returns:
The time value in seconds

shortValue

public short shortValue()
Convert the time held in this Sexagesimal object to seconds. This is a double representation cast to a short Needed to subclass Number

Overrides:
shortValue in class Number
Returns:
The time value in seconds

byteValue

public byte byteValue()
Convert the time held in this Sexagesimal object to seconds. This is a double representation cast to a byte Needed to subclass Number

Overrides:
byteValue in class Number
Returns:
The time value in seconds

doubleValue

public double doubleValue()
Convert the time held in this Sexagesimal object to seconds. This is a double representation cast to a double Needed to subclass Number

Specified by:
doubleValue in class Number
Returns:
The time value in seconds

compareTo

public int compareTo(Object o)
Compare this object with the given object.

Specified by:
compareTo in interface Comparable
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