Top Description Methods
tech.units.indriya

public Interface ComparableQuantity<Q extends Quantity<Q>>

extends Quantity<Q extends Quantity<Q>>, Comparable<Quantity<Q extends Quantity<Q>>>, QuantityConverter<Q extends Quantity<Q>>, Serializable
Known Direct Implementers
tech.units.indriya.AbstractQuantity
Type Parameters
<Q>
the quantity type
Imports
java.io.Serializable, javax.measure.Quantity, .Unit, tech.uom.lib.common.function.QuantityConverter

Quantity that adapts Comparable to the Quantity interface. For use in other quantities, when supposed to work on Comparables. It extends Quantity with Comparable and Serializable
Authors
otaviojava, werner
Since
1.0
Version
2.6, November 14, 2024
See Also
Quantity

Method Summary

Modifier and TypeMethod and Description
public ComparableQuantity<Q>
add(Quantity<Q>
the Quantity to be added.
that
)

Redeclares javax.measure.Quantity.add.

Returns the sum of this Quantity with the one specified.

public <T extends Quantity<T>> ComparableQuantity<T>
asType(Class<T>
the quantity class identifying the nature of the quantity.
type
)

Redeclares javax.measure.Quantity.asType.

Casts this quantity to a parameterized unit of specified nature or throw a ClassCastException if the dimension of the specified quantity and this measure unit's dimension do not match.

public ComparableQuantity<?>
divide(Quantity<?>
the Quantity divisor.
that
)

Redeclares javax.measure.Quantity.divide.

Returns the quotient of this Quantity divided by the Quantity specified.

public ComparableQuantity<Q>
divide(Number
the Number divisor.
that
)

Redeclares javax.measure.Quantity.divide.

Returns the quotient of this Quantity divided by the Number specified.

public <T extends Quantity<T>, E extends Quantity<E>> ComparableQuantity<E>

Returns:

the QuantityOperations multiplied and converted
divide
(Quantity<T>
quantity to be multiplied
that
,
Class<E>
quantity to be converted
asTypeQuantity
)

Multiply and cast the ComparableQuantity

public ComparableQuantity<?>
inverse()

Redeclares javax.measure.Quantity.inverse.

Returns a Quantity that is the multiplicative inverse of this Quantity, having reciprocal value and reciprocal unit as given by this.getUnit().inverse().

public <T extends Quantity<T>> ComparableQuantity<T>
inverse(Class<T>
Quantity to be converted
quantityClass
)

invert and already cast to defined quantityClass

public boolean

Returns:

true if this > that.
isGreaterThan
(Quantity<Q>
the quantity<Q> to be compared with this instance.
that
)

Compares two instances of Quantity.

public boolean

Returns:

true if this >= that.
isGreaterThanOrEqualTo
(Quantity<Q>
the quantity<Q> to be compared with this instance.
that
)

Compares two instances of Quantity, converting the unit if necessary.

public boolean

Returns:

true if this < that.
isLessThan
(Quantity<Q>
the quantity<Q> to be compared with this instance.
that
)

Compares two instances of Quantity, converting the unit if necessary.

public boolean

Returns:

true if this <= that.
isLessThanOrEqualTo
(Quantity<Q>
the quantity<Q> to be compared with this instance.
that
)

Compares two instances of Quantity, converting the unit if necessary.

public ComparableQuantity<?>
multiply(Quantity<?>
the Quantity multiplicand.
multiplier
)

Redeclares javax.measure.Quantity.multiply.

Returns the product of this Quantity with the one specified.

public ComparableQuantity<Q>
multiply(Number
the Number multiplicand.
multiplier
)

Redeclares javax.measure.Quantity.multiply.

Returns the product of this Quantity with the Number value specified.

public <T extends Quantity<T>, E extends Quantity<E>> ComparableQuantity<E>

Returns:

the QuantityOperations multiplied and converted
multiply
(Quantity<T>
quantity to be divided
that
,
Class<E>
quantity to be converted
asTypeQuantity
)

