Package org.openjdk.jmc.common.unit
Interface ITypedQuantity<U extends TypedUnit<U>>
-
- All Superinterfaces:
Comparable<IQuantity>
,IDisplayable
,IItem
,IQuantity
public interface ITypedQuantity<U extends TypedUnit<U>> extends IQuantity
Type parameterized extension ofIQuantity
. This construction exists to reduce clutter for casual users of IQuantity, while still providing type safety for internal implementations. (Proposed "self-variance" extensions to Java, in JDK 9 or beyond, may directly support this with a single interface.)
-
-
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 ITypedQuantity<U>
add(ITypedQuantity<LinearUnit> addend)
ITypedQuantity<U>
floorQuantize(ITypedQuantity<LinearUnit> quanta)
KindOfQuantity<U>
getType()
Get the kind of this quantity.U
getUnit()
ITypedQuantity<U>
in(U targetUnit)
Get this quantity expressed in the unittargetUnit
.String
interactiveFormat(boolean allowCustomUnit)
String
localizedFormat(boolean useBreakingSpace, boolean allowCustomUnit)
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.ITypedQuantity<LinearUnit>
subtract(ITypedQuantity<U> subtrahend)
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface org.openjdk.jmc.common.IDisplayable
displayUsing
-
Methods inherited from interface org.openjdk.jmc.common.unit.IQuantity
add, clampedFloorIn, clampedIntFloorIn, clampedLongValueIn, doubleValue, doubleValueIn, in, interactiveFormat, isLinear, longValue, longValueIn, longValueIn, numberValue, numberValueIn, persistableString, ratioTo, subtract
-
-
-
-
Method Detail
-
getType
KindOfQuantity<U> getType()
Description copied from interface:IQuantity
Get the kind of this quantity.
-
getUnit
U getUnit()
-
in
ITypedQuantity<U> in(U targetUnit)
Get this quantity expressed in the unittargetUnit
. Note that as a result of this conversion, precision may be lost. Note that this method differs fromIQuantity.in(IUnit)
only by stricter typing.- Returns:
- a quantity, with approximately the same value as this quantity, expressed in
targetUnit
- Throws:
IllegalArgumentException
- iftargetUnit
is not of the same kind of quantity
-
add
ITypedQuantity<U> add(ITypedQuantity<LinearUnit> addend) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
subtract
ITypedQuantity<LinearUnit> subtract(ITypedQuantity<U> subtrahend) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
multiply
ITypedQuantity<U> multiply(long factor) throws 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.- Specified by:
multiply
in interfaceIQuantity
- Returns:
- this quantity multiplied with
factor
- Throws:
UnsupportedOperationException
- if this quantity is not linear
-
multiply
ITypedQuantity<U> multiply(double factor) throws 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.- Specified by:
multiply
in interfaceIQuantity
- Returns:
- this quantity multiplied with
factor
- Throws:
UnsupportedOperationException
- if this quantity is not linear
-
floorQuantize
ITypedQuantity<U> floorQuantize(ITypedQuantity<LinearUnit> quanta)
-
interactiveFormat
String interactiveFormat(boolean allowCustomUnit)
-
localizedFormat
String localizedFormat(boolean useBreakingSpace, boolean allowCustomUnit)
-
-