Top Description Inners Fields Constructors Methods
tech.units.indriya.unit

public final Class ProductUnit<Q extends Quantity<Q>>

extends AbstractUnit<Q extends Quantity<Q>>
Class Inheritance
Type Parameters
<Q>
The type of the quantity measured by this unit.
Static Imports
javax.measure.Quantity.Scale.RELATIVE

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.

Authors
Jean-Marie Dautelle, Werner Keil, Andi Huber
Since
1.0
Version
2.1, September 30, 2024

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ProductUnit.Element

Inner product element represents a rational power of a single unit.

private static class
private static class

Field Summary

Modifier and TypeField and Description
private final ProductUnit.Element[]
elements

Holds the units composing this product unit.

private transient Lazy<Integer>
private static final long
Inherited from tech.units.indriya.AbstractUnit:
ONEscaleSYMBOL_TO_UNIT

Constructor Summary

AccessConstructor and Description
public
ProductUnit()

DefaultQuantityFactory constructor (used solely to create ONE instance).

public
ProductUnit(Unit<?>
the product unit source.
productUnit
)

Copy constructor (allows for parameterization of product units).

private
ProductUnit(ProductUnit.Element[]
the product elements.
elements
)

Product unit constructor.

Method Summary

Modifier and TypeMethod and Description
private int
public boolean
equals(Object
the reference object with which to compare.
obj
)

Implements abstract tech.units.indriya.AbstractUnit.equals.

Indicates whether some other object is "equal to" this one.

private static int

Returns:

the greatest common divisor.
gcd
(int
the first number.
m
,
int n)

