Package org.openjdk.jmc.common.unit
Class TypedUnit<U extends TypedUnit<U>>
- java.lang.Object
-
- org.openjdk.jmc.common.unit.TypedUnit<U>
-
- All Implemented Interfaces:
IUnit
- Direct Known Subclasses:
LinearUnit
,TimestampUnit
public abstract class TypedUnit<U extends TypedUnit<U>> extends Object implements IUnit
Type parameterized extension ofIUnit
. This construction exists to reduce clutter for casual users of IUnit, 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.)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TypedUnit.UnitSelector<U extends TypedUnit<U>>
-
Field Summary
-
Fields inherited from interface org.openjdk.jmc.common.unit.IUnit
EMPTY_STRING_ARRAY
-
-
Constructor Summary
Constructors Constructor Description TypedUnit()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract ITypedQuantity<U>
add(long numericalAugend, LinearUnit addendUnit, long numericalAddend)
protected ITypedQuantity<U>
addPossiblyIntegral(long numericalAugend, IScalarAffineTransform addendValueTransform, long numericalAddend)
protected abstract ITypedQuantity<U>
floorQuantize(double numericalValue, ITypedQuantity<LinearUnit> quanta)
protected abstract ITypedQuantity<U>
floorQuantize(long numericalValue, ITypedQuantity<LinearUnit> quanta)
abstract KindOfQuantity<U>
getContentType()
Get the kind of quantity of this unit.protected abstract U
getScaledUnit(LinearUnit deltaUnit)
Return a unit with the same origin (if absolute) as this unit, but with the givendeltaUnit
as its delta unit.protected abstract Class<U>
getUnitClass()
protected abstract String
localizedFormatFor(Number numericalValue, boolean useBreakingSpace, boolean allowCustomUnit)
protected abstract String
persistableStringFor(Number numericalValue)
abstract ITypedQuantity<U>
quantity(double numericalValue)
Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.abstract ITypedQuantity<U>
quantity(long numericalValue)
Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.ITypedQuantity<U>
quantity(Number value)
Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.protected abstract ITypedQuantity<LinearUnit>
subtractSame(long numericalMinuend, U subtrahendUnit, long numericalSubtrahend)
IScalarAffineTransform
valueTransformTo(IUnit targetUnit)
Get a transform for transforming numerical quantity values expressed in this unit to numerical quantity values expressed intargetUnit
.abstract IScalarAffineTransform
valueTransformTo(U targetUnit)
Get a transform for transforming numerical quantity values expressed in this unit to numerical quantity values expressed intargetUnit
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openjdk.jmc.common.unit.IUnit
getAltLocalizedNames, getAppendableSuffix, getDeltaUnit, getIdentifier, getLocalizedDescription, getLocalizedSymbol, isLinear
-
-
-
-
Method Detail
-
getScaledUnit
protected abstract U getScaledUnit(LinearUnit deltaUnit)
Return a unit with the same origin (if absolute) as this unit, but with the givendeltaUnit
as its delta unit.Linear units
will returndeltaUnit
.- Throws:
IllegalArgumentException
- ifdeltaUnit
is of the wrong kind, although linear units are not guaranteed to verify this here
-
getContentType
public abstract KindOfQuantity<U> getContentType()
Description copied from interface:IUnit
Get the kind of quantity of this unit.- Specified by:
getContentType
in interfaceIUnit
-
quantity
public ITypedQuantity<U> quantity(Number value)
Description copied from interface:IUnit
Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.
-
quantity
public abstract ITypedQuantity<U> quantity(long numericalValue)
Description copied from interface:IUnit
Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.
-
quantity
public abstract ITypedQuantity<U> quantity(double numericalValue)
Description copied from interface:IUnit
Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.
-
valueTransformTo
public IScalarAffineTransform valueTransformTo(IUnit targetUnit)
Description copied from interface:IUnit
Get a transform for transforming numerical quantity values expressed in this unit to numerical quantity values expressed intargetUnit
. This method is typically only used internally by the quantity implementations.- Specified by:
valueTransformTo
in interfaceIUnit
-
valueTransformTo
public abstract IScalarAffineTransform valueTransformTo(U targetUnit)
Get a transform for transforming numerical quantity values expressed in this unit to numerical quantity values expressed intargetUnit
. This method is typically only used internally by the quantity implementations. Note that this method differs fromvalueTransformTo(IUnit)
only by stricter typing.- Throws:
IllegalArgumentException
- iftargetUnit
is not of the same kind of quantity
-
addPossiblyIntegral
protected final ITypedQuantity<U> addPossiblyIntegral(long numericalAugend, IScalarAffineTransform addendValueTransform, long numericalAddend)
-
add
protected abstract ITypedQuantity<U> add(long numericalAugend, LinearUnit addendUnit, long numericalAddend)
-
subtractSame
protected abstract ITypedQuantity<LinearUnit> subtractSame(long numericalMinuend, U subtrahendUnit, long numericalSubtrahend)
-
floorQuantize
protected abstract ITypedQuantity<U> floorQuantize(long numericalValue, ITypedQuantity<LinearUnit> quanta)
-
floorQuantize
protected abstract ITypedQuantity<U> floorQuantize(double numericalValue, ITypedQuantity<LinearUnit> quanta)
-
localizedFormatFor
protected abstract String localizedFormatFor(Number numericalValue, boolean useBreakingSpace, boolean allowCustomUnit)
-
-