cds.astro
Class Converter

java.lang.Object
  extended by cds.astro.Converter

public class Converter
extends java.lang.Object

This class, tightly connected to the Unit class, gathers non-standard unit conversions.

Standard conversions are made between units having the same physical dimension, as e.g. a conversion between Hz and km/s/Mpc. Conversion bewteen units having different physical dimensions are called non-standard, e.g. between hours (time) and degrees (angle). This default class contains linear transformations only; a derived class can be used if necessary to generate more complex converters.

Version:
1.0 15-Nov-2006: Finalisation
Author:
Brice GASSMANN, Francois Ochsenbein-- francois@astro.u-strasbg.fr

Field Summary
 double factor
          The conversion factor, if used (target = factor * source)
 Unit source
          The source unit
 Unit target
          The target unit
 
Constructor Summary
Converter(java.lang.String source_unit, java.lang.String target_unit)
          Creation of a standard converter.
Converter(java.lang.String source_unit, java.lang.String target_unit, double factor)
          Creation (and registration) of a unit converter.
 
Method Summary
 double convert(double value)
          Convert a number.
 double convert(java.lang.String value)
          Convert a value.
 void dump(java.lang.String title)
          Dump the object
 java.lang.String toString()
          Standard edition of the unit converter
 java.lang.String transform(double value)
          Convert a value, return its edited form.
 java.lang.String transform(java.lang.String value)
          Convert a value, return its edited form.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

source

public Unit source
The source unit


target

public Unit target
The target unit


factor

public double factor
The conversion factor, if used (target = factor * source)

Constructor Detail

Converter

public Converter(java.lang.String source_unit,
                 java.lang.String target_unit)
Creation of a standard converter. The standard rules of unit conversion are applied (see Unit.convert(cds.astro.Unit, cds.astro.Unit))

Parameters:
source_unit - unit of source value
target_unit - unit of target value

Converter

public Converter(java.lang.String source_unit,
                 java.lang.String target_unit,
                 double factor)
Creation (and registration) of a unit converter. New objects of this class are known in Unit.convert(cds.astro.Unit, cds.astro.Unit), i.e. the convert(double) method defined here is applied.

Examples could be Converter("h", "deg", 15.) or Converter("\"d:m:s\"", "\"h:m:s\"", 1./15.)

Parameters:
source_unit - unit of source value.
target_unit - unit of target value
factor - factor of conversion in: target = factor * source
Method Detail

dump

public void dump(java.lang.String title)
Dump the object

Parameters:
title - title line of the dump

convert

public double convert(double value)
               throws java.lang.ArithmeticException
Convert a number. Convert the value from source unit into target unit

Parameters:
value - the value (expressed in source)
Returns:
the corresponding value, expressed in target units.
Throws:
java.lang.ArithmeticException

convert

public double convert(java.lang.String value)
               throws java.text.ParseException,
                      java.lang.ArithmeticException
Convert a value. Convert the value from source unit into target unit

Parameters:
value - the value (expressed in source)
Returns:
the corresponding value, expressed in target units.
Throws:
java.text.ParseException
java.lang.ArithmeticException

transform

public java.lang.String transform(java.lang.String value)
                           throws java.text.ParseException,
                                  java.lang.ArithmeticException
Convert a value, return its edited form. Convert the value from source unit into target unit

Parameters:
value - the value (expressed in source)
Returns:
the corresponding edited value, expressed in target units.
Throws:
java.text.ParseException
java.lang.ArithmeticException

transform

public java.lang.String transform(double value)
                           throws java.lang.ArithmeticException
Convert a value, return its edited form. Convert the value from source unit into target unit

Parameters:
value - the value (expressed in source)
Returns:
the corresponding edited value, expressed in target units.
Throws:
java.lang.ArithmeticException

toString

public java.lang.String toString()
Standard edition of the unit converter

Overrides:
toString in class java.lang.Object


Copyright © 2009 UDS/CNRS