Java Units API
Build 2004-02-06

javax.units
Class BaseUnit

Object
  extended byUnit
      extended byBaseUnit
All Implemented Interfaces:
Serializable

public class BaseUnit
extends Unit

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

Base units are mutually independent; although some implementation may support conversions between base units by allowing the dimensional unit of a base unit to be changed (ref. optional operation: setDimension(javax.units.Unit, javax.units.Converter)).

Examples of base units:


         METER = BaseUnit.getInstance("m");
         KILOGRAM = BaseUnit.getInstance("kg");
         SECOND = BaseUnit.getInstance("s");
         AMPERE = BaseUnit.getInstance("A");
     

See Also:
Serialized Form

Field Summary
 
Fields inherited from class Unit
ONE
 
Constructor Summary
protected BaseUnit(String symbol)
          Creates a base unit with the specified symbol.
 
Method Summary
 boolean equals(Object that)
          Indicates if this unit is equal to the object specified.
 Unit getBaseUnits()
           
static BaseUnit getInstance(String symbol)
          Returns the base unit with the specified symbol.
 String getSymbol()
          Returns the symbol for this base unit.
 Unit getSystemUnit()
          Returns the system unit for this unit.
 void setDimension(Unit unit, Converter toDimension)
          Optional operation: Sets the dimensional unit of this base unit.
 
Methods inherited from class Unit
add, alternate, appendTo, divide, getConverterTo, getDimension, getInstance, getInstances, hashCode, isCompatible, isSystemUnit, multiply, multiply, pow, readResolve, root, searchSymbol, toString, valueOf
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BaseUnit

protected BaseUnit(String symbol)
Creates a base unit with the specified symbol.

Parameters:
symbol - the symbol of this base unit.
Method Detail

getInstance

public static BaseUnit getInstance(String symbol)
Returns the base unit with the specified symbol. If the base unit does not already exist, then it is created.

Parameters:
symbol - the base unit symbol.
Returns:
the corresponding base unit.
Throws:
IllegalArgumentException - if the specified symbol is currently associated to a different type of unit.

getSymbol

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

Returns:
this base unit's symbol.

setDimension

public void setDimension(Unit unit,
                         Converter toDimension)
Optional operation: Sets the dimensional unit of this base unit. By default a base unit's dimension is itself. It is possible to set the dimension to any other unit. The only constraint being that distinct dimensional units should be independent from each other (e.g. if the dimensional unit for meter is "ns", then the dimensional unit for second should be "ns" as well). For example:
     SI.METER.setDimension(SI.NANO(SI.SECOND),
                           new MultiplyConverter(1e9 / c));
     SI.SECOND.setDimension(SI.NANO(SI.SECOND),
                            new MultiplyConverter(1e9));
     // In this high-energy context, length and time are compatible,
     // they have the same "ns" dimensional unit.
 }

Note: Changing the dimensional units, makes possible conversions otherwise prohibited (e.g. conversion between meters and seconds in a relativistic context).

Parameters:
unit - the unit identifying the new dimension of this base unit.
toDimension - the converter to the specified dimensional unit.
Throws:
UnsupportedOperationException - if this operation is not supported by this implementation.

getSystemUnit

public Unit getSystemUnit()
Description copied from class: Unit
Returns the system unit for this unit. The system unit identifies the nature of the quantity being measured using this unit.

Note: Having the same system units is not sufficient to ensure that a converter exists between the two units (e.g. °C/m and K/m).

Specified by:
getSystemUnit in class Unit
Returns:
the system unit for this unit.
See Also:
Unit.isSystemUnit()

equals

public boolean equals(Object that)
Description copied from class: Unit
Indicates if this unit is equal to the object specified. Units are unique and immutable, therefore users might want to use == to test for equality.

Specified by:
equals in class Unit
Parameters:
that - the object to compare for equality.
Returns:
true if this unit and the specified object are considered equal; false otherwise.

getBaseUnits

public Unit getBaseUnits()

Java Units API
Build 2004-02-06

Symbols, terms and definitions
JSR-108 project