public interface UnitFormat
Formats instances of Unit
to a String
or an Appendable
and parses a CharSequence
to a Unit
.
Instances of this class are not required to be thread-safe. It is recommended to of separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
Unit
Modifier and Type | Method and Description |
---|---|
String |
format(Unit<?> unit)
Formats the specified
Unit . |
Appendable |
format(Unit<?> unit,
Appendable appendable)
Formats the specified
Unit . |
boolean |
isLocaleSensitive()
|
void |
label(Unit<?> unit,
String label)
Attaches a system-wide label to the specified unit.
|
Unit<?> |
parse(CharSequence csq)
Parses a portion of the specified
CharSequence from the
specified position to produce a unit. |
Appendable format(Unit<?> unit, Appendable appendable) throws IOException
Unit
.unit
- the Unit
to format, not null
appendable
- the appendable destination.IOException
- if an error occurs while writing to the destination.String format(Unit<?> unit)
Unit
.unit
- the Unit
to format, not null
UnitFormat
.IOException
- if an error occurs while writing to the destination.void label(Unit<?> unit, String label)
If the specified label is already associated to a unit the previous
association can be discarded or ignored.
Depending on the UnitFormat
implementation, this call may be ignored if the particular unit already has a label.
UnitFormat
implementation is explicitly immutable, similar to e.g. the result of Collections.unmodifiableList(), then an UnsupportedOperationException may be thrown upon this call.Since UnitFormat implementations often apply the Singleton pattern, system-wide means, the label applies to every instance of UnitFormatA implementing UnitFormat in this case, but not every instance of UnitFormatB or UnitFormatC both also implementing UnitFormat. If a UnitFormat #isLocaleSensitive() it is up to the implementation, whether the label is ignored, applied in a local-neutral manner (in addition to its local-sensitive information) or locale-specific.
unit
- the unit being labeled.label
- the new label for this unit.IllegalArgumentException
- if the label is not a valid identifier. This may include characters not supported by a particular UnitFormat
implementation (e.g. only ASCII characters for certain devices)UnsupportedOperationException
- if the label operation
is not supported by this UnitFormat
boolean isLocaleSensitive()
true
if this UnitFormat
depends on a Locale
to perform its tasks.
In environments that do not support a Locale
, e.g. Java ME, this usually returns false
.
Unit<?> parse(CharSequence csq) throws ParserException
CharSequence
from the
specified position to produce a unit. If there is no unit to parse
the unitary unit (dimensionless) is returned.csq
- the CharSequence
to parse.ParserException
- if any problem occurs while parsing the
specified character sequence (e.g. illegal syntax).Copyright © 2014–2015 Jean-Marie Dautelle, Werner Keil, V2COM. All rights reserved.