Package tech.units.indriya.unit
Class ProductUnit<Q extends 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<Unit<Q>>,Unit<Q>,tech.uom.lib.common.function.Nameable,tech.uom.lib.common.function.PrefixOperator<Q>,tech.uom.lib.common.function.SymbolSupplier
public final class ProductUnit<Q extends Quantity<Q>> extends AbstractUnit<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)returnsMETRE.- Since:
- 1.0
- Version:
- 2.1, September 30, 2024
- Author:
- Jean-Marie Dautelle, Werner Keil, Andi Huber
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class tech.units.indriya.AbstractUnit
AbstractUnit.Equalizer
-
-
Field Summary
-
Fields inherited from class tech.units.indriya.AbstractUnit
ONE, scale, SYMBOL_TO_UNIT
-
-
Constructor Summary
Constructors Constructor Description ProductUnit()DefaultQuantityFactory constructor (used solely to createONEinstance).ProductUnit(Unit<?> productUnit)Copy constructor (allows for parameterization of product units).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Map<Unit<?>,Integer>getBaseUnits()DimensiongetDimension()UnitConvertergetSystemConverter()Returns the converter from this unit to its unscaledSystem Unitunit.Unit<?>getUnit(int index)Returns the unit element at the specified position.intgetUnitCount()Returns 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 Unit<?>ofPow(Unit<?> unit, int n)Returns the product unit corresponding to this unit raised to the specified exponent.static Unit<?>ofProduct(Unit<?> left, Unit<?> right)Returns the product of the specified units.static Unit<?>ofQuotient(Unit<?> left, Unit<?> right)Returns the quotient of the specified units.static Unit<?>ofRoot(Unit<?> unit, int n)Returns the product unit corresponding to the specified root of the specified unit.Unit<?>pow(int n)Returns a unit equals to this unit raised to an exponent.Unit<Q>toSystemUnit()Returns the unscaledSIunit from which this unit is derived.-
Methods inherited from class tech.units.indriya.AbstractUnit
alternate, annotate, asType, compareTo, divide, divide, divide, getActualType, getConverterTo, getConverterTo, getConverterToAny, getConverterToAny, getName, getSymbol, getSystemUnit, internalGetConverterTo, inverse, isCompatible, isEquivalentTo, isSystemUnit, multiply, multiply, multiply, parse, prefix, root, setName, setSymbol, shift, shift, toString, transform
-
-
-
-
Constructor Detail
-
ProductUnit
public ProductUnit()
DefaultQuantityFactory constructor (used solely to createONEinstance).
-
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
-
ofProduct
public static Unit<?> ofProduct(Unit<?> left, 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 Unit<?> ofQuotient(Unit<?> left, 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 Unit<?> ofRoot(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 Unit<?> ofPow(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
-
pow
public Unit<?> pow(int n)
Description copied from class:AbstractUnitReturns a unit equals to this unit raised to an exponent.
-
getUnitCount
public int getUnitCount()
Returns the number of unit elements in this product.- Returns:
- the number of unit elements.
-
getUnit
public 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
public Map<Unit<?>,Integer> getBaseUnits()
- Specified by:
getBaseUnitsin interfaceUnit<Q extends Quantity<Q>>- Specified by:
getBaseUnitsin classAbstractUnit<Q extends Quantity<Q>>
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin classAbstractUnit<Q extends Quantity<Q>>
-
toSystemUnit
public Unit<Q> toSystemUnit()
Description copied from class:AbstractUnitReturns the unscaledSIunit from which this unit is derived. The SI unit can be be used to identify a quantity given the unit. For example:static boolean isAngularVelocity(AbstractUnit> unit) { return unit.toSystemUnit().equals(RADIAN.divide(SECOND)); } assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); // Returns true.- Specified by:
toSystemUnitin classAbstractUnit<Q extends Quantity<Q>>- Returns:
- the unscaled metric unit from which this unit is derived.
-
getSystemConverter
public UnitConverter getSystemConverter()
Description copied from class:AbstractUnitReturns the converter from this unit to its unscaledSystem Unitunit.- Specified by:
getSystemConverterin classAbstractUnit<Q extends Quantity<Q>>- Returns:
getConverterTo(this.toSystemUnit())- See Also:
AbstractUnit.toSystemUnit()
-
getDimension
public Dimension getDimension()
- Specified by:
getDimensionin interfaceUnit<Q extends Quantity<Q>>- Specified by:
getDimensionin classAbstractUnit<Q extends Quantity<Q>>
-
-