JSR-275 - Measurements and Units Specification

javax.measure.unit
Class ProductUnit<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.ProductUnit<Q>
All Implemented Interfaces:
java.io.Serializable

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

This class represents units formed by the product of rational powers of existing units.

This class maintains the canonical form of this product (simplest form after factorization). For example: METER.pow(2).divide(METER) returns METER.

Version:
3.1, April 22, 2006
Author:
Jean-Marie Dautelle
See Also:
Unit.times(Unit), Unit.divide(Unit), Unit.pow(int), Unit.root(int), Serialized Form

Field Summary
 
Fields inherited from class javax.measure.unit.Unit
ONE
 
Constructor Summary
ProductUnit(Unit productUnit)
          Copy constructor (allows for parameterization of product units).
 
Method Summary
 boolean equals(java.lang.Object that)
          Indicates if this product unit is considered equals to the specified object.
 Unit<? super Q> getSystemUnit()
          Returns the base unit, alternate unit or product of base units and alternate units this unit is derived from.
 Unit<? extends Quantity> getUnit(int index)
          Returns the unit at the specified position.
 int getUnitCount()
          Returns the number of units in this product.
 int getUnitPow(int index)
          Returns the power exponent of the unit at the specified position.
 int getUnitRoot(int index)
          Returns the root exponent of the unit at the specified position.
 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

ProductUnit

public ProductUnit(Unit productUnit)
Copy constructor (allows for parameterization of product units).

Parameters:
productUnit - the product unit source.
Throws:
java.lang.ClassCastException - if the specified unit is not a product unit.
Method Detail

getUnitCount

public int getUnitCount()
Returns the number of units in this product.

Returns:
the number of units being multiplied.

getUnit

public Unit<? extends Quantity> getUnit(int index)
Returns the unit at the specified position.

Parameters:
index - the index of the unit to return.
Returns:
the unit at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

getUnitPow

public int getUnitPow(int index)
Returns the power exponent of the unit at the specified position.

Parameters:
index - the index of the unit to return.
Returns:
the unit power exponent at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

getUnitRoot

public int getUnitRoot(int index)
Returns the root exponent of the unit at the specified position.

Parameters:
index - the index of the unit to return.
Returns:
the unit root exponent at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

equals

public boolean equals(java.lang.Object that)
Indicates if this product unit is considered equals to the specified object.

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.

getSystemUnit

public 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 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())

JSR-275 - Measurements and Units Specification

Copyright © 2007 JSR-275