Package org.openjdk.jmc.common.unit
Class ScalarQuantity.LongStored<U extends TypedUnit<U>>
- java.lang.Object
-
- java.lang.Number
-
- org.openjdk.jmc.common.unit.ScalarQuantity<U>
-
- org.openjdk.jmc.common.unit.ScalarQuantity.LongStored<U>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<IQuantity>
,IDisplayable
,IItem
,IQuantity
,ITypedQuantity<U>
- Enclosing class:
- ScalarQuantity<U extends TypedUnit<U>>
public static class ScalarQuantity.LongStored<U extends TypedUnit<U>> extends ScalarQuantity<U>
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openjdk.jmc.common.unit.ScalarQuantity
ScalarQuantity.DoubleStored<U extends TypedUnit<U>>, ScalarQuantity.LongStored<U extends TypedUnit<U>>
-
-
Field Summary
Fields Modifier and Type Field Description private long
numericalValue
private static long
serialVersionUID
-
Fields inherited from class org.openjdk.jmc.common.unit.ScalarQuantity
unit
-
Fields inherited from interface org.openjdk.jmc.common.IDisplayable
AUTO, EXACT, VERBOSE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
LongStored(long numericalValue, U unit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ITypedQuantity<U>
add(ITypedQuantity<LinearUnit> addend)
long
clampedFloorIn(IUnit targetUnit)
Get thelong
value closest to the floor of the numerical quantity value that this quantity would have if expressed in the unittargetUnit
.int
clampedIntFloorIn(IUnit targetUnit)
Get theint
value closest to the floor of the numerical quantity value that this quantity would have if expressed in the unittargetUnit
.long
clampedLongValueIn(IUnit targetUnit)
Get thelong
value closest to the numerical quantity value that this quantity would have if expressed in the unittargetUnit
.int
compareTo(IQuantity other)
double
doubleValue()
Get the numerical quantity value of this quantity as adouble
.double
doubleValueIn(IUnit targetUnit)
Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit
, as adouble
.boolean
equals(java.lang.Object other)
float
floatValue()
ITypedQuantity<U>
floorQuantize(ITypedQuantity<LinearUnit> quanta)
int
hashCode()
int
intValue()
java.lang.String
localizedFormat(boolean useBreakingSpace, boolean allowCustomUnit)
long
longValue()
Get the numerical quantity value of this quantity as along
.long
longValueIn(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]
.ITypedQuantity<U>
multiply(double factor)
Returns a new quantity that is this quantity multiplied withfactor
, if this is a linear quantity.ITypedQuantity<U>
multiply(long factor)
Returns a new quantity that is this quantity multiplied withfactor
, if this is a linear quantity.java.lang.Number
numberValue()
Get the numerical quantity value that this quantity, as either aLong
or aNumber
with at least the precision ofdouble
.java.lang.Number
numberValueIn(IUnit targetUnit)
Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit
, as either aLong
or aNumber
with at least the precision ofdouble
.java.lang.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 isequal
to this quantity.double
ratioTo(IQuantity denominator)
Compute the ratio of this quantity to the givenconsequent
quantity, if both are of the same linear kind.ITypedQuantity<LinearUnit>
subtract(ITypedQuantity<U> subtrahend)
protected ITypedQuantity<U>
subtractLinear(ITypedQuantity<LinearUnit> subtrahend)
java.lang.String
toString()
-
Methods inherited from class org.openjdk.jmc.common.unit.ScalarQuantity
add, displayUsing, getType, getUnit, in, in, interactiveFormat, interactiveFormat, isLinear, longValueIn, subtract
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
numericalValue
private final long numericalValue
-
-
Constructor Detail
-
LongStored
protected LongStored(long numericalValue, U unit)
-
-
Method Detail
-
intValue
public int intValue()
- Specified by:
intValue
in classjava.lang.Number
-
longValue
public long longValue()
Description copied from interface:IQuantity
Get the numerical quantity value of this quantity as along
. This may cause truncation and loss of precision.
-
floatValue
public float floatValue()
- Specified by:
floatValue
in classjava.lang.Number
-
doubleValue
public double doubleValue()
Description copied from interface:IQuantity
Get the numerical quantity value of this quantity as adouble
. This may cause loss of precision.- Specified by:
doubleValue
in interfaceIQuantity
- Specified by:
doubleValue
in classjava.lang.Number
- Returns:
- the numerical quantity, as a
double
-
numberValue
public java.lang.Number numberValue()
Description copied from interface:IQuantity
Get the numerical quantity value that this quantity, as either aLong
or aNumber
with at least the precision ofdouble
.- Returns:
- the numerical quantity
-
longValueIn
public long longValueIn(IUnit targetUnit, long maxAbsValue) throws QuantityConversionException
Description copied from interface:IQuantity
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, anQuantityConversionException
will 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 range- See Also:
IQuantity.numberValueIn(IUnit)
-
clampedLongValueIn
public long clampedLongValueIn(IUnit targetUnit)
Description copied from interface:IQuantity
Get thelong
value 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
IQuantity.in(IUnit)
@.
IQuantity.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
- See Also:
IQuantity.numberValueIn(IUnit)
-
clampedFloorIn
public long clampedFloorIn(IUnit targetUnit)
Description copied from interface:IQuantity
Get thelong
value 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
-
clampedIntFloorIn
public int clampedIntFloorIn(IUnit targetUnit)
Description copied from interface:IQuantity
Get theint
value 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
-
doubleValueIn
public double doubleValueIn(IUnit targetUnit)
Description copied from interface:IQuantity
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
-
numberValueIn
public java.lang.Number numberValueIn(IUnit targetUnit)
Description copied from interface:IQuantity
Get the numerical quantity value that this quantity would have if expressed in the unittargetUnit
, as either aLong
or aNumber
with 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
, aLong
will be returned. Otherwise, some otherNumber
implementation, such asDouble
will be returned. Note that as a result of this conversion, precision may be lost.- Returns:
- the numerical quantity, as a
Long
if exact, otherwise as some otherNumber
- See Also:
IQuantity.clampedLongValueIn(IUnit)
-
floorQuantize
public ITypedQuantity<U> floorQuantize(ITypedQuantity<LinearUnit> quanta)
-
persistableString
public java.lang.String persistableString()
Description copied from interface:IQuantity
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 isequal
to this quantity. That is, the exact representation must be preserved.- Returns:
- a string representation independent of locale or internationalization.
-
localizedFormat
public java.lang.String localizedFormat(boolean useBreakingSpace, boolean allowCustomUnit)
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classScalarQuantity<U extends TypedUnit<U>>
-
compareTo
public int compareTo(IQuantity other)
-
equals
public boolean equals(java.lang.Object other)
- Specified by:
equals
in classScalarQuantity<U extends TypedUnit<U>>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
add
public ITypedQuantity<U> add(ITypedQuantity<LinearUnit> addend) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
subtractLinear
protected ITypedQuantity<U> subtractLinear(ITypedQuantity<LinearUnit> subtrahend)
- Specified by:
subtractLinear
in classScalarQuantity<U extends TypedUnit<U>>
-
subtract
public ITypedQuantity<LinearUnit> subtract(ITypedQuantity<U> subtrahend) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
multiply
public ITypedQuantity<U> multiply(long factor) throws java.lang.UnsupportedOperationException
Description copied from interface:IQuantity
Returns a new quantity that is this quantity multiplied withfactor
, if this is a linear quantity. Otherwise, this operation is undefined andUnsupportedOperationException
will be thrown.- Returns:
- this quantity multiplied with
factor
- Throws:
java.lang.UnsupportedOperationException
- if this quantity is not linear
-
multiply
public ITypedQuantity<U> multiply(double factor) throws java.lang.UnsupportedOperationException
Description copied from interface:IQuantity
Returns a new quantity that is this quantity multiplied withfactor
, if this is a linear quantity. Otherwise, this operation is undefined andUnsupportedOperationException
will be thrown.- Returns:
- this quantity multiplied with
factor
- Throws:
java.lang.UnsupportedOperationException
- if this quantity is not linear
-
ratioTo
public double ratioTo(IQuantity denominator) throws java.lang.UnsupportedOperationException, java.lang.IllegalArgumentException
Description copied from interface:IQuantity
Compute the ratio of this quantity to the givenconsequent
quantity, 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 adouble
fraction - Throws:
java.lang.UnsupportedOperationException
- if this quantity is not linearjava.lang.IllegalArgumentException
- ifconsequent
is not of a compatible kind of quantity
-
-