Top Description Fields Constructors Methods
tech.units.indriya.quantity

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

extends Object
implements QuantityConverter<Q extends Quantity<Q>>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, tech.uom.lib.common.function.QuantityConverter
Annotations
@API
status:MAINTAINED
Type Parameters
<Q>
The type of the quantity.
Static Imports
org.apiguardian.api.API.Status.MAINTAINED

This class represents mixed-radix quantities (like "1 hour, 5 min, 30 sec" or "6 ft, 3 in").

Authors
Werner Keil, Andi Huber
Since
2.1.2
Version
2.4, June 5, 2023
See Also
Wolfram Language: Mixed Quantities, Wikipedia: Mixed Numbers, MixedRadix

Field Summary

Modifier and TypeField and Description
private Quantity.Scale
private Unit<Q>
private MixedRadix<Q>
private final Object[]
private final List<Quantity<Q>>
private static final long
private final List<Unit<Q>>

Constructor Summary

AccessConstructor and Description
protected
MixedQuantity(final List<Quantity<Q>>
- the list of quantities to construct this MixedQuantity.
quantities
)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this and obj are considered equal; falseotherwise.
equals
(Object
the object to compare for equality.
obj
)

Overrides java.lang.Object.equals.

Indicates if this mixed quantity is considered equal to the specified object (both are mixed units with same composing units in the same order).

public static <Q extends Quantity<Q>> MixedQuantity<Q>

Returns:

a MixedQuantity with the specified quantities
fromArray
(Quantity<Q>... quantities)

public List<Quantity<Q>>

Returns:

a list containing the quantities, not null
getQuantities
()

Gets quantities in this MixedQuantity.

public List<Unit<Q>>

Returns:

a list containing the units, not null
getUnits
()

Gets the list of units in this MixedQuantity.

private static void
private static <Q extends Quantity<Q>> void
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public static <Q extends Quantity<Q>> MixedQuantity<Q>

Returns:

a MixedQuantity with the specified quantities
of
(Quantity<Q>... quantities)

public static <Q extends Quantity<Q>> MixedQuantity<Q>

Returns:

a MixedQuantity with the specified quantities
of
(List<Quantity<Q>> quantities)

public Quantity<Q>

Returns:

the sum of all quantities in this MixedQuantity or a new quantity stated in the specified unit.
to
(Unit<Q>
the Unit unit in which the returned quantity is stated.
unit
)

Implements tech.uom.lib.common.function.QuantityConverter.to.

Returns the sum of all quantity values in this MixedQuantity converted into another (compatible) unit.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

commonScaleback to summary
private Quantity.Scale commonScale
leastSignificantUnitback to summary
private Unit<Q> leastSignificantUnit
mixedRadixIfPossibleback to summary
private MixedRadix<Q> mixedRadixIfPossible
quantityArrayback to summary
private final Object[] quantityArray
quantityListback to summary
private final List<Quantity<Q>> quantityList
serialVersionUIDback to summary
private static final long serialVersionUID
unitListback to summary
private final List<Unit<Q>> unitList

Constructor Detail

MixedQuantityback to summary
protected MixedQuantity(final List<Quantity<Q>> quantities)
Parameters
quantities:List<Quantity<Q>>

- the list of quantities to construct this MixedQuantity.

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Indicates if this mixed quantity is considered equal to the specified object (both are mixed units with same composing units in the same order).

Parameters
obj:Object

the object to compare for equality.

Returns:boolean

true if this and obj are considered equal; falseotherwise.

fromArrayback to summary
public static <Q extends Quantity<Q>> MixedQuantity<Q> fromArray(Quantity<Q>... quantities)
Returns:MixedQuantity<Q>

a MixedQuantity with the specified quantities

Annotations
@SafeVarargs
Exceptions
IllegalArgumentException:
if given quantities is null or empty or contains any null values or contains quantities of mixed scale
getQuantitiesback to summary
public List<Quantity<Q>> getQuantities()

Gets quantities in this MixedQuantity.

Returns:List<Quantity<Q>>

a list containing the quantities, not null

getUnitsback to summary
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:List<Unit<Q>>

a list containing the units, not null

guardAgainstIllegalQuantitiesArgumentback to summary
private static void guardAgainstIllegalQuantitiesArgument(Quantity<?>[] quantities)
guardAgainstIllegalQuantitiesArgumentback to summary
private static <Q extends Quantity<Q>> void guardAgainstIllegalQuantitiesArgument(List<Quantity<Q>> quantities)
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
ofback to summary
public static <Q extends Quantity<Q>> MixedQuantity<Q> of(Quantity<Q>... quantities)
Returns:MixedQuantity<Q>

a MixedQuantity with the specified quantities

Annotations
@SafeVarargs
Exceptions
IllegalArgumentException:
if given quantities is null or empty or contains any null values or contains quantities of mixed scale
ofback to summary
public static <Q extends Quantity<Q>> MixedQuantity<Q> of(List<Quantity<Q>> quantities)
Returns:MixedQuantity<Q>

a MixedQuantity with the specified quantities

Exceptions
IllegalArgumentException:
if given quantities is null or empty or contains any null values or contains quantities of mixed scale
toback to summary
public Quantity<Q> to(Unit<Q> unit)

Implements tech.uom.lib.common.function.QuantityConverter.to.

Returns the sum of all quantity values in this MixedQuantity converted into another (compatible) unit.

Parameters
unit:Unit<Q>

the Unit unit in which the returned quantity is stated.

Returns:Quantity<Q>

the sum of all quantities in this MixedQuantity or a new quantity stated in the specified unit.

Annotations
@Override
Exceptions
ArithmeticException:
if the result is inexact and the quotient has a non-terminating decimal expansion.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override