JSR-275 - Measurements and Units Specification

javax.measure.unit
Class AlternateUnit<Q extends Quantity>

java.lang.Object
  extended by javax.measure.unit.Unit<Q>
      extended by javax.measure.unit.DerivedUnit<Q>
          extended by javax.measure.unit.AlternateUnit<Q>
All Implemented Interfaces:
java.io.Serializable

public final class AlternateUnit<Q extends Quantity>
extends DerivedUnit<Q>

This class represents the units used in expressions to distinguish between quantities of a different nature but of the same dimensions.

Examples of alternate units:

     Unit<Angle> RADIAN = new AlternateUnit<Angle>("rad", ONE);
     Unit<Force> NEWTON = new AlternateUnit<Force>("N", METER.times(KILOGRAM).divide(SECOND.pow(2)));
     Unit<Pressure> PASCAL = new AlternateUnit<Pressure>("Pa", NEWTON.divide(METER.pow(2)));
     

Version:
3.1, April 22, 2006
Author:
Jean-Marie Dautelle
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.measure.unit.Unit
ONE
 
Constructor Summary
AlternateUnit(java.lang.String symbol, Unit parent)
          Creates an alternate unit for the specified unit identified by the specified symbol.
 
Method Summary
 boolean equals(java.lang.Object that)
          Indicates if this alternate unit is considered equals to the specified object (both are alternate units with equal symbol, equal base units and equal converter to base units).
 Unit<? super Q> getParent()
          Returns the parent unit from which this alternate unit is derived (a system unit itself).
 java.lang.String getSymbol()
          Returns the symbol for this alternate unit.
 Unit<? super Q> getSystemUnit()
          Returns the base unit, alternate unit or product of base units and alternate units this unit is derived from.
 int hashCode()
          Returns the hash code for this unit.
 UnitConverter toSystemUnit()
          Returns the converter from this unit to its system unit.
 
Methods inherited from class javax.measure.unit.Unit
asType, compound, divide, divide, divide, getConverterTo, getDimension, inverse, isCompatible, plus, pow, root, times, times, times, toString, transform, valueOf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AlternateUnit

public AlternateUnit(java.lang.String symbol,
                     Unit parent)
Creates an alternate unit for the specified unit identified by the specified symbol.

Parameters:
symbol - the symbol for this alternate unit.
parent - the system unit from which this alternate unit is derived.
Throws:
java.lang.IllegalArgumentException - if the specified parent unit is not a system unit (base unit, alternate unit or rational product of base units and alternate units).
java.lang.IllegalArgumentException - if the specified symbol is associated to a different unit.
Method Detail

getSymbol

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

Returns:
this alternate unit symbol.

getParent

public final Unit<? super Q> getParent()
Returns the parent unit from which this alternate unit is derived (a system unit itself).

Returns:
the parent of the alternate unit.

getSystemUnit

public final Unit<? super Q> getSystemUnit()
Description copied from class: Unit
Returns the base unit, alternate unit or product of base units and alternate units this unit is derived from. The system unit identifies the "type" of quantity for which this unit is employed. For example:
    boolean isAngularVelocity(Unit<?> u) {
       return u.getSystemUnit().equals(RADIAN.divide(SECOND));
    }
    assert(REVOLUTION.divide(MINUTE).isAngularVelocity());  
 

Note: Having the same system unit 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<Q extends Quantity>
Returns:
the system unit this unit is derived from.

toSystemUnit

public final UnitConverter toSystemUnit()
Description copied from class: Unit
Returns the converter from this unit to its system unit.

Specified by:
toSystemUnit in class Unit<Q extends Quantity>
Returns:
this.getConverterTo(this.getSystemUnit())

equals

public boolean equals(java.lang.Object that)
Indicates if this alternate unit is considered equals to the specified object (both are alternate units with equal symbol, equal base units and equal converter to base units).

Specified by:
equals in class Unit<Q extends Quantity>
Parameters:
that - the object to compare for equality.
Returns:
true if this and that are considered equals; falseotherwise.

hashCode

public int hashCode()
Description copied from class: Unit
Returns the hash code for this unit.

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

JSR-275 - Measurements and Units Specification

Copyright © 2007 JSR-275