Package tech.units.indriya.quantity
Class MixedQuantity<Q extends Quantity<Q>>
- java.lang.Object
-
- tech.units.indriya.quantity.MixedQuantity<Q>
-
- Type Parameters:
Q- The type of the quantity.
- All Implemented Interfaces:
Serializable,tech.uom.lib.common.function.QuantityConverter<Q>
@API(status=MAINTAINED) public final class MixedQuantity<Q extends Quantity<Q>> extends Object implements tech.uom.lib.common.function.QuantityConverter<Q>, Serializable
This class represents mixed-radix quantities (like "1 hour, 5 min, 30 sec" or "6 ft, 3 in").
- Since:
- 2.1.2
- Version:
- 2.4, June 5, 2023
- Author:
- Werner Keil, Andi Huber
- See Also:
- Wolfram Language: Mixed Quantities,
Wikipedia: Mixed Numbers,
MixedRadix, Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMixedQuantity(List<Quantity<Q>> quantities)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Indicates if this mixed quantity is considered equal to the specified object (both are mixed units with same composing units in the same order).static <Q extends Quantity<Q>>
MixedQuantity<Q>fromArray(Quantity<Q>... quantities)List<Quantity<Q>>getQuantities()Gets quantities in this MixedQuantity.List<Unit<Q>>getUnits()Gets the list of units in this MixedQuantity.inthashCode()static <Q extends Quantity<Q>>
MixedQuantity<Q>of(List<Quantity<Q>> quantities)static <Q extends Quantity<Q>>
MixedQuantity<Q>of(Quantity<Q>... quantities)Quantity<Q>to(Unit<Q> unit)Returns the sum of all quantity values in this MixedQuantity converted into another (compatible) unit.StringtoString()
-
-
-
Constructor Detail
-
MixedQuantity
protected MixedQuantity(List<Quantity<Q>> quantities)
- Parameters:
quantities- - the list of quantities to construct this MixedQuantity.
-
-
Method Detail
-
of
@SafeVarargs public static <Q extends Quantity<Q>> MixedQuantity<Q> of(Quantity<Q>... quantities)
- Type Parameters:
Q-- Parameters:
quantities-- Returns:
- a
MixedQuantitywith the specifiedquantities - Throws:
IllegalArgumentException- if givenquantitiesisnullor empty or contains anynullvalues or contains quantities of mixed scale
-
fromArray
@SafeVarargs public static <Q extends Quantity<Q>> MixedQuantity<Q> fromArray(Quantity<Q>... quantities)
- Type Parameters:
Q-- Parameters:
quantities-- Returns:
- a
MixedQuantitywith the specifiedquantities - Throws:
IllegalArgumentException- if givenquantitiesisnullor empty or contains anynullvalues or contains quantities of mixed scale
-
of
public static <Q extends Quantity<Q>> MixedQuantity<Q> of(List<Quantity<Q>> quantities)
- Type Parameters:
Q-- Parameters:
quantities-- Returns:
- a
MixedQuantitywith the specifiedquantities - Throws:
IllegalArgumentException- if givenquantitiesisnullor empty or contains anynullvalues or contains quantities of mixed scale
-
getUnits
public List<Unit<Q>> getUnits()
Gets the list of units in this MixedQuantity.This list can be used in conjunction with
getQuantities()to access the entire quantity.- Returns:
- a list containing the units, not null
-
getQuantities
public List<Quantity<Q>> getQuantities()
Gets quantities in this MixedQuantity.- Returns:
- a list containing the quantities, not null
-
to
public Quantity<Q> to(Unit<Q> unit)
Returns the sum of all quantity values in this MixedQuantity converted into another (compatible) unit.- Specified by:
toin interfacetech.uom.lib.common.function.QuantityConverter<Q extends Quantity<Q>>- Parameters:
unit- theUnit unitin which the returned quantity is stated.- Returns:
- the sum of all quantities in this MixedQuantity or a new quantity stated in the specified unit.
- Throws:
ArithmeticException- if the result is inexact and the quotient has a non-terminating decimal expansion.
-
equals
public boolean equals(Object obj)
Indicates if this mixed quantity is considered equal to the specified object (both are mixed units with same composing units in the same order).
-
-