Divide and cast the ComparableQuantity

public ComparableQuantity<Q>
subtract(Quantity<Q>
the Quantity to be subtracted.
that
)

Redeclares javax.measure.Quantity.subtract.

Returns the difference between this Quantity and the one specified.

public ComparableQuantity<Q>
to(Unit<Q>
the Unit unit in which the returned quantity is stated.
unit
)

Redeclares javax.measure.Quantity.to, tech.uom.lib.common.function.QuantityConverter.to.

Returns this Quantity converted into another (compatible) Unit.

Inherited from java.lang.Comparable:
compareTo
Inherited from javax.measure.Quantity:
getScalegetUnitgetValueisEquivalentTonegatetoSystemUnit

Method Detail

addback to summary
public ComparableQuantity<Q> add(Quantity<Q> that)

Redeclares javax.measure.Quantity.add.

Doc from javax.measure.Quantity.add.

Returns the sum of this Quantity with the one specified. The result shall be as if this quantity and the given addend were converted to system unit before to be added, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Quantity<Q>

the Quantity to be added.

Returns:ComparableQuantity<Q>

this + addend.

See Also
Quantity#add(Quantity)
asTypeback to summary
public <T extends Quantity<T>> ComparableQuantity<T> asType(Class<T> type) throws ClassCastException

Redeclares javax.measure.Quantity.asType.

Doc from javax.measure.Quantity.asType.

Casts this quantity to a parameterized unit of specified nature or throw a ClassCastException if the dimension of the specified quantity and this measure unit's dimension do not match. For example:

Quantity<Length> length = Quantities.getQuantity("2 km").asType(Length.class); or Quantity<Speed> C = length.multiply(299792458).divide(second).asType(Speed.class);

Parameters
<T>
The type of the quantity.
type:Class<T>

the quantity class identifying the nature of the quantity.

Returns:ComparableQuantity<T>

this quantity parameterized with the specified type.

Exceptions
ClassCastException:
if the dimension of this unit is different from the specified quantity dimension.
See Also
Quantity#asType(Class)
divideback to summary
public ComparableQuantity<?> divide(Quantity<?> that)

Redeclares javax.measure.Quantity.divide.

Doc from javax.measure.Quantity.divide.

Returns the quotient of this Quantity divided by the Quantity specified. The result shall be as if this quantity and the given divisor were converted to system unit before to be divided, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Quantity<?>

the Quantity divisor.

Returns:ComparableQuantity<?>

this / divisor.

See Also
Quantity#divide(Quantity)
divideback to summary
public ComparableQuantity<Q> divide(Number that)

Redeclares javax.measure.Quantity.divide.

Doc from javax.measure.Quantity.divide.

Returns the quotient of this Quantity divided by the Number specified. The result shall be as if this quantity was converted to system unit before to be divided, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Number

the Number divisor.

Returns:ComparableQuantity<Q>

this / divisor.

See Also
Quantity#divide(Number)
divideback to summary
public <T extends Quantity<T>, E extends Quantity<E>> ComparableQuantity<E> divide(Quantity<T> that, Class<E> asTypeQuantity)

Multiply and cast the ComparableQuantity

Parameters
that:Quantity<T>

quantity to be multiplied

asTypeQuantity:Class<E>

quantity to be converted

Returns:ComparableQuantity<E>

the QuantityOperations multiplied and converted

See Also
Quantity#divide(Quantity), Quantity#asType(Class)
inverseback to summary
public ComparableQuantity<?> inverse()

Redeclares javax.measure.Quantity.inverse.

Doc from javax.measure.Quantity.inverse.

Returns a Quantity that is the multiplicative inverse of this Quantity, having reciprocal value and reciprocal unit as given by this.getUnit().inverse().

Returns:ComparableQuantity<?>

reciprocal Quantity

See Also
Quantity#inverse()
inverseback to summary
public <T extends Quantity<T>> ComparableQuantity<T> inverse(Class<T> quantityClass)

invert and already cast to defined quantityClass

Parameters
quantityClass:Class<T>

