Package javax.measure.unit
Class ProductUnit<Q extends Quantity>
- java.lang.Object
-
- javax.measure.unit.Unit<Q>
-
- javax.measure.unit.DerivedUnit<Q>
-
- javax.measure.unit.ProductUnit<Q>
-
- All Implemented Interfaces:
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)
returnsMETER
.
-
-
Constructor Summary
Constructors Constructor Description ProductUnit(Unit<?> productUnit)
Copy constructor (allows for parameterization of product units).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object that)
Indicates if this product unit is considered equals to the specified object.Unit<? super Q>
getStandardUnit()
Returns thebase 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
toStandardUnit()
Returns the converter from this unit to its system unit.
-
-
-
Constructor Detail
-
ProductUnit
public ProductUnit(Unit<?> productUnit)
Copy constructor (allows for parameterization of product units).- Parameters:
productUnit
- the product unit source.- Throws:
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:
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:
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:
IndexOutOfBoundsException
- if index is out of range(index < 0 || index >= size())
.
-
equals
public boolean equals(Object that)
Indicates if this product unit is considered equals to the specified object.
-
hashCode
public int hashCode()
Description copied from class:Unit
Returns the hash code for this unit.
-
getStandardUnit
public Unit<? super Q> getStandardUnit()
Description copied from class:Unit
Returns thebase unit
,alternate unit
or product of base units and alternate units this unit is derived from. The standard unit identifies the "type" ofquantity
for which this unit is employed. For example:[code] boolean isAngularVelocity(Unit> u) { return u.getStandardUnit().equals(RADIAN.divide(SECOND)); } assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); [/code]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:
getStandardUnit
in classUnit<Q extends Quantity>
- Returns:
- the system unit this unit is derived from.
-
toStandardUnit
public UnitConverter toStandardUnit()
Description copied from class:Unit
Returns the converter from this unit to its system unit.- Specified by:
toStandardUnit
in classUnit<Q extends Quantity>
- Returns:
this.getConverterTo(this.getSystemUnit())
-
-