Package org.openjdk.jmc.common.unit
Class LinearUnit
- java.lang.Object
-
- org.openjdk.jmc.common.unit.TypedUnit<LinearUnit>
-
- org.openjdk.jmc.common.unit.LinearUnit
-
- All Implemented Interfaces:
java.lang.Comparable<LinearUnit>,IUnit
- Direct Known Subclasses:
LinearUnit.Custom
public class LinearUnit extends TypedUnit<LinearUnit> implements java.lang.Comparable<LinearUnit>
A measurement unit for a particular kind of quantity.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classLinearUnit.Custom-
Nested classes/interfaces inherited from class org.openjdk.jmc.common.unit.TypedUnit
TypedUnit.UnitSelector<U extends TypedUnit<U>>
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String[]altNamesprivate java.lang.StringbreakingSuffixprivate ScaleFactorfactorToAtomprivate java.lang.StringidSuffixprivate LinearKindOfQuantitykindOfQuantityprivate java.lang.StringnonBreakingSuffixprivate java.util.Map<java.lang.String,? extends LinearUnit>parseMapprivate java.lang.StringunitDescriptionprivate java.lang.StringunitIdprivate java.lang.StringunitSymbol-
Fields inherited from interface org.openjdk.jmc.common.unit.IUnit
EMPTY_STRING_ARRAY
-
-
Constructor Summary
Constructors Constructor Description LinearUnit(LinearKindOfQuantity kindOfQuantity, java.lang.String unitId, ScaleFactor factorToAtom, java.lang.String unitSymbol, java.lang.String unitDesc, java.lang.String... altNames)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ITypedQuantity<LinearUnit>add(long numericalAugend, LinearUnit addendUnit, long numericalAddend)ITypedQuantity<LinearUnit>asWellKnownQuantity()intcompareTo(LinearUnit other)ITypedQuantity<LinearUnit>customParseInteractive(java.lang.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.booleanequals(java.lang.Object other)protected ITypedQuantity<LinearUnit>floorQuantize(double numericalValue, ITypedQuantity<LinearUnit> quanta)private longfloorQuantize(long value, long alignment)protected ITypedQuantity<LinearUnit>floorQuantize(long numericalValue, ITypedQuantity<LinearUnit> quanta)java.lang.String[]getAltLocalizedNames()Get alternate names for content assist matching.java.lang.StringgetAppendableSuffix(boolean useBreakingSpace)Convenience method for (localized) formatters, to prepend a space toIUnit.getLocalizedSymbol(), if needed.LinearKindOfQuantitygetContentType()Get the kind of quantity of this unit.LinearUnitgetDeltaUnit()Get the unit that the difference between two quantities in this unit will have.java.lang.StringgetIdentifier()Persistable identifier, not to show interactively.java.lang.StringgetLocalizedDescription()In the real world, units are sometimes used ambiguously (like MB).java.lang.StringgetLocalizedSymbol()Symbols for units are most often not locale dependent, but there are exceptions (like in French).protected LinearUnitgetScaledUnit(LinearUnit deltaUnit)Return a unit with the same origin (if absolute) as this unit, but with the givendeltaUnitas its delta unit.protected java.lang.Class<LinearUnit>getUnitClass()inthashCode()protected booleanisCustom()booleanisLinear()If this unit is linear.protected java.lang.StringlocalizedFormatFor(java.lang.Number numericalValue, boolean useBreakingSpace, boolean allowCustomUnit)protected java.lang.StringpersistableStringFor(java.lang.Number numericalValue)ITypedQuantity<LinearUnit>quantity(double numericalValue)Create a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue.ITypedQuantity<LinearUnit>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)java.lang.StringtoString()private ScaleFactorvalueFactorToAtom()ScaleFactorvalueTransformTo(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
-
-
-
-
Field Detail
-
kindOfQuantity
private final LinearKindOfQuantity kindOfQuantity
-
factorToAtom
private final ScaleFactor factorToAtom
-
unitId
private final java.lang.String unitId
-
idSuffix
private final java.lang.String idSuffix
-
unitSymbol
private final java.lang.String unitSymbol
-
nonBreakingSuffix
private final java.lang.String nonBreakingSuffix
-
breakingSuffix
private final java.lang.String breakingSuffix
-
unitDescription
private final java.lang.String unitDescription
-
altNames
private final java.lang.String[] altNames
-
parseMap
private final java.util.Map<java.lang.String,? extends LinearUnit> parseMap
-
-
Constructor Detail
-
LinearUnit
public LinearUnit(LinearKindOfQuantity kindOfQuantity, java.lang.String unitId, ScaleFactor factorToAtom, java.lang.String unitSymbol, java.lang.String unitDesc, java.lang.String... altNames)
-
-
Method Detail
-
getUnitClass
protected final java.lang.Class<LinearUnit> getUnitClass()
Description copied from class:TypedUnitGet the typedClassobject of the actualTypedUnitsubclassU. This method is intended to simplify generic code, written inTypedUnit, to go from loosely typed arguments into stricter parameterized arguments.- Specified by:
getUnitClassin classTypedUnit<LinearUnit>
-
getContentType
public LinearKindOfQuantity getContentType()
Description copied from interface:IUnitGet the kind of quantity of this unit.- Specified by:
getContentTypein interfaceIUnit- Specified by:
getContentTypein classTypedUnit<LinearUnit>
-
getDeltaUnit
public LinearUnit getDeltaUnit()
Description copied from interface:IUnitGet the unit that the difference between two quantities in this unit will have. For linear units, this is always the unit itself.- Specified by:
getDeltaUnitin interfaceIUnit- Returns:
- the linear unit in which deltas of this unit is expressed
-
getScaledUnit
protected LinearUnit getScaledUnit(LinearUnit deltaUnit)
Description copied from class:TypedUnitReturn a unit with the same origin (if absolute) as this unit, but with the givendeltaUnitas its delta unit.Linear unitswill returndeltaUnit.- Specified by:
getScaledUnitin classTypedUnit<LinearUnit>
-
getAppendableSuffix
public java.lang.String getAppendableSuffix(boolean useBreakingSpace)
Description copied from interface:IUnitConvenience method for (localized) formatters, to prepend a space toIUnit.getLocalizedSymbol(), if needed.- Specified by:
getAppendableSuffixin 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
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
compareTo
public int compareTo(LinearUnit other)
- Specified by:
compareToin interfacejava.lang.Comparable<LinearUnit>
-
quantity
public ITypedQuantity<LinearUnit> quantity(long numericalValue)
Description copied from interface:IUnitCreate a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue.- Specified by:
quantityin interfaceIUnit- Specified by:
quantityin classTypedUnit<LinearUnit>
-
quantity
public ITypedQuantity<LinearUnit> quantity(double numericalValue)
Description copied from interface:IUnitCreate a quantity expressed in this unit and with a numerical quantity value equal tonumericalValue.- Specified by:
quantityin interfaceIUnit- Specified by:
quantityin classTypedUnit<LinearUnit>
-
valueTransformTo
public ScaleFactor valueTransformTo(LinearUnit targetUnit)
Description copied from class:TypedUnitGet 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:
valueTransformToin classTypedUnit<LinearUnit>
-
valueFactorToAtom
private ScaleFactor valueFactorToAtom()
-
isLinear
public boolean isLinear()
Description copied from interface:IUnitIf 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:
addin classTypedUnit<LinearUnit>
-
subtractSame
protected ITypedQuantity<LinearUnit> subtractSame(long numericalMinuend, LinearUnit subtrahendUnit, long numericalSubtrahend)
- Specified by:
subtractSamein classTypedUnit<LinearUnit>
-
floorQuantize
private long floorQuantize(long value, long alignment)
-
floorQuantize
protected ITypedQuantity<LinearUnit> floorQuantize(long numericalValue, ITypedQuantity<LinearUnit> quanta)
- Specified by:
floorQuantizein classTypedUnit<LinearUnit>
-
floorQuantize
protected ITypedQuantity<LinearUnit> floorQuantize(double numericalValue, ITypedQuantity<LinearUnit> quanta)
- Specified by:
floorQuantizein classTypedUnit<LinearUnit>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getIdentifier
public java.lang.String getIdentifier()
Description copied from interface:IUnitPersistable identifier, not to show interactively.- Specified by:
getIdentifierin interfaceIUnit- Returns:
- the persistable (locale independent) identifier, or (possibly) null if this unit isn't persistable.
-
getLocalizedSymbol
public java.lang.String getLocalizedSymbol()
Description copied from interface:IUnitSymbols 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:
getLocalizedSymbolin interfaceIUnit- Returns:
- the localized symbol of this unit.
-
getLocalizedDescription
public java.lang.String getLocalizedDescription()
Description copied from interface:IUnitIn the real world, units are sometimes used ambiguously (like MB). This description is intended to remove such ambiguity where needed.- Specified by:
getLocalizedDescriptionin interfaceIUnit- Returns:
- a (possibly) localized unambiguous description of this unit
-
getAltLocalizedNames
public java.lang.String[] getAltLocalizedNames()
Description copied from interface:IUnitGet alternate names for content assist matching. Note that these should never contain non-breaking spaces, only regular (breaking) spaces.- Specified by:
getAltLocalizedNamesin interfaceIUnit- Returns:
- an array, possibly empty, of names with which to match for content assist, never
null.
-
isCustom
protected boolean isCustom()
-
asWellKnownQuantity
public ITypedQuantity<LinearUnit> asWellKnownQuantity()
- Returns:
- a quantity with the same magnitude as this unit, defined in a non-custom unit (possibly itself)
-
persistableStringFor
protected java.lang.String persistableStringFor(java.lang.Number numericalValue)
- Specified by:
persistableStringForin classTypedUnit<LinearUnit>
-
localizedFormatFor
protected java.lang.String localizedFormatFor(java.lang.Number numericalValue, boolean useBreakingSpace, boolean allowCustomUnit)- Specified by:
localizedFormatForin classTypedUnit<LinearUnit>
-
customParseInteractive
public ITypedQuantity<LinearUnit> customParseInteractive(java.lang.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
-
-