dods.clients.importwizard.TMAP.convert
Class Convert

java.lang.Object
  extended by dods.clients.importwizard.TMAP.convert.Convert
Direct Known Subclasses:
ConvertLatitude, ConvertLength, ConvertLongitude

public abstract class Convert
extends Object

An abstract class for conversions between double and String along an axis. The axis will have a range of acceptable values. This package is designed to be hooked up with TextInputFields for region specification on database servers.

Version:
0.1, Sep 03, 1997
Author:
Jonathan Callahan This class may change substantially when ported to JDK 1.1 which contains a java.text.Format class. In the future, Convert and its subclasses may extend that class. This software was developed by the Thermal Modeling and Analysis Project(TMAP) of the National Oceanographic and Atmospheric Administration's (NOAA) Pacific Marine Environmental Lab(PMEL), hereafter referred to as NOAA/PMEL/TMAP. Access and use of this software shall impose the following obligations and understandings on the user. The user is granted the right, without any fee or cost, to use, copy, modify, alter, enhance and distribute this software, and any derivative works thereof, and its supporting documentation for any purpose whatsoever, provided that this entire notice appears in all copies of the software, derivative works and supporting documentation. Further, the user agrees to credit NOAA/PMEL/TMAP in any publications that result from the use of this software or in any product that includes this software. The names TMAP, NOAA and/or PMEL, however, may not be used in any advertising or publicity to endorse or promote any products or commercial entity unless specific written permission is obtained from NOAA/PMEL/TMAP. The user also understands that NOAA/PMEL/TMAP is not obligated to provide the user with any support, consulting, training or assistance of any kind with regard to the use, operation and performance of this software nor to provide the user with any updates, revisions, new versions or "bug fixes". THIS SOFTWARE IS PROVIDED BY NOAA/PMEL/TMAP "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NOAA/PMEL/TMAP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE.

Field Summary
protected static int HI
           
protected static int LO
           
protected  int outputStyle
          The output style as defined by individual Convert objects.
protected  double[] range
          The range within which a value is acceptable.
protected  String[] recognizedUnits
          The strings recognized as valid units.
protected  String units
          The base units in which all double values will be expressed.
 
Constructor Summary
Convert()
          Creates a Convert object.
 
Method Summary
 double getNearestValue(double val)
          Returns the nearest value within the range.
 double getNearestValue(double val, int lo_hi)
          Returns the nearest value within the range.
 double[] getRange()
          Returns the LO [0] and HI [1] values of the range as an array of doubles.
 double getRange(int index)
          Returns the LO [0] or HI [1] value from the range of acceptable values.
 String getUnits()
          Returns a String describing the base units.
 double[] intersectRange(double val_lo, double val_hi)
          Returns the intersection of the incoming range within the internal range.
protected  double rangeTest(double val)
           
 void setRange(double lo, double hi)
          Sets the valid range for the Convert object.
 void setUnits(String u)
          Sets the String describing the base units.
abstract  double toDouble(String s)
          Converts a double value to a String.
 String toString()
          Prints out the internal properties.
abstract  String toString(double val)
          Converts a String value to a double.
protected  String unitTest(String u)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LO

protected static final int LO
See Also:
Constant Field Values

HI

protected static final int HI
See Also:
Constant Field Values

outputStyle

protected int outputStyle
The output style as defined by individual Convert objects.


range

protected double[] range
The range within which a value is acceptable.

This can be used if you have a region of interest and you wish to do bounds checking at the level of the input before passing to value to any other routines.


units

protected String units
The base units in which all double values will be expressed.


recognizedUnits

protected String[] recognizedUnits
The strings recognized as valid units. (always lower case) Standard units are specified in individual subclasses.

Constructor Detail

Convert

public Convert()
Creates a Convert object.

Method Detail

getUnits

public String getUnits()
Returns a String describing the base units. For example: m, km, ft, sec, msec, deg E, etc.


setRange

public void setRange(double lo,
                     double hi)
              throws IllegalArgumentException
Sets the valid range for the Convert object. range[LO] < range[HI] regardless of the order in which they are passed in.

Parameters:
lo - the lowest acceptable value.
hi - the highest acceptable value.
Throws:
IllegalArgumentException

getRange

public double getRange(int index)
Returns the LO [0] or HI [1] value from the range of acceptable values.

Parameters:
index - the LO [0] or HI [1] index.
Returns:
the requested value.

getRange

public double[] getRange()
Returns the LO [0] and HI [1] values of the range as an array of doubles.

Returns:
the lo and hi valus of the range.

setUnits

public void setUnits(String u)
              throws IllegalArgumentException
Sets the String describing the base units. For example: m, km, ft, sec, msec, deg E, etc. Standard units are specified in individual subclasses.

Parameters:
u - the string describing the base units.
Throws:
IllegalArgumentException - the unit string is not recognized.

toDouble

public abstract double toDouble(String s)
                         throws IllegalArgumentException
Converts a double value to a String. This is the abstract method which makes this class abstract.

Parameters:
string - the string to be converted.
Throws:
IllegalArgumentException

toString

public String toString()
Prints out the internal properties.

Overrides:
toString in class Object
Returns:
String the internal properties of this converter.

toString

public abstract String toString(double val)
                         throws IllegalArgumentException
Converts a String value to a double. This is the abstract method which makes this class abstract.

Parameters:
val - the string to be converted.
Throws:
IllegalArgumentException

getNearestValue

public double getNearestValue(double val)
Returns the nearest value within the range.

Parameters:
val - The value passed in.
Returns:
the nearest value within the range.

getNearestValue

public double getNearestValue(double val,
                              int lo_hi)
Returns the nearest value within the range. If the value is completely outside the range, the lo_hi parameter is used to determine which end of the range to return.

Parameters:
val - The value passed in.
lo_hi - which end of the range to return.
Returns:
the nearest value within the range.

intersectRange

public double[] intersectRange(double val_lo,
                               double val_hi)
                        throws IllegalArgumentException
Returns the intersection of the incoming range within the internal range. An error is returned if there is no intersection.

Parameters:
val_lo - The lo value of the range to be tested.
val_hi - The hi value of the range to be tested.
Returns:
the nearest value within the range.
Throws:
IllegalArgumentException - range is outside the internally defined range.

rangeTest

protected double rangeTest(double val)
                    throws IllegalArgumentException
Throws:
IllegalArgumentException

unitTest

protected String unitTest(String u)
                   throws IllegalArgumentException
Throws:
IllegalArgumentException