Class LinearKindOfQuantity
- java.lang.Object
- 
- org.openjdk.jmc.common.unit.ContentType<IQuantity>
- 
- org.openjdk.jmc.common.unit.KindOfQuantity<LinearUnit>
- 
- org.openjdk.jmc.common.unit.LinearKindOfQuantity
 
 
 
- 
- All Implemented Interfaces:
- IDescribable,- IType<IQuantity>,- IConstraint<IQuantity>,- IPersister<IQuantity>
 
 public class LinearKindOfQuantity extends KindOfQuantity<LinearUnit> The kind of a linear (scalar) physical quantity. Closely related to the dimension of a quantity, but we separate them further to be able to use units specific to certain kinds of quantities. In particular, Hertz for (clock) frequency. We are mainly interested in the commensurability of quantities, to display them in the same graph. So when the dimension suffices we do not need to introduce additional kinds of quantities. (Although we should strive to follow VIM.)Each kind of quantity has a single "atom unit" which may be used with prefixes. Where applicable, this unit is the SI base unit with any prefix stripped (that is, "kg" is the base unit, but the atom unit is "g"). According to BIPM/VIM above, units that are not formed by a prefix and the atom unit may be permitted, but are treated as off-system units. This means that they cannot have prefixes. (Also, SI only permits a specified set of off-system units to be used with SI, in order to avoid ambiguity. For instance, since there's a unit "Pa", for Pascal, and prefixes "P" for Peta and "E" for Exa, no in-system unit may be designated by "a", and no off-system unit may be designated with "EPa".) To avoid future problems, where we might persist a unit without content type, we should stick to this. Note that there's a relevant specification for representing units, SI as well as conventional, without ambiguity, in ASCII, with or without case sensitivity, see UCUM. We should strive for "limited conformance" with this specification. That is, it will hardly be worth the trouble of parsing every possible UCUM expression. (There's an Eclipse project for that, UOMo, but it has too much dependencies.) But what we produce when persisting quantities and units should be valid UCUM expressions. That will allow us to export data into a standardized format. And also to switch to a full UCUM implementation, should a suitable one become available. 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classLinearKindOfQuantity.AutoFormatterstatic classLinearKindOfQuantity.DualUnitFormatterstatic interfaceLinearKindOfQuantity.LinearUnitSelector- 
Nested classes/interfaces inherited from class org.openjdk.jmc.common.unit.KindOfQuantityKindOfQuantity.ExactFormatter<U extends TypedUnit<U>>, KindOfQuantity.VerboseFormatter<U extends TypedUnit<U>>
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected Collection<LinearUnit>allUnitsprotected LinearUnitatomUnitprotected StringatomUnitNameprotected Collection<LinearUnit>commonUnitsprotected Map<String,LinearUnit>interactiveSymbolToUnitMapprotected Map<Object,LinearUnit>unitCacheprotected LinearKindOfQuantity.LinearUnitSelectorunitSelector- 
Fields inherited from class org.openjdk.jmc.common.unit.ContentTypem_identifier
 
- 
 - 
Constructor SummaryConstructors Constructor Description LinearKindOfQuantity(String id, String atomUnitId)Create a new linear kind of quantity, with content type identifieridand sole unit identifieratomUnitId.LinearKindOfQuantity(String id, String atomUnitId, P minPrefix, P maxPrefix)Create a new linear kind of quantity, with content type identifieridand atom unit identifieratomUnitId, using prefixes in the rangeminPrefixtomaxPrefix.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddUnit(LinearUnit unit)Add a common unit (displayed to the user when selecting a unit).protected voidaddUnit(LinearUnit unit, boolean common)Add a unit so that it is available for parsing and content assist, optionally also for direct selection by users.Collection<LinearUnit>getAllUnits()protected ScaleFactorgetBestScaleFactorFor(long value)LinearUnitgetCachedUnit(Object key)Collection<LinearUnit>getCommonUnits()LinearUnitgetDefaultUnit()KindOfQuantity<LinearUnit>getDeltaKind()IFormatter<IQuantity>getFormatterResolving(IRange<IQuantity> range)Get a formatter with sufficient resolution to produce unique strings for both ends ofrange, and consecutive equally spaced quantities.LinearUnitgetLargestExactUnit(IQuantity quantity)Get the largest unit, if any, in which this quantity can be expressed exactly, typically with an integer.static NumberFormatgetNumberFormat(boolean interactive)Get a thread local configuredNumberFormatsuitable for display or interactive formatting, or interactive parsing.LinearUnitgetPreferredUnit(IQuantity quantity, double minNumericalValue, double maxNumericalValue)LinearUnitgetUnit(String id)LinearUnitgetUnit(IPrefix<?> prefix)LinearUnitmakeCustomUnit(ITypedQuantity<LinearUnit> quantity)Create a custom unit.LinearUnitmakeUnit(String id, ITypedQuantity<LinearUnit> quantity)Create an off-system unit with no default localized name.LinearUnitmakeUnit(String id, ITypedQuantity<LinearUnit> quantity, String localizedName)ITypedQuantity<LinearUnit>parseInteractive(String interactiveQuantity)Parse an interactive string.ITypedQuantity<LinearUnit>parseInteractive(String interactiveQuantity, Map<String,? extends LinearUnit> symbolToUnitMap)ITypedQuantity<LinearUnit>parsePersisted(String persistedQuantity)Parse a persisted string.protected StringresolveLocalizedName(IPrefix<?> prefix)protected StringresolveLocalizedSymbol(IPrefix<?> prefix)protected voidsetDefaultSelector(LinearKindOfQuantity.LinearUnitSelector unitSelector)ITypedQuantity<LinearUnit>snapToBestBetweenHalfAndEqual(ITypedQuantity<LinearUnit> upperLimit)StringtoString()- 
Methods inherited from class org.openjdk.jmc.common.unit.KindOfQuantitycombine, format, getAccessor, getAccessorKeys, getAttributes, getFirstBucket, getFirstBucket, getPersister, getRangeFormatter, interactiveFormat, persistableString, validate
 - 
Methods inherited from class org.openjdk.jmc.common.unit.ContentTypeaddFormatter, getDefaultFormatter, getDescription, getFormatter, getFormatters, getIdentifier, getName, hasAttribute, lookupNameFor
 
- 
 
- 
- 
- 
Field Detail- 
atomUnitprotected final LinearUnit atomUnit 
 - 
atomUnitNameprotected final String atomUnitName 
 - 
commonUnitsprotected final Collection<LinearUnit> commonUnits 
 - 
allUnitsprotected final Collection<LinearUnit> allUnits 
 - 
interactiveSymbolToUnitMapprotected final Map<String,LinearUnit> interactiveSymbolToUnitMap 
 - 
unitSelectorprotected LinearKindOfQuantity.LinearUnitSelector unitSelector 
 - 
unitCacheprotected final Map<Object,LinearUnit> unitCache 
 
- 
 - 
Method Detail- 
getNumberFormatpublic static NumberFormat getNumberFormat(boolean interactive) Get a thread local configuredNumberFormatsuitable for display or interactive formatting, or interactive parsing. The returned formatter mustn't be modified except as by theNumberFormat.parse(String)andFormat.format(Object)family of methods.- Parameters:
- interactive- true to format/parse for interactive use, false otherwise
- Returns:
- a thread local configured NumberFormat
 
 - 
setDefaultSelectorprotected void setDefaultSelector(LinearKindOfQuantity.LinearUnitSelector unitSelector) 
 - 
getDeltaKindpublic KindOfQuantity<LinearUnit> getDeltaKind() - Specified by:
- getDeltaKindin class- KindOfQuantity<LinearUnit>
 
 - 
getDefaultUnitpublic LinearUnit getDefaultUnit() - Specified by:
- getDefaultUnitin class- KindOfQuantity<LinearUnit>
 
 - 
getUnitpublic LinearUnit getUnit(IPrefix<?> prefix) 
 - 
getUnitpublic LinearUnit getUnit(String id) - Overrides:
- getUnitin class- KindOfQuantity<LinearUnit>
 
 - 
getCachedUnitpublic LinearUnit getCachedUnit(Object key) 
 - 
getBestScaleFactorForprotected ScaleFactor getBestScaleFactorFor(long value) 
 - 
makeUnitpublic LinearUnit makeUnit(String id, ITypedQuantity<LinearUnit> quantity) Create an off-system unit with no default localized name.- Parameters:
- id- unit identifier which also is used as the unit symbol
 
 - 
makeUnitpublic LinearUnit makeUnit(String id, ITypedQuantity<LinearUnit> quantity, String localizedName) 
 - 
makeCustomUnitpublic LinearUnit makeCustomUnit(ITypedQuantity<LinearUnit> quantity) Create a custom unit. That is, one that normally isn't available for parsing (persisted or interactive).
 - 
toStringpublic String toString() - Overrides:
- toStringin class- ContentType<IQuantity>
 
 - 
getPreferredUnitpublic LinearUnit getPreferredUnit(IQuantity quantity, double minNumericalValue, double maxNumericalValue) - Specified by:
- getPreferredUnitin class- KindOfQuantity<LinearUnit>
 
 - 
getLargestExactUnitpublic LinearUnit getLargestExactUnit(IQuantity quantity) Description copied from class:KindOfQuantityGet the largest unit, if any, in which this quantity can be expressed exactly, typically with an integer. If the quantity has zero magnitude (quantity.doubleValue()== 0.0quantity.getUnit()will be returned. Thus, if you want to find out a maximum common unit for a set of quantities (not recommended), only use the non-zero quantities.Note that this may be a fairly expensive operation, and isn't intended to be used excessively. The only valid use case is for guessing the original unit in which a quantity was expressed, after it has been stored or transmitted using a legacy mechanism with a fixed unit. - Specified by:
- getLargestExactUnitin class- KindOfQuantity<LinearUnit>
- Returns:
- a unit or null
 
 - 
snapToBestBetweenHalfAndEqualpublic ITypedQuantity<LinearUnit> snapToBestBetweenHalfAndEqual(ITypedQuantity<LinearUnit> upperLimit) 
 - 
getFormatterResolvingpublic IFormatter<IQuantity> getFormatterResolving(IRange<IQuantity> range) Description copied from class:KindOfQuantityGet a formatter with sufficient resolution to produce unique strings for both ends ofrange, and consecutive equally spaced quantities. The returned formatter might implementIIncrementalFormatter, in which case its method can be used to reduce redundant information between adjacent quantities.- Specified by:
- getFormatterResolvingin class- KindOfQuantity<LinearUnit>
 
 - 
parsePersistedpublic ITypedQuantity<LinearUnit> parsePersisted(String persistedQuantity) throws QuantityConversionException Description copied from class:KindOfQuantityParse a persisted string. Only guaranteed to be able to parse strings produced byIQuantity.persistableString()for quantities of this kind of quantity. Only use this on persisted strings, never for interactive input.- Specified by:
- parsePersistedin interface- IConstraint<IQuantity>
- Specified by:
- parsePersistedin class- KindOfQuantity<LinearUnit>
- Parameters:
- persistedQuantity- persisted string to parse
- Returns:
- a valid quantity for this kind of quantity
- Throws:
- QuantityConversionException- if parsing failed
 
 - 
getAllUnitspublic Collection<LinearUnit> getAllUnits() - Overrides:
- getAllUnitsin class- KindOfQuantity<LinearUnit>
- Returns:
- all units, suitable for parsing, content assist and similar.
- See Also:
- KindOfQuantity.getCommonUnits()
 
 - 
getCommonUnitspublic Collection<LinearUnit> getCommonUnits() - Overrides:
- getCommonUnitsin class- KindOfQuantity<LinearUnit>
- Returns:
- the most common units, suitable to display a unit selection to the user.
- See Also:
- KindOfQuantity.getAllUnits()
 
 - 
addUnitprotected void addUnit(LinearUnit unit) Description copied from class:KindOfQuantityAdd a common unit (displayed to the user when selecting a unit).- Overrides:
- addUnitin class- KindOfQuantity<LinearUnit>
 
 - 
addUnitprotected void addUnit(LinearUnit unit, boolean common) Add a unit so that it is available for parsing and content assist, optionally also for direct selection by users.- Parameters:
- common- whether to include when showing most common units to users
 
 - 
parseInteractivepublic ITypedQuantity<LinearUnit> parseInteractive(String interactiveQuantity) throws QuantityConversionException Description copied from class:KindOfQuantityParse an interactive string. Only guaranteed to be able to parse strings produced byIQuantity.interactiveFormat()for quantities of this kind of quantity and in the same locale. Only use this for interactive input, never for persisted strings.- Specified by:
- parseInteractivein interface- IConstraint<IQuantity>
- Specified by:
- parseInteractivein class- KindOfQuantity<LinearUnit>
- Parameters:
- interactiveQuantity- interactive string to parse
- Returns:
- a valid quantity for this kind of quantity
- Throws:
- QuantityConversionException- if parsing failed
 
 - 
parseInteractivepublic ITypedQuantity<LinearUnit> parseInteractive(String interactiveQuantity, Map<String,? extends LinearUnit> symbolToUnitMap) throws QuantityConversionException - Parameters:
- interactiveQuantity- string to parse, interactive style
- symbolToUnitMap- map of additional symbols to parse into units, or null
- Returns:
- the parsed quantity
- Throws:
- QuantityConversionException- containing detailed structured information, if parsing failed
 
 
- 
 
-