Returns the greatest common divisor (Euclid's algorithm).

public Map<Unit<?>, Integer>
getBaseUnits()

Implements abstract tech.units.indriya.AbstractUnit.getBaseUnits.

Implements javax.measure.Unit.getBaseUnits.

Returns the base units and their exponent whose product is this unit, or null if this unit is a base unit (not a product of existing units).

public Dimension
getDimension()

Implements abstract tech.units.indriya.AbstractUnit.getDimension.

Implements javax.measure.Unit.getDimension.

Returns the dimension of this unit.

private static Unit<?>

Returns:

the corresponding unit.
getInstance
(ProductUnit.Element[]
left multiplicand elements.
leftElems
,
ProductUnit.Element[]
right multiplicand elements.
rightElems
)

Returns the unit defined from the product of the specified elements.

public UnitConverter
getSystemConverter()

Implements abstract tech.units.indriya.AbstractUnit.getSystemConverter.

Returns the converter from this unit to its unscaled System Unit unit.

public Unit<?>

Returns:

the unit element at the specified position.
getUnit
(int
the index of the unit element to return.
index
)

Returns the unit element at the specified position.

public int

Returns:

the number of unit elements.
getUnitCount
()

Returns the number of unit elements in this product.

public int

Returns:

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

Returns the power exponent of the unit element at the specified position.

public int

Returns:

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

Returns the root exponent of the unit element at the specified position.

public int
hashCode()

Implements abstract tech.units.indriya.AbstractUnit.hashCode.

Returns a hash code value for this object.

public static Unit<?>

Returns:

unit^n
ofPow
(Unit<?>
the unit.
unit
,
int n)

Returns the product unit corresponding to this unit raised to the specified exponent.

public static Unit<?>

Returns:

left * right
ofProduct
(Unit<?>
the left unit operand.
left
,
Unit<?>
the right unit operand.
right
)

Returns the product of the specified units.

public static Unit<?>

Returns:

dividend / divisor
ofQuotient
(Unit<?>
the dividend unit operand.
left
,
Unit<?>
the divisor unit operand.
right
)

Returns the quotient of the specified units.

public static Unit<?>

Returns:

unit^(1/nn)
ofRoot
(Unit<?>
the unit.
unit
,
int
the root's order (n > 0).
n
)

Returns the product unit corresponding to the specified root of the specified unit.

public Unit<?>
pow(int
the exponent.
n
)

Overrides tech.units.indriya.AbstractUnit.pow.

Implements javax.measure.Unit.pow.

Returns a unit equals to this unit raised to an exponent.

private void
public Unit<Q>
toSystemUnit()

Implements abstract tech.units.indriya.AbstractUnit.toSystemUnit.

Returns the unscaled SI unit from which this unit is derived.

private Object
Inherited from tech.units.indriya.AbstractUnit:
alternateannotateasTypecompareTodividedividedividegetActualTypegetConverterTogetConverterTogetConverterToAnygetConverterToAnygetNamegetSymbolgetSystemUnitinternalGetConverterToinverseisCompatibleisEquivalentToisSystemUnitmultiplymultiplymultiplyparseprefixrootsetNamesetSymbolshiftshifttoStringtransform

Field Detail

elementsback to summary
private final ProductUnit.Element[] elements

Holds the units composing this product unit.

Implementation Note:
considered immutable after constructor was called
hashCodeback to summary
private transient Lazy<Integer> hashCode
serialVersionUIDback to summary
private static final long serialVersionUID

Hides tech.units.indriya.AbstractUnit.serialVersionUID.

Constructor Detail

ProductUnitback to summary
public ProductUnit()

DefaultQuantityFactory constructor (used solely to create ONE instance).

ProductUnitback to summary
public ProductUnit(Unit<?> productUnit)

Copy constructor (allows for parameterization of product units).

Parameters
productUnit:Unit<?>

the product unit source.

Exceptions
ClassCastException:
if the specified unit is not a product unit.
ProductUnitback to summary
private ProductUnit(ProductUnit.Element[] elements)

Product unit constructor.

Parameters
elements:ProductUnit.Element[]

the product elements.

Method Detail

calculateHashCodeback to summary
private int calculateHashCode()
equalsback to summary
public boolean equals(Object obj)

Implements abstract tech.units.indriya.AbstractUnit.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
gcdback to summary
private static int gcd(int m, int n)

Returns the greatest common divisor (Euclid's algorithm).

Parameters
m:int

the first number.

Returns:int

the greatest common divisor.

getBaseUnitsback to summary
public Map<Unit<?>, Integer> getBaseUnits()

Implements abstract tech.units.indriya.AbstractUnit.getBaseUnits.

Implements javax.measure.Unit.getBaseUnits.

Doc from javax.measure.Unit.getBaseUnits.

Returns the base units and their exponent whose product is this unit, or null if this unit is a base unit (not a product of existing units).

Returns:Map<Unit<?>, Integer>

the base units and their exponent making up this unit.

Annotations
@Override
getDimensionback to summary
public Dimension getDimension()

Implements abstract tech.units.indriya.AbstractUnit.getDimension.

Implements javax.measure.Unit.getDimension.

Doc from javax.measure.Unit.getDimension.

Returns the dimension of this unit. Two units u1 and u2 are compatible if and only if u1.getDimension().equals(u2.getDimension()).

Returns:Dimension

the dimension of this unit.

Annotations
@Override
getInstanceback to summary
private static Unit<?> getInstance(ProductUnit.Element[] leftElems, ProductUnit.Element[] rightElems)

Returns the unit defined from the product of the specified elements.

Parameters
leftElems:ProductUnit.Element[]

left multiplicand elements.

rightElems:ProductUnit.Element[]

right multiplicand elements.

Returns:Unit<?>

the corresponding unit.

Annotations
@SuppressWarnings:rawtypes
getSystemConverterback to summary
public UnitConverter getSystemConverter()

Implements abstract tech.units.indriya.AbstractUnit.getSystemConverter.

Doc from tech.units.indriya.AbstractUnit.getSystemConverter.

Returns the converter from this unit to its unscaled System Unit unit.

Returns:UnitConverter

getConverterTo(this.toSystemUnit())

Annotations
@Override
getUnitback to summary
public Unit<?> getUnit(int index)

Returns the unit element at the specified position.

Parameters
index:int

the index of the unit element to return.

Returns:Unit<?>

the unit element at the specified position.

Exceptions
IndexOutOfBoundsException:
if index is out of range (index < 0 || index >= getUnitCount()).
getUnitCountback to summary
public int getUnitCount()

Returns the number of unit elements in this product.

Returns:int

the number of unit elements.

getUnitPowback to summary
public int getUnitPow(int index)

Returns the power exponent of the unit element at the specified position.

Parameters
index:int

the index of the unit element.

Returns:int

the unit power exponent at the specified position.

Exceptions
IndexOutOfBoundsException:
if index is out of range (index < 0 || index >= getUnitCount()).
getUnitRootback to summary
public int getUnitRoot(int index)

Returns the root exponent of the unit element at the specified position.

Parameters
index:int

the index of the unit element.

Returns:int

the unit root exponent at the specified position.

Exceptions
IndexOutOfBoundsException:
if index is out of range (index < 0 || index >= getUnitCount()).
hashCodeback to summary
public int hashCode()

Implements abstract tech.units.indriya.AbstractUnit.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
ofPowback to summary
public static Unit<?> ofPow(Unit<?> unit, int n)

Returns the product unit corresponding to this unit raised to the specified exponent.

Parameters
unit:Unit<?>

the unit.

Returns:Unit<?>

unit^n

ofProductback to summary
public static Unit<?> ofProduct(Unit<?> left, Unit<?> right)

Returns the product of the specified units.

Parameters
left:Unit<?>

the left unit operand.

right:Unit<?>

the right unit operand.

Returns:Unit<?>

left * right

ofQuotientback to summary
public static Unit<?> ofQuotient(Unit<?> left, Unit<?> right)

Returns the quotient of the specified units.

Parameters
left:Unit<?>

the dividend unit operand.

right:Unit<?>

the divisor unit operand.

Returns:Unit<?>

dividend / divisor

ofRootback to summary
public static Unit<?> ofRoot(Unit<?> unit, int n)

Returns the product unit corresponding to the specified root of the specified unit.

Parameters
unit:Unit<?>

the unit.

n:int

the root's order (n > 0).

Returns:Unit<?>

unit^(1/nn)

Exceptions
ArithmeticException:
if n == 0.
powback to summary
public Unit<?> pow(int n)

Overrides tech.units.indriya.AbstractUnit.pow.

Implements javax.measure.Unit.pow.

Doc from tech.units.indriya.AbstractUnit.pow.

Returns a unit equals to this unit raised to an exponent.

Parameters
n:int

the exponent.

Returns:Unit<?>

the result of raising this unit to the exponent.

Annotations
@Override
readObjectback to summary
private void readObject(ObjectInputStream stream) throws InvalidObjectException
toSystemUnitback to summary
public Unit<Q> toSystemUnit()

Implements abstract tech.units.indriya.AbstractUnit.toSystemUnit.

Doc from tech.units.indriya.AbstractUnit.toSystemUnit.

Returns the unscaled SI unit 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.

Returns:Unit<Q>

the unscaled metric unit from which this unit is derived.

Annotations
@SuppressWarnings:unchecked
@Override
writeReplaceback to summary
private Object writeReplace()
tech.units.indriya.unit back to summary

private final Class ProductUnit.Element

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Inner product element represents a rational power of a single unit.

Field Summary

Modifier and TypeField and Description
private final int
pow

Holds the power exponent.

private final int
root

Holds the root exponent.

private static final long
private final Unit<?>
unit

Holds the single unit.

Constructor Summary

AccessConstructor and Description
private
Element(Unit<?>
the unit.
unit
,
int
the power exponent.
pow
,
int
the root exponent.
root
)

Structural constructor.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int

Returns:

the power exponent of the single unit.
getPow
()

Returns the power exponent.

public int

Returns:

the root exponent of the single unit.
getRoot
()

Returns the root exponent.

public Unit<?>

Returns:

the single unit.
getUnit
()

Returns this element's unit.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

powback to summary
private final int pow

Holds the power exponent.

rootback to summary
private final int root

Holds the root exponent.

serialVersionUIDback to summary
private static final long serialVersionUID
unitback to summary
private final Unit<?> unit

Holds the single unit.

Constructor Detail

Elementback to summary
private Element(Unit<?> unit, int pow, int root)

Structural constructor.

Parameters
unit:Unit<?>

the unit.

pow:int

the power exponent.

root:int

the root exponent.

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getPowback to summary
public int getPow()

Returns the power exponent. The power exponent can be negative but is always different from zero.

Returns:int

the power exponent of the single unit.

getRootback to summary
public int getRoot()

Returns the root exponent. The root exponent is always greater than zero.

Returns:int

the root exponent of the single unit.

getUnitback to summary
public Unit<?> getUnit()

Returns this element's unit.

Returns:Unit<?>

the single unit.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
tech.units.indriya.unit back to summary

private final Class ProductUnit.ElementUtil

extends Object
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static boolean
private static int
private static ProductUnit.Element[]
copyAndSort(final ProductUnit.Element[] elements)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ElementUtilback to summary
private ElementUtil()

Method Detail

arrayEqualsArbitraryOrderback to summary
private static boolean arrayEqualsArbitraryOrder(final ProductUnit.Element[] e0, final ProductUnit.Element[] e1)
compareback to summary
private static int compare(final ProductUnit.Element e0, final ProductUnit.Element e1)
copyAndSortback to summary
private static ProductUnit.Element[] copyAndSort(final ProductUnit.Element[] elements)
tech.units.indriya.unit back to summary

private Class ProductUnit.SerializationProxy

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private final ProductUnit.Element[]
private static final long
private final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

elementsback to summary
private final ProductUnit.Element[] elements
serialVersionUIDback to summary
private static final long serialVersionUID
symbolback to summary
private final String symbol

Constructor Detail

SerializationProxyback to summary
private SerializationProxy(ProductUnit<?> productUnit)

Method Detail

readResolveback to summary
private Object readResolve()