public abstract class KindOfQuantity<U extends TypedUnit<U>> extends ContentType<IQuantity> implements IPersister<IQuantity>
Modifier and Type | Class and Description |
---|---|
static class |
KindOfQuantity.ExactFormatter<U extends TypedUnit<U>> |
static class |
KindOfQuantity.VerboseFormatter<U extends TypedUnit<U>> |
m_identifier
Modifier and Type | Method and Description |
---|---|
protected void |
addUnit(U unit)
Add a common unit (displayed to the user when selecting a unit).
|
IConstraint<IQuantity> |
combine(IConstraint<?> other)
Return a constraint that honors both this constraint and
other , if such a constraint
would accept anything except null . |
static <U extends TypedUnit<U>> |
format(Number number,
IUnit unit)
Convenience method (possibly temporary) until type parameters has settled.
|
<M> IMemberAccessor<M,IQuantity> |
getAccessor(IAccessorKey<M> attribute)
Internal low-level mechanism for retrieving a member accessor for a type, or null if not
available.
|
Map<IAccessorKey<?>,? extends IDescribable> |
getAccessorKeys()
Get keys for the accessors that this type knows of.
|
Collection<? extends U> |
getAllUnits() |
List<IAttribute<?>> |
getAttributes() |
Collection<? extends U> |
getCommonUnits() |
abstract U |
getDefaultUnit() |
abstract KindOfQuantity<LinearUnit> |
getDeltaKind() |
IRange<IQuantity> |
getFirstBucket(IQuantity start,
IQuantity end,
double maxBuckets)
Divide the given range into at most
maxBuckets "naturally" aligned buckets, and
return the first one. |
protected IRange<IQuantity> |
getFirstBucket(ITypedQuantity<U> start,
ITypedQuantity<U> end,
double maxBuckets) |
abstract IFormatter<IQuantity> |
getFormatterResolving(IRange<IQuantity> range)
Get a formatter with sufficient resolution to produce unique strings for both ends of
range , and consecutive equally spaced quantities. |
abstract U |
getLargestExactUnit(IQuantity quantity)
Get the largest unit, if any, in which this quantity can be expressed exactly, typically with
an integer.
|
IPersister<IQuantity> |
getPersister() |
abstract U |
getPreferredUnit(IQuantity quantity,
double minNumericalValue,
double maxNumericalValue) |
IFormatter<IRange<IQuantity>> |
getRangeFormatter(String formatHint)
Temporary helper to format quantity ranges.
|
U |
getUnit(String id) |
String |
interactiveFormat(IQuantity value)
An exact string representation taking locale and internationalization into account.
|
abstract ITypedQuantity<U> |
parseInteractive(String interactiveQuantity)
Parse an interactive string.
|
abstract ITypedQuantity<U> |
parsePersisted(String persistedQuantity)
Parse a persisted string.
|
String |
persistableString(IQuantity value)
A string representation independent of locale or internationalization, that when parsed using
IConstraint.parsePersisted(String) (on this instance) yields a result that is
equal to the given value . |
boolean |
validate(IQuantity value)
Fundamentally, check that
value satisfies this constraint and throw an exception
otherwise. |
addFormatter, getDefaultFormatter, getDescription, getFormatter, getFormatters, getIdentifier, getName, hasAttribute, lookupNameFor, toString
public static <U extends TypedUnit<U>> String format(Number number, IUnit unit)
U
- Unit type. Inferred from the unit
argument.number
- numerical quantity valueunit
- quantity unitpublic abstract KindOfQuantity<LinearUnit> getDeltaKind()
public abstract U getDefaultUnit()
protected void addUnit(U unit)
public Collection<? extends U> getCommonUnits()
getAllUnits()
public Collection<? extends U> getAllUnits()
getCommonUnits()
public IPersister<IQuantity> getPersister()
getPersister
in class ContentType<IQuantity>
public IConstraint<IQuantity> combine(IConstraint<?> other)
IConstraint
other
, if such a constraint
would accept anything except null
. Otherwise, return null
.combine
in interface IConstraint<IQuantity>
null
public boolean validate(IQuantity value)
IConstraint
value
satisfies this constraint and throw an exception
otherwise. As long as the method returns normally, value
is a valid value, regardless
of the return value. However, when wrapping a persister in a constraint, it is possible that
the persister treats some magic values differently. If the constraint isn't aware of these
magical values it should typically not try to validate them. This is signaled by the
persister by returning true from this method.validate
in interface IConstraint<IQuantity>
validate
in interface IPersister<IQuantity>
value
is valid.public String persistableString(IQuantity value)
IPersister
IConstraint.parsePersisted(String)
(on this instance) yields a result that is
equal
to the given value
. That is, the exact
representation must be preserved.persistableString
in interface IConstraint<IQuantity>
persistableString
in interface IPersister<IQuantity>
public abstract ITypedQuantity<U> parsePersisted(String persistedQuantity) throws QuantityConversionException
IQuantity.persistableString()
for quantities of this kind of quantity. Only use this
on persisted strings, never for interactive input.parsePersisted
in interface IConstraint<IQuantity>
persistedQuantity
- persisted string to parseQuantityConversionException
- if parsing failedpublic String interactiveFormat(IQuantity value)
IPersister
IConstraint.parseInteractive(String)
(on this instance) yields a result that is
equal
to the given value
. That is, the exact
representation must be preserved.interactiveFormat
in interface IConstraint<IQuantity>
interactiveFormat
in interface IPersister<IQuantity>
public abstract ITypedQuantity<U> parseInteractive(String interactiveQuantity) throws QuantityConversionException
IQuantity.interactiveFormat()
for quantities of this kind of quantity and in the same
locale. Only use this for interactive input, never for persisted strings.parseInteractive
in interface IConstraint<IQuantity>
interactiveQuantity
- interactive string to parseQuantityConversionException
- if parsing failedpublic abstract U getPreferredUnit(IQuantity quantity, double minNumericalValue, double maxNumericalValue)
public abstract U getLargestExactUnit(IQuantity quantity)
quantity.doubleValue()
== 0.0
),
quantity.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.
null
public final IRange<IQuantity> getFirstBucket(IQuantity start, IQuantity end, double maxBuckets)
maxBuckets
"naturally" aligned buckets, and
return the first one. This can be used to create tick marks in charts or buckets for
histograms. The number of buckets will typically be between maxBuckets/2
and
maxBuckets
, but this should be better specified.
Note that start
is included in the first bucket.
start
- range start valueend
- range end valuemaxBuckets
- maximum number of buckets to divide range intoprotected IRange<IQuantity> getFirstBucket(ITypedQuantity<U> start, ITypedQuantity<U> end, double maxBuckets)
public IFormatter<IRange<IQuantity>> getRangeFormatter(String formatHint)
formatHint
- A format hint. See IDisplayable.displayUsing(String)
.public abstract IFormatter<IQuantity> getFormatterResolving(IRange<IQuantity> range)
range
, and consecutive equally spaced quantities. The returned formatter might
implement IIncrementalFormatter
, in which case its method can be used to reduce
redundant information between adjacent quantities.public List<IAttribute<?>> getAttributes()
getAttributes
in interface IType<IQuantity>
getAttributes
in class ContentType<IQuantity>
public Map<IAccessorKey<?>,? extends IDescribable> getAccessorKeys()
IType
Should only be used for low level type inspection. Iterators etc. should use a collection of
predefined attributes
.
getAccessorKeys
in interface IType<IQuantity>
getAccessorKeys
in class ContentType<IQuantity>
public <M> IMemberAccessor<M,IQuantity> getAccessor(IAccessorKey<M> attribute)
IType
This is only intended to be used by implementors of IAccessorFactory
. All other usage
should be replaced with ICanonicalAccessorFactory.getAccessor(IType)
call to pre-defined accessors.
getAccessor
in interface IType<IQuantity>
getAccessor
in class ContentType<IQuantity>
M
- accessor value typeattribute
- the identifier for the fieldCopyright © 2020. All rights reserved.