uk.ac.starlink.ast.gui
Class AstDouble

java.lang.Object
  extended by java.lang.Number
      extended by uk.ac.starlink.ast.gui.AstDouble
All Implemented Interfaces:
Serializable, Comparable

public class AstDouble
extends Number
implements Comparable

AstDouble implements a double precision Number that represents a value that should be formatted and unformatted using the characteristics of an axis of an AST Frame. This allows it to be encoded and decoded as say RA and Dec, as well as more mundane types such as simple double precision.

This transformation is achieved using the "format" and "unformat" AST routines. Failures to decode a string are signalled by the value of this object being equivalent to BAD (i.e. test isBad()).

Version:
$Id$
Author:
Peter W. Draper
See Also:
Starlink User Note 211, Serialized Form

Field Summary
static double BAD
          The AST bad value.
 
Constructor Summary
AstDouble(double value, Frame frame, int axis)
          Construct an AstDouble.
AstDouble(String value, Frame frame, int axis)
          Construct an AstDouble from a formatted value.
 
Method Summary
 byte byteValue()
           
 int compareTo(Object o)
          Compares this AstDouble to another Object.
 double doubleValue()
           
 float floatValue()
           
 int intValue()
           
 boolean isBad()
          Check if this object is BAD (i.e.
static boolean isBad(double value)
          Check if a value is BAD (i.e.
 long longValue()
           
static double parseDouble(String value, Frame frame, int axis)
          Returns a new double initialized to the value represented by the specified String.
 short shortValue()
           
 String toString()
          Return a String representation of this object.
static String toString(double value, Frame frame, int axis)
          Return a formatted String representation of a double.
 AstDouble valueOf(String value)
          Creates a new AstDouble object by initializing to the value represented by the specified string.
static AstDouble valueOf(String value, Frame frame, int axis)
          Returns a new AstDouble object initialized to the value represented by the specified string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BAD

public static final double BAD
The AST bad value.

See Also:
Constant Field Values
Constructor Detail

AstDouble

public AstDouble(double value,
                 Frame frame,
                 int axis)
Construct an AstDouble.

Parameters:
value - the value to be stored.
frame - a reference to an AST frame whose properties define the axis formatting and unformatting capabilities. This may be a frameset or plot, in which case it applies to the current frame.
axis - the axis in the frameset that should be used.

AstDouble

public AstDouble(String value,
                 Frame frame,
                 int axis)
          throws NumberFormatException
Construct an AstDouble from a formatted value.

Parameters:
value - the value to be unformatted and stored.
frame - a reference to an AST frame whose properties define the axis formatting and unformatting capabilities. This may be a frameset or plot, in which case it applies to the current frame.
axis - the axis in the frameset that should be used.
Throws:
NumberFormatException
Method Detail

isBad

public boolean isBad()
Check if this object is BAD (i.e. AST__BAD).


isBad

public static boolean isBad(double value)
Check if a value is BAD (i.e. AST__BAD).

Parameters:
value - the value to compare.

parseDouble

public static double parseDouble(String value,
                                 Frame frame,
                                 int axis)
Returns a new double initialized to the value represented by the specified String.

Parameters:
value - the string to be parsed.
frame - a reference to an AST frame whose properties define the axis formatting and unformatting capabilities. This may be a frameset or plot, in which case it applies to the current frame.
axis - the axis in the frameset that should be used.
Returns:
double representation of the string. BAD if fails.

toString

public String toString()
Return a String representation of this object.

Overrides:
toString in class Object
Returns:
the AST formatted representation of this object.

toString

public static String toString(double value,
                              Frame frame,
                              int axis)
Return a formatted String representation of a double.

Parameters:
value - the value to be formatted.
frame - a reference to an AST frame whose properties define the axis formatting and unformatting capabilities. This may be a frameset or plot, in which case it applies to the current frame.
axis - the axis in the frameset that should be used.

valueOf

public AstDouble valueOf(String value)
Creates a new AstDouble object by initializing to the value represented by the specified string. This is useful as it keeps the existing frame set and axis.

Parameters:
s - the string to be parsed.
frame - a reference to an AST frame whose properties define the axis formatting and unformatting capabilities. This may be a frameset or plot, in which case it applies to the current frame.
axis - the axis in the frameset that should be used.
Returns:
the new AstDouble object.

valueOf

public static AstDouble valueOf(String value,
                                Frame frame,
                                int axis)
Returns a new AstDouble object initialized to the value represented by the specified string.

Parameters:
s - the string to be parsed.
frame - a reference to an AST frame whose properties define the axis formatting and unformatting capabilities. This may be a frameset or plot, in which case it applies to the current frame.
axis - the axis in the frameset that should be used.
Returns:
the new AstDouble object.

byteValue

public byte byteValue()
Overrides:
byteValue in class Number

doubleValue

public double doubleValue()
Specified by:
doubleValue in class Number

floatValue

public float floatValue()
Specified by:
floatValue in class Number

intValue

public int intValue()
Specified by:
intValue in class Number

longValue

public long longValue()
Specified by:
longValue in class Number

shortValue

public short shortValue()
Overrides:
shortValue in class Number

compareTo

public int compareTo(Object o)
Compares this AstDouble to another Object. If the Object is an AstDouble, this method behaves like compareTo(AstDouble). Otherwise, it throws a ClassCastException (as AstDoubles are comparable only to other AstDoubles).

Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared.
Returns:
the value 0 if the argument is an AstDouble numerically equal to this AstDouble; a value less than 0 if the argument is a Double numerically greater than this AstDouble; and a value greater than 0 if the argument is an AstDouble numerically less than this Double.
Throws:
ClassCastException - if the argument is not an AstDouble.
See Also:
java.lang.Double.compareTo()


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.