public abstract class UnitFormat extends Format
This class provides the interface for formatting and parsing units
.
For all SI
units, the 20 SI prefixes used to form decimal
multiples and sub-multiples of SI units are recognized.
NonSI
units are directly recognized. For example:[code]
Unit.valueOf("m°C").equals(SI.MILLI(SI.CELSIUS))
Unit.valueOf("kW").equals(SI.KILO(SI.WATT))
Unit.valueOf("ft").equals(SI.METER.multiply(0.3048))[/code]
Modifier and Type | Class and Description |
---|---|
protected static class |
UnitFormat.ASCIIFormat
This class represents the ASCIIFormat format.
|
protected static class |
UnitFormat.DefaultFormat
This class represents the standard format.
|
Format.Field
Modifier | Constructor and Description |
---|---|
protected |
UnitFormat()
Base constructor.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
alias(Unit<?> unit,
String alias)
Attaches a system-wide alias to this unit.
|
StringBuffer |
format(Object unit,
StringBuffer toAppendTo,
FieldPosition pos)
Formats an unit and appends the resulting text to a given string
buffer (implements
java.text.Format ). |
abstract Appendable |
format(Unit<?> unit,
Appendable appendable)
Formats the specified unit.
|
static UnitFormat |
getInstance()
Returns the unit format for the default locale (format used by
Unit.valueOf(CharSequence) and
Unit.toString() ). |
static UnitFormat |
getInstance(Locale inLocale)
Returns the unit format for the specified locale.
|
static UnitFormat |
getUCUMInstance()
Returns the UCUM
international unit format; this format uses characters range
0000-007F exclusively and is not locale-sensitive. |
abstract boolean |
isValidIdentifier(String name)
Indicates if the specified name can be used as unit identifier.
|
abstract void |
label(Unit<?> unit,
String label)
Attaches a system-wide label to the specified unit.
|
Unit<?> |
parseObject(String source,
ParsePosition pos)
Parses the text from a string to produce an object
(implements
java.text.Format ). |
abstract Unit<? extends Quantity> |
parseProductUnit(CharSequence csq,
ParsePosition pos)
Parses a sequence of character to produce a unit or a rational product
of unit.
|
abstract Unit<? extends Quantity> |
parseSingleUnit(CharSequence csq,
ParsePosition pos)
Parses a sequence of character to produce a single unit.
|
clone, format, formatToCharacterIterator, parseObject
public static UnitFormat getInstance()
Unit.valueOf(CharSequence)
and
Unit.toString()
).public static UnitFormat getInstance(Locale inLocale)
public static UnitFormat getUCUMInstance()
0000-007F
exclusively and is not locale-sensitive.
For example: kg.m/s2
public abstract Appendable format(Unit<?> unit, Appendable appendable) throws IOException
unit
- the unit to format.appendable
- the appendable destination.IOException
- if an error occurs.public abstract Unit<? extends Quantity> parseProductUnit(CharSequence csq, ParsePosition pos) throws ParseException
csq
- the CharSequence
to parse.pos
- an object holding the parsing index and error position.Unit
parsed from the character sequence.IllegalArgumentException
- if the character sequence contains
an illegal syntax.ParseException
public abstract Unit<? extends Quantity> parseSingleUnit(CharSequence csq, ParsePosition pos) throws ParseException
csq
- the CharSequence
to parse.pos
- an object holding the parsing index and error position.Unit
parsed from the character sequence.IllegalArgumentException
- if the character sequence does not contain
a valid unit identifier.ParseException
public abstract void label(Unit<?> unit, String label)
unit
- the unit being labelled.label
- the new label for this unit.IllegalArgumentException
- if the label is not a
isValidIdentifier(String)
valid identifier.public abstract void alias(Unit<?> unit, String alias)
unit
- the unit being aliased.alias
- the alias attached to this unit.IllegalArgumentException
- if the label is not a
isValidIdentifier(String)
valid identifier.public abstract boolean isValidIdentifier(String name)
name
- the identifier to be tested.true
if the name specified can be used as
label or alias for this format;false
otherwise.public final StringBuffer format(Object unit, StringBuffer toAppendTo, FieldPosition pos)
java.text.Format
).public final Unit<?> parseObject(String source, ParsePosition pos)
java.text.Format
).parseObject
in class Format
source
- the string source, part of which should be parsed.pos
- the cursor position.null
if the string
cannot be parsed.Copyright © 2012. All Rights Reserved.