JScience v2.0

org.jscience.physics.units
Class BaseUnit<Q extends Quantity>

java.lang.Object
  extended by org.jscience.physics.units.Unit<Q>
      extended by org.jscience.physics.units.BaseUnit<Q>
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Currency

public class BaseUnit<Q extends Quantity>
extends Unit<Q>

This class represents the building blocks on top of which all others units are created.

Base units are typically mutually independent. Although, in specialized context (e.g. relativistic context), conversions between base units is possible (Ref. setDimension(org.jscience.physics.units.Dimension, org.jscience.physics.units.Converter)).

Examples of base units:


         METER = new BaseUnit<Length>("m", Dimension.LENGTH, Converter.IDENTITY);
         KILOGRAM = new BaseUnit<Mass>("kg", Dimension.MASS, Converter.IDENTITY);
         SECOND = new BaseUnit<Duration>("s", Dimension.TIME, Converter.IDENTITY);
     

Version:
1.1, May 24, 2005
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jscience.physics.units.Unit
ONE
 
Constructor Summary
BaseUnit(java.lang.String symbol, Dimension dimension, Converter transform)
          Creates a new base unit having the specified symbol.
 
Method Summary
protected  boolean equalsImpl(java.lang.Object that)
          Indicates if the specified unit can be considered equals to the one specified (for unicity purpose).
protected  Unit<Q> getParentUnitImpl()
          Returns the parent units this unit is derived from.
 java.lang.String getSymbol()
          Returns the symbol for this base unit.
protected  int hashCodeImpl()
          Returns the hash code for this unit (calculated only once as units are unique).
 void setDimension(Dimension dimension, Converter transform)
          Sets the local dimension of this base unit.
protected  Converter toParentUnitImpl()
          Returns the converter to the parent unit.
 
Methods inherited from class org.jscience.physics.units.Unit
alias, alternate, compound, divide, equals, getBaseUnits, getConverterTo, getDimension, getInstance, getInstances, getParentUnit, hashCode, inverse, isCompatible, label, plus, pow, readResolve, root, times, times, toBaseUnits, toParentUnit, toString, toText, transform, valueOf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BaseUnit

public BaseUnit(java.lang.String symbol,
                Dimension dimension,
                Converter transform)
Creates a new base unit having the specified symbol. Any unit having the specified symbol as label loses its label (symbols and labels cannot conflict).

Parameters:
symbol - the symbol of this base unit.
dimension - the default dimension for this unit.
transform - the default intrinsic dimensional transform.
Throws:
java.lang.IllegalArgumentException - if the specified symbol is already used.
Method Detail

getSymbol

public final java.lang.String getSymbol()
Returns the symbol for this base unit.

Returns:
this base unit symbol.

setDimension

public void setDimension(Dimension dimension,
                         Converter transform)
Sets the local dimension of this base unit. For example:
 LocalContext.enter(); // Ensures that setting is local to current thread.
 try {
     SI.METER.setDimension(TIME, new MultiplyConverter(1e9 / c));
     // In this high-energy context, length and time are compatible,
     // they have the same "ns" dimensional unit.
 } finally {
     LocalContext.exit();
 }

Parameters:
dimension - the unit identifying the new dimension of this base unit.
transform - the dimensional intrinsic transform for this base unit (typically a multiply converter).

equalsImpl

protected boolean equalsImpl(java.lang.Object that)
Description copied from class: Unit
Indicates if the specified unit can be considered equals to the one specified (for unicity purpose).

Specified by:
equalsImpl in class Unit<Q extends Quantity>
Returns:
true if this unit is considered equal to that unit; false otherwise.

hashCodeImpl

protected int hashCodeImpl()
Description copied from class: Unit
Returns the hash code for this unit (calculated only once as units are unique).

Specified by:
hashCodeImpl in class Unit<Q extends Quantity>
Returns:
this unit hashcode value.

getParentUnitImpl

protected Unit<Q> getParentUnitImpl()
Description copied from class: Unit
Returns the parent units this unit is derived from.

Specified by:
getParentUnitImpl in class Unit<Q extends Quantity>
Returns:
the parent unit or this if this unit is a base unit or a product of base units.

toParentUnitImpl

protected Converter toParentUnitImpl()
Description copied from class: Unit
Returns the converter to the parent unit.

Specified by:
toParentUnitImpl in class Unit<Q extends Quantity>
Returns:
the converter to Unit.getParentUnitImpl()

JScience v2.0

Copyright © 2005 JScience.