Interface UnitFormat
-
public interface UnitFormatFormats instances ofUnitto aStringorAppendableand parses aCharSequenceto aUnit.Synchronization
Instances of this class are not required to be thread-safe. It is recommended to use separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
- Since:
- 1.0
- Version:
- 1.0, August 8, 2016
- See Also:
Unit
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Stringformat(Unit<?> unit)Formats the specifiedUnit.java.lang.Appendableformat(Unit<?> unit, java.lang.Appendable appendable)Formats the specifiedUnit.booleanisLocaleSensitive()voidlabel(Unit<?> unit, java.lang.String label)Attaches a system-wide label to the specified unit.Unit<?>parse(java.lang.CharSequence csq)Parses the text into an instance ofUnit.
-
-
-
Method Detail
-
format
java.lang.Appendable format(Unit<?> unit, java.lang.Appendable appendable) throws java.io.IOException
Formats the specifiedUnit.- Parameters:
unit- theUnitto format, notnullappendable- the appendable destination.- Returns:
- the appendable destination passed in with formatted text appended.
- Throws:
java.io.IOException- if an error occurs while writing to the destination.
-
format
java.lang.String format(Unit<?> unit)
Formats the specifiedUnit.- Parameters:
unit- theUnitto format, notnull- Returns:
- the string representation using the settings of this
UnitFormat.
-
label
void label(Unit<?> unit, java.lang.String label)
Attaches a system-wide label to the specified unit.If the specified label is already associated to a unit the previous association can be discarded or ignored. Depending on the
If aUnitFormatimplementation, this call may be ignored if the particular unit already has a label.UnitFormatimplementation 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.
- Parameters:
unit- the unit being labeled.label- the new label for this unit.- Throws:
java.lang.IllegalArgumentException- if the label is not a valid identifier. This may include characters not supported by a particularUnitFormatimplementation (e.g. only ASCII characters for certain devices)java.lang.UnsupportedOperationException- if the label operation is not supported by thisUnitFormat
-
isLocaleSensitive
boolean isLocaleSensitive()
Returnstrueif thisUnitFormatdepends on aLocaleto perform its tasks.In environments that do not support a
Locale, e.g. Java ME, this usually returnsfalse.- Returns:
- Whether this format depends on the locale.
-
parse
Unit<?> parse(java.lang.CharSequence csq) throws ParserException
Parses the text into an instance ofUnit.The parse must complete normally and parse the entire text. If the parse completes without reading the entire length of the text, an exception is thrown. If any other problem occurs during parsing, an exception is thrown.
- Parameters:
csq- theCharSequenceto parse.- Returns:
- the unit parsed from the specified character sequence.
- Throws:
ParserException- if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).java.lang.UnsupportedOperationException- if theUnitFormatis unable to parse.
-
-