Quantity to be converted

See Also
Quantity#inverse(), Quantity#asType(Class)
isGreaterThanback to summary
public boolean isGreaterThan(Quantity<Q> that)

Compares two instances of Quantity. Conversion of unit can happen if necessary

Parameters
that:Quantity<Q>

the quantity<Q> to be compared with this instance.

Returns:boolean

true if this > that.

Exceptions
NullPointerException:
if the that is null
isGreaterThanOrEqualToback to summary
public boolean isGreaterThanOrEqualTo(Quantity<Q> that)

Compares two instances of Quantity, converting the unit if necessary.

Parameters
that:Quantity<Q>

the quantity<Q> to be compared with this instance.

Returns:boolean

true if this >= that.

Exceptions
NullPointerException:
if the that is null
isLessThanback to summary
public boolean isLessThan(Quantity<Q> that)

Compares two instances of Quantity, converting the unit if necessary.

Parameters
that:Quantity<Q>

the quantity<Q> to be compared with this instance.

Returns:boolean

true if this < that.

Exceptions
NullPointerException:
if the quantity is null
isLessThanOrEqualToback to summary
public boolean isLessThanOrEqualTo(Quantity<Q> that)

Compares two instances of Quantity, converting the unit if necessary.

Parameters
that:Quantity<Q>

the quantity<Q> to be compared with this instance.

Returns:boolean

true if this <= that.

Exceptions
NullPointerException:
if the quantity is null
multiplyback to summary
public ComparableQuantity<?> multiply(Quantity<?> multiplier)

Redeclares javax.measure.Quantity.multiply.

Doc from javax.measure.Quantity.multiply.

Returns the product of this Quantity with the one specified. The result shall be as if this quantity and the given multiplicand were converted to system unit before to be multiplied, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
multiplier:Quantity<?>

the Quantity multiplicand.

Returns:ComparableQuantity<?>

this * multiplicand.

See Also
Quantity#multiply(Quantity)
multiplyback to summary
public ComparableQuantity<Q> multiply(Number multiplier)

Redeclares javax.measure.Quantity.multiply.

Doc from javax.measure.Quantity.multiply.

Returns the product of this Quantity with the Number value specified. The result shall be as if this quantity was converted to system unit before to be multiplied, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
multiplier:Number

the Number multiplicand.

Returns:ComparableQuantity<Q>

this * multiplicand.

See Also
Quantity#multiply(Number)
multiplyback to summary
public <T extends Quantity<T>, E extends Quantity<E>> ComparableQuantity<E> multiply(Quantity<T> that, Class<E> asTypeQuantity)

Divide and cast the ComparableQuantity

Parameters
that:Quantity<T>

quantity to be divided

asTypeQuantity:Class<E>

quantity to be converted

Returns:ComparableQuantity<E>

the QuantityOperations multiplied and converted

See Also
QuantityOperations, QuantityOperations#of(Quantity, Class), Quantity#asType(Class), Quantity#multiply(Quantity)
subtractback to summary
public ComparableQuantity<Q> subtract(Quantity<Q> that)

Redeclares javax.measure.Quantity.subtract.

Doc from javax.measure.Quantity.subtract.

Returns the difference between this Quantity and the one specified. The result shall be as if this quantity and the given subtrahend were converted to system unit before to be subtracted, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Quantity<Q>

the Quantity to be subtracted.

Returns:ComparableQuantity<Q>

this - subtrahend.

See Also
Quantity#subtract(Quantity)
toback to summary
public ComparableQuantity<Q> to(Unit<Q> unit)

Redeclares javax.measure.Quantity.to, tech.uom.lib.common.function.QuantityConverter.to.

Doc from javax.measure.Quantity.to.

Returns this Quantity converted into another (compatible) Unit.

Parameters
unit:Unit<Q>

the Unit unit in which the returned quantity is stated.

Returns:ComparableQuantity<Q>

this quantity or a new quantity equivalent to this quantity stated in the specified unit.

See Also
Quantity#to(Unit)