Package tech.units.indriya.unit
Class ProductUnit<Q extends javax.measure.Quantity<Q>>
java.lang.Object
tech.units.indriya.AbstractUnit<Q>
tech.units.indriya.unit.ProductUnit<Q>
- Type Parameters:
Q- The type of the quantity measured by this unit.
- All Implemented Interfaces:
Serializable,Comparable<javax.measure.Unit<Q>>,javax.measure.Unit<Q>,ComparableUnit<Q>
This class represents units formed by the product of rational powers of existing physical units.
This class maintains the canonical form of this product (simplest form after factorization). For example: METRE.pow(2).divide(METRE)
returns METRE.
- Since:
- 1.0
- Version:
- 1.4.2, November 7, 2017
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classInner product element represents a rational power of a single unit.Nested classes/interfaces inherited from class tech.units.indriya.AbstractUnit
AbstractUnit.Equalizer -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ProductUnit.Element[]Holds the units composing this product unit.private static final longprivate final StringHolds the symbol for this unit.Fields inherited from class tech.units.indriya.AbstractUnit
name, ONE, SYMBOL_TO_UNIT -
Constructor Summary
ConstructorsModifierConstructorDescriptionDefaultQuantityFactory constructor (used solely to createONEinstance).ProductUnit(javax.measure.Unit<?> productUnit) Copy constructor (allows for parameterization of product units).privateProductUnit(ProductUnit.Element[] elements) Product unit constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanprivate static intgcd(int m, int n) Returns the greatest common divisor (Euclid's algorithm).javax.measure.Dimensionprivate static javax.measure.Unit<?> getInstance(ProductUnit.Element[] leftElems, ProductUnit.Element[] rightElems) Returns the unit defined from the product of the specified elements.javax.measure.UnitConverterReturns the converter from this unit to its unscaledunit.invalid reference
System Unitjavax.measure.Unit<?> getUnit(int index) Returns the unit element at the specified position.intReturns the number of unit elements in this product.intgetUnitPow(int index) Returns the power exponent of the unit element at the specified position.intgetUnitRoot(int index) Returns the root exponent of the unit element at the specified position.inthashCode()static javax.measure.Unit<?> ofPow(javax.measure.Unit<?> unit, int n) Returns the product unit corresponding to this unit raised to the specified exponent.static javax.measure.Unit<?> ofProduct(javax.measure.Unit<?> left, javax.measure.Unit<?> right) Returns the product of the specified units.static javax.measure.Unit<?> ofQuotient(javax.measure.Unit<?> left, javax.measure.Unit<?> right) Returns the quotient of the specified units.static javax.measure.Unit<?> ofRoot(javax.measure.Unit<?> unit, int n) Returns the product unit corresponding to the specified root of the specified unit.javax.measure.Unit<Q> Returns the unscaledunit from which this unit is derived.invalid reference
SIMethods inherited from class tech.units.indriya.AbstractUnit
alternate, annotate, asType, compareTo, divide, divide, divide, getActualType, getConverterTo, getConverterToAny, getName, getSystemUnit, inverse, isCompatible, isEquivalentOf, isSystemUnit, multiply, multiply, multiply, parse, pow, prefix, root, setName, setSymbol, shift, toString, transform
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
elements
Holds the units composing this product unit. -
symbol
Holds the symbol for this unit.
-
-
Constructor Details
-
ProductUnit
public ProductUnit()DefaultQuantityFactory constructor (used solely to createONEinstance). -
ProductUnit
public ProductUnit(javax.measure.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.
-
ProductUnit
Product unit constructor.- Parameters:
elements- the product elements.
-
-
Method Details
-
ofProduct
public static javax.measure.Unit<?> ofProduct(javax.measure.Unit<?> left, javax.measure.Unit<?> right) Returns the product of the specified units.- Parameters:
left- the left unit operand.right- the right unit operand.- Returns:
left * right
-
ofQuotient
public static javax.measure.Unit<?> ofQuotient(javax.measure.Unit<?> left, javax.measure.Unit<?> right) Returns the quotient of the specified units.- Parameters:
left- the dividend unit operand.right- the divisor unit operand.- Returns:
dividend / divisor
-
ofRoot
public static javax.measure.Unit<?> ofRoot(javax.measure.Unit<?> unit, int n) Returns the product unit corresponding to the specified root of the specified unit.- Parameters:
unit- the unit.n- the root's order (n > 0).- Returns:
unit^(1/nn)- Throws:
ArithmeticException- ifn == 0.
-
ofPow
public static javax.measure.Unit<?> ofPow(javax.measure.Unit<?> unit, int n) Returns the product unit corresponding to this unit raised to the specified exponent.- Parameters:
unit- the unit.nn- the exponent (nn > 0).- Returns:
unit^n
-
getUnitCount
public int getUnitCount()Returns the number of unit elements in this product.- Returns:
- the number of unit elements.
-
getUnit
public javax.measure.Unit<?> getUnit(int index) Returns the unit element at the specified position.- Parameters:
index- the index of the unit element to return.- Returns:
- the unit element at the specified position.
- Throws:
IndexOutOfBoundsException- if index is out of range(index < 0 || index >= getUnitCount()).
-
getUnitPow
public int getUnitPow(int index) Returns the power exponent of the unit element at the specified position.- Parameters:
index- the index of the unit element.- Returns:
- the unit power exponent at the specified position.
- Throws:
IndexOutOfBoundsException- if index is out of range(index < 0 || index >= getUnitCount()).
-
getUnitRoot
public int getUnitRoot(int index) Returns the root exponent of the unit element at the specified position.- Parameters:
index- the index of the unit element.- Returns:
- the unit root exponent at the specified position.
- Throws:
IndexOutOfBoundsException- if index is out of range(index < 0 || index >= getUnitCount()).
-
getBaseUnits
- Specified by:
getBaseUnitsin interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>- Specified by:
getBaseUnitsin classAbstractUnit<Q extends javax.measure.Quantity<Q>>
-
equals
- Specified by:
equalsin classAbstractUnit<Q extends javax.measure.Quantity<Q>>
-
hashCode
public int hashCode()- Specified by:
hashCodein classAbstractUnit<Q extends javax.measure.Quantity<Q>>
-
toSystemUnit
Description copied from class:AbstractUnitReturns the unscaledunit from which this unit is derived. The SI unit can be be used to identify a quantity given the unit. For example:invalid reference
SIstatic boolean isAngularVelocity(AbstractUnitinvalid input: '<'?> unit) { return unit.toSystemUnit().equals(RADIAN.divide(SECOND)); } assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); // Returns true.- Specified by:
toSystemUnitin classAbstractUnit<Q extends javax.measure.Quantity<Q>>- Returns:
- the unscaled metric unit from which this unit is derived.
-
getSystemConverter
public javax.measure.UnitConverter getSystemConverter()Description copied from class:AbstractUnitReturns the converter from this unit to its unscaledunit.invalid reference
System Unit- Specified by:
getSystemConverterin classAbstractUnit<Q extends javax.measure.Quantity<Q>>- Returns:
getConverterTo(this.toSystemUnit())- See Also:
-
getDimension
public javax.measure.Dimension getDimension()- Specified by:
getDimensionin interfacejavax.measure.Unit<Q extends javax.measure.Quantity<Q>>- Specified by:
getDimensionin classAbstractUnit<Q extends javax.measure.Quantity<Q>>
-
getInstance
private static javax.measure.Unit<?> getInstance(ProductUnit.Element[] leftElems, ProductUnit.Element[] rightElems) Returns the unit defined from the product of the specified elements.- Parameters:
leftElems- left multiplicand elements.rightElems- right multiplicand elements.- Returns:
- the corresponding unit.
-
gcd
private static int gcd(int m, int n) Returns the greatest common divisor (Euclid's algorithm).- Parameters:
m- the first number.nn- the second number.- Returns:
- the greatest common divisor.
-
getSymbol
-