Interface IQuantity
-
- All Superinterfaces:
Comparable<IQuantity>,IDisplayable,IItem
- All Known Subinterfaces:
ITypedQuantity<U>
public interface IQuantity extends IItem, IDisplayable, Comparable<IQuantity>
-
-
Field Summary
-
Fields inherited from interface org.openjdk.jmc.common.IDisplayable
AUTO, EXACT, VERBOSE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description IQuantityadd(IQuantity addend)Returns a new quantity that is the arithmetic sum of this quantity andaddend, if such an operation is defined for this kind of quantity.longclampedFloorIn(IUnit targetUnit)Get thelongvalue closest to the floor of the numerical quantity value that this quantity would have if expressed in the unittargetUnit.intclampedIntFloorIn(IUnit targetUnit)Get theintvalue closest to the floor of the numerical quantity value that this quantity would have if expressed in the unittargetUnit.longclampedLongValueIn(IUnit targetUnit)Get thelongvalue closest to the numerical quantity value that this quantity would have if expressed in the unittargetUnit.doubledoubleValue()Get the numerical quantity value of this quantity as adouble.doubledoubleValueIn(IUnit targetUnit)Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit, as adouble.KindOfQuantity<?>getType()Get the kind of this quantity.IUnitgetUnit()IQuantityin(IUnit targetUnit)Get this quantity expressed in the unittargetUnit.StringinteractiveFormat()An exact string representation taking locale and internationalization into account.booleanisLinear()If this quantity is linear.longlongValue()Get the numerical quantity value of this quantity as along.longlongValueIn(IUnit targetUnit)Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit, rounded to a mathematical integer, if that numerical value can be represented in along.longlongValueIn(IUnit targetUnit, long maxAbsValue)Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit, rounded to a mathematical integer, if that numerical value is in the range[-maxAbsValue-1, maxAbsValue].IQuantitymultiply(double factor)Returns a new quantity that is this quantity multiplied withfactor, if this is a linear quantity.IQuantitymultiply(long factor)Returns a new quantity that is this quantity multiplied withfactor, if this is a linear quantity.NumbernumberValue()NumbernumberValueIn(IUnit targetUnit)StringpersistableString()A string representation independent of locale or internationalization, that when parsed usingKindOfQuantity.parsePersisted(String)(by this quantity's kind of quantity) yields a value that isequalto this quantity.doubleratioTo(IQuantity consequent)Compute the ratio of this quantity to the givenconsequentquantity, if both are of the same linear kind.IQuantitysubtract(IQuantity subtrahend)Returns a new quantity that is the arithmetic difference of this quantity andsubtrahend, if such an operation is defined for this kind of quantity.-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface org.openjdk.jmc.common.IDisplayable
displayUsing
-
-
-
-
Method Detail
-
getType
KindOfQuantity<?> getType()
Get the kind of this quantity.
-
getUnit
IUnit getUnit()
- Returns:
- the unit in which this quantity is expressed
-
in
IQuantity in(IUnit targetUnit)
Get this quantity expressed in the unittargetUnit. Note that as a result of this conversion, precision may be lost. Partly due to that fact, this method should generally not be used. If the ultimate goal is some pure numerical value, there are more suitable methods, some of which are listed below, which directly provides such values. In either case, the quantity returned from this method should not be kept alive, as the original quantity provides better precision.- Returns:
- a quantity, with approximately the same value as this quantity, expressed in
targetUnit - Throws:
IllegalArgumentException- iftargetUnitis not of the same kind of quantity- See Also:
doubleValueIn(IUnit),numberValueIn(IUnit),clampedLongValueIn(IUnit),ratioTo(IQuantity)
-
longValueIn
long longValueIn(IUnit targetUnit, long maxAbsValue) throws QuantityConversionException
Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit, rounded to a mathematical integer, if that numerical value is in the range[-maxAbsValue-1, maxAbsValue]. Otherwise, anQuantityConversionExceptionwill be thrown, with the violation encoded. Note that as a result of this conversion, precision may be lost.- Returns:
- the numerical quantity, as a
long - Throws:
QuantityConversionException- if the result would be out of rangeIllegalArgumentException- iftargetUnitis not of the same kind of quantity- See Also:
numberValueIn(IUnit)
-
longValueIn
long longValueIn(IUnit targetUnit) throws QuantityConversionException
Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit, rounded to a mathematical integer, if that numerical value can be represented in along. Otherwise, anQuantityConversionExceptionwill be thrown, with the violation encoded. Note that as a result of this conversion, precision may be lost.This method is equivalent to
longValueIn(IUnit, Long.MAX_VALUE).- Returns:
- the numerical quantity, as a
long - Throws:
QuantityConversionException- if the result would be out of rangeIllegalArgumentException- iftargetUnitis not of the same kind of quantity- See Also:
numberValueIn(IUnit)
-
clampedLongValueIn
long clampedLongValueIn(IUnit targetUnit)
Get thelongvalue closest to the numerical quantity value that this quantity would have if expressed in the unittargetUnit. This means that values outside the range[Long.MIN_VALUE,Long.MAX_VALUE]will be clamped to the closest extreme. Note that as a result of this conversion, precision may be lost.This method is equivalent to
in(IUnit)@.longValue(), but is preferred since it is both cheaper and its name more explicitly conveys the limitations involved.- Returns:
- the numerical quantity, as a
long - Throws:
IllegalArgumentException- iftargetUnitis not of the same kind of quantity- See Also:
numberValueIn(IUnit)
-
clampedFloorIn
long clampedFloorIn(IUnit targetUnit)
Get thelongvalue closest to the floor of the numerical quantity value that this quantity would have if expressed in the unittargetUnit. This means that values outside the range[Long.MIN_VALUE,Long.MAX_VALUE]will be clamped to the closest extreme. Note that as a result of this conversion, precision may be lost.- Returns:
- the floor of the numerical quantity, as a
long - Throws:
IllegalArgumentException- iftargetUnitis not of the same kind of quantity
-
clampedIntFloorIn
int clampedIntFloorIn(IUnit targetUnit)
Get theintvalue closest to the floor of the numerical quantity value that this quantity would have if expressed in the unittargetUnit. This means that values outside the range[Integer.MIN_VALUE,Integer.MAX_VALUE]will be clamped to the closest extreme. Note that as a result of this conversion, precision may be lost.- Returns:
- the floor of the numerical quantity, as an
int - Throws:
IllegalArgumentException- iftargetUnitis not of the same kind of quantity
-
doubleValueIn
double doubleValueIn(IUnit targetUnit)
Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit, as adouble. Note that as a result of this conversion, precision may be lost.- Returns:
- the numerical quantity, as a
double - Throws:
IllegalArgumentException- iftargetUnitis not of the same kind of quantity
-
numberValueIn
Number numberValueIn(IUnit targetUnit)
Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit, as either aLongor aNumberwith at least the precision ofdouble. If this quantity is exact, the unit conversion is known to be exact, and the result can be exactly represented in along, aLongwill be returned. Otherwise, some otherNumberimplementation, such asDoublewill be returned. Note that as a result of this conversion, precision may be lost.- Returns:
- the numerical quantity, as a
Longif exact, otherwise as some otherNumber - Throws:
IllegalArgumentException- iftargetUnitis not of the same kind of quantity- See Also:
clampedLongValueIn(IUnit)
-
longValue
long longValue()
Get the numerical quantity value of this quantity as along. This may cause truncation and loss of precision.- Returns:
- the numerical quantity, as a
long
-
doubleValue
double doubleValue()
Get the numerical quantity value of this quantity as adouble. This may cause loss of precision.- Returns:
- the numerical quantity, as a
double
-
numberValue
Number numberValue()
Get the numerical quantity value that this quantity, as either aLongor aNumberwith at least the precision ofdouble.- Returns:
- the numerical quantity
-
persistableString
String persistableString()
A string representation independent of locale or internationalization, that when parsed usingKindOfQuantity.parsePersisted(String)(by this quantity's kind of quantity) yields a value that isequalto this quantity. That is, the exact representation must be preserved.- Returns:
- a string representation independent of locale or internationalization.
-
interactiveFormat
String interactiveFormat()
An exact string representation taking locale and internationalization into account. When parsed usingKindOfQuantity.parseInteractive(String)(by this quantity's kind of quantity), in the same locale, yields a value that isequalto this quantity. That is, the exact representation must be preserved.- Returns:
- a string representation taking locale and internationalization into account.
-
isLinear
boolean isLinear()
If this quantity is linear. That is, if quantities of the same kind can be added to and subtracted from it, and the resulting quantity remains of the same kind.- Returns:
- true iff the quantity is linear
-
add
IQuantity add(IQuantity addend) throws IllegalArgumentException
Returns a new quantity that is the arithmetic sum of this quantity andaddend, if such an operation is defined for this kind of quantity. This operation is commutative, so thata.add(b)produces the same result, or throws the same kind of exception, asb.add(a).Note that if this quantity is linear, adding a quantity of the same kind is guaranteed to succeed and produces a quantity of the same kind. Also, the sum of a non-linear quantity and a linear quantity of a specific related (delta) kind of quantity is defined and produces a non-linear quantity. However, two non-linear quantities may never be added.
- Returns:
- the sum of this quantity and
addend - Throws:
IllegalArgumentException- ifaddendis not of a compatible kind of quantity
-
subtract
IQuantity subtract(IQuantity subtrahend) throws IllegalArgumentException
Returns a new quantity that is the arithmetic difference of this quantity andsubtrahend, if such an operation is defined for this kind of quantity. This operation is anti-commutative when this quantity andsubtrahendare of the same kind. That is, when the result is linear.Quantities of the same kind may be subtracted, giving a linear result. Additionally, a linear quantity may be subtracted from a non-linear quantity, provided their kinds are related.
- Returns:
- the difference of this quantity and
subtrahend - Throws:
IllegalArgumentException- ifsubtrahendis not of a compatible kind of quantity
-
multiply
IQuantity multiply(long factor) throws UnsupportedOperationException
Returns a new quantity that is this quantity multiplied withfactor, if this is a linear quantity. Otherwise, this operation is undefined andUnsupportedOperationExceptionwill be thrown.- Returns:
- this quantity multiplied with
factor - Throws:
UnsupportedOperationException- if this quantity is not linear
-
multiply
IQuantity multiply(double factor) throws UnsupportedOperationException
Returns a new quantity that is this quantity multiplied withfactor, if this is a linear quantity. Otherwise, this operation is undefined andUnsupportedOperationExceptionwill be thrown.- Returns:
- this quantity multiplied with
factor - Throws:
UnsupportedOperationException- if this quantity is not linear
-
ratioTo
double ratioTo(IQuantity consequent) throws UnsupportedOperationException, IllegalArgumentException
Compute the ratio of this quantity to the givenconsequentquantity, if both are of the same linear kind. Otherwise, this operation is undefined and an exception is thrown.- Returns:
- the ratio of this quantity to
consequent, as adoublefraction - Throws:
UnsupportedOperationException- if this quantity is not linearIllegalArgumentException- ifconsequentis not of a compatible kind of quantity
-
-