Package org.openjdk.jmc.common.unit
Class LinearUnit
- All Implemented Interfaces:
Comparable<LinearUnit>
,IUnit
- Direct Known Subclasses:
LinearUnit.Custom
A measurement unit for a particular kind of quantity.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.openjdk.jmc.common.unit.TypedUnit
TypedUnit.UnitSelector<U extends TypedUnit<U>>
-
Field Summary
Fields inherited from interface org.openjdk.jmc.common.unit.IUnit
EMPTY_STRING_ARRAY
-
Constructor Summary
ConstructorsConstructorDescriptionLinearUnit
(LinearKindOfQuantity kindOfQuantity, String unitId, ScaleFactor factorToAtom, String unitSymbol, String unitDesc, String... altNames) -
Method Summary
Modifier and TypeMethodDescriptionprotected ITypedQuantity<LinearUnit>
add
(long numericalAugend, LinearUnit addendUnit, long numericalAddend) int
compareTo
(LinearUnit other) customParseInteractive
(String interactiveQuantity) Parse an interactive string, likeKindOfQuantity.parseInteractive(String)
, with the addition that this unit is accepted, even if not generally by the kind of quantity.boolean
protected ITypedQuantity<LinearUnit>
floorQuantize
(double numericalValue, ITypedQuantity<LinearUnit> quanta) protected ITypedQuantity<LinearUnit>
floorQuantize
(long numericalValue, ITypedQuantity<LinearUnit> quanta) String[]
Get alternate names for content assist matching.getAppendableSuffix
(boolean useBreakingSpace) Convenience method for (localized) formatters, to prepend a space toIUnit.getLocalizedSymbol()
, if needed.Get the kind of quantity of this unit.Get the unit that the difference between two quantities in this unit will have.Persistable identifier, not to show interactively.In the real world, units are sometimes used ambiguously (like MB).Symbols for units are most often not locale dependent, but there are exceptions (like in French).protected LinearUnit
getScaledUnit
(LinearUnit deltaUnit) Return a unit with the same origin (if absolute) as this unit, but with the givendeltaUnit
as its delta unit.protected final Class<LinearUnit>
int
hashCode()
protected boolean
isCustom()
boolean
isLinear()
If this unit is linear.protected String
localizedFormatFor
(Number numericalValue, boolean useBreakingSpace, boolean allowCustomUnit) protected String
persistableStringFor
(Number numericalValue) quantity
(double numericalValue) Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.quantity
(long numericalValue) Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.protected ITypedQuantity<LinearUnit>
subtractSame
(long numericalMinuend, LinearUnit subtrahendUnit, long numericalSubtrahend) toString()
valueTransformTo
(LinearUnit targetUnit) Get a transform for transforming numerical quantity values expressed in this unit to numerical quantity values expressed intargetUnit
.Methods inherited from class org.openjdk.jmc.common.unit.TypedUnit
addPossiblyIntegral, quantity, valueTransformTo
-
Constructor Details
-
LinearUnit
public LinearUnit(LinearKindOfQuantity kindOfQuantity, String unitId, ScaleFactor factorToAtom, String unitSymbol, String unitDesc, String... altNames)
-
-
Method Details
-
getUnitClass
Description copied from class:TypedUnit
Get the typedClass
object of the actualTypedUnit
subclassU
. This method is intended to simplify generic code, written inTypedUnit
, to go from loosely typed arguments into stricter parameterized arguments.- Specified by:
getUnitClass
in classTypedUnit<LinearUnit>
-
getContentType
Description copied from interface:IUnit
Get the kind of quantity of this unit.- Specified by:
getContentType
in interfaceIUnit
- Specified by:
getContentType
in classTypedUnit<LinearUnit>
-
getDeltaUnit
Description copied from interface:IUnit
Get the unit that the difference between two quantities in this unit will have. For linear units, this is always the unit itself.- Specified by:
getDeltaUnit
in interfaceIUnit
- Returns:
- the linear unit in which deltas of this unit is expressed
-
getScaledUnit
Description copied from class:TypedUnit
Return a unit with the same origin (if absolute) as this unit, but with the givendeltaUnit
as its delta unit.Linear units
will returndeltaUnit
.- Specified by:
getScaledUnit
in classTypedUnit<LinearUnit>
-
getAppendableSuffix
Description copied from interface:IUnit
Convenience method for (localized) formatters, to prepend a space toIUnit.getLocalizedSymbol()
, if needed.- Specified by:
getAppendableSuffix
in interfaceIUnit
- Parameters:
useBreakingSpace
- to use breaking space instead of the default, non-breaking space (only for edit)- Returns:
- a localized string to be appended to a number when displaying a quantity (including space, if non-empty).
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<LinearUnit>
-
quantity
Description copied from interface:IUnit
Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.- Specified by:
quantity
in interfaceIUnit
- Specified by:
quantity
in classTypedUnit<LinearUnit>
-
quantity
Description copied from interface:IUnit
Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue
.- Specified by:
quantity
in interfaceIUnit
- Specified by:
quantity
in classTypedUnit<LinearUnit>
-
valueTransformTo
Description copied from class:TypedUnit
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 fromTypedUnit.valueTransformTo(IUnit)
only by stricter typing.- Specified by:
valueTransformTo
in classTypedUnit<LinearUnit>
-
isLinear
public boolean isLinear()Description copied from interface:IUnit
If this unit is linear. That is, if quantities expressed in this unit and in units of the same kind can be added to and subtracted from each other, and the resulting quantity remains of the same kind. -
add
protected ITypedQuantity<LinearUnit> add(long numericalAugend, LinearUnit addendUnit, long numericalAddend) - Specified by:
add
in classTypedUnit<LinearUnit>
-
subtractSame
protected ITypedQuantity<LinearUnit> subtractSame(long numericalMinuend, LinearUnit subtrahendUnit, long numericalSubtrahend) - Specified by:
subtractSame
in classTypedUnit<LinearUnit>
-
floorQuantize
protected ITypedQuantity<LinearUnit> floorQuantize(long numericalValue, ITypedQuantity<LinearUnit> quanta) - Specified by:
floorQuantize
in classTypedUnit<LinearUnit>
-
floorQuantize
protected ITypedQuantity<LinearUnit> floorQuantize(double numericalValue, ITypedQuantity<LinearUnit> quanta) - Specified by:
floorQuantize
in classTypedUnit<LinearUnit>
-
toString
-
getIdentifier
Description copied from interface:IUnit
Persistable identifier, not to show interactively.- Specified by:
getIdentifier
in interfaceIUnit
- Returns:
- the persistable (locale independent) identifier, or (possibly) null if this unit isn't persistable.
-
getLocalizedSymbol
Description copied from interface:IUnit
Symbols for units are most often not locale dependent, but there are exceptions (like in French). Also, besides real persistable units, temporary units are sometimes constructed for display purposes, and they might vary due to internationalization, and conceivably language.While symbols normally don't contain any white space, spacing occur in circumstances like custom units. In this case, it is important that they are non-breaking spaces (
- Specified by:
getLocalizedSymbol
in interfaceIUnit
- Returns:
- the localized symbol of this unit.
-
getLocalizedDescription
Description copied from interface:IUnit
In the real world, units are sometimes used ambiguously (like MB). This description is intended to remove such ambiguity where needed.- Specified by:
getLocalizedDescription
in interfaceIUnit
- Returns:
- a (possibly) localized unambiguous description of this unit
-
getAltLocalizedNames
Description copied from interface:IUnit
Get alternate names for content assist matching. Note that these should never contain non-breaking spaces, only regular (breaking) spaces.- Specified by:
getAltLocalizedNames
in interfaceIUnit
- Returns:
- an array, possibly empty, of names with which to match for content assist, never
null
.
-
isCustom
protected boolean isCustom() -
asWellKnownQuantity
- Returns:
- a quantity with the same magnitude as this unit, defined in a non-custom unit (possibly itself)
-
persistableStringFor
- Specified by:
persistableStringFor
in classTypedUnit<LinearUnit>
-
localizedFormatFor
protected String localizedFormatFor(Number numericalValue, boolean useBreakingSpace, boolean allowCustomUnit) - Specified by:
localizedFormatFor
in classTypedUnit<LinearUnit>
-
customParseInteractive
public ITypedQuantity<LinearUnit> customParseInteractive(String interactiveQuantity) throws QuantityConversionException Parse an interactive string, likeKindOfQuantity.parseInteractive(String)
, with the addition that this unit is accepted, even if not generally by the kind of quantity. Only guaranteed to be able to parse strings produced bylocalizedFormatFor(Number, boolean, boolean)
for this unit or byIQuantity.interactiveFormat()
for quantities of this kind of quantity, and in the same locale. Only use this for interactive input, never for persisted strings.- Parameters:
interactiveQuantity
- interactive string to parse- Returns:
- a valid quantity for this kind of quantity
- Throws:
QuantityConversionException
- if parsing failed
-