public abstract class SimpleUnitFormat extends AbstractUnitFormat
This class implements the UnitFormat
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. Units
are directly
recognized. For example:
AbstractUnit.parse("m°C").equals(MetricPrefix.MILLI(Units.CELSIUS))
AbstractUnit.parse("kW").equals(MetricPrefix.KILO(Units.WATT))
AbstractUnit.parse("ft").equals(Units.METRE.multiply(0.3048))
Modifier and Type | Class and Description |
---|---|
protected static class |
SimpleUnitFormat.ASCIIFormat
This class represents the ASCII format.
|
protected static class |
SimpleUnitFormat.DefaultFormat
This class represents the standard format.
|
static class |
SimpleUnitFormat.Flavor
Flavor of this format
|
Modifier | Constructor and Description |
---|---|
protected |
SimpleUnitFormat()
Base constructor.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
alias(javax.measure.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(javax.measure.Unit<?> unit,
Appendable appendable)
Formats the specified unit.
|
static SimpleUnitFormat |
getInstance()
Returns the unit format for the default locale (format used by
AbstractUnit.parse(CharSequence) and
Unit.toString() ). |
static SimpleUnitFormat |
getInstance(SimpleUnitFormat.Flavor flavor)
Returns the
SimpleUnitFormat in the desired SimpleUnitFormat.Flavor |
protected static boolean |
isAllASCII(String input) |
boolean |
isLocaleSensitive() |
abstract boolean |
isValidIdentifier(String name)
Indicates if the specified name can be used as unit identifier.
|
abstract void |
label(javax.measure.Unit<?> unit,
String label)
Attaches a system-wide label to the specified unit.
|
javax.measure.Unit<?> |
parseObject(String source,
ParsePosition pos)
Parses the text from a string to produce an object (implements
java.text.Format ). |
abstract javax.measure.Unit<? extends javax.measure.Quantity> |
parseProductUnit(CharSequence csq,
ParsePosition pos)
Parses a sequence of character to produce a unit or a rational product of unit.
|
abstract javax.measure.Unit<? extends javax.measure.Quantity> |
parseSingleUnit(CharSequence csq,
ParsePosition pos)
Parses a sequence of character to produce a single unit.
|
format, getSymbols, parse, parse
protected SimpleUnitFormat()
public static SimpleUnitFormat getInstance()
AbstractUnit.parse(CharSequence)
and
Unit.toString()
).public static SimpleUnitFormat getInstance(SimpleUnitFormat.Flavor flavor)
SimpleUnitFormat
in the desired SimpleUnitFormat.Flavor
SimpleUnitFormat.Flavor
.public abstract Appendable format(javax.measure.Unit<?> unit, Appendable appendable) throws IOException
format
in interface javax.measure.format.UnitFormat
format
in class AbstractUnitFormat
unit
- the unit to format.appendable
- the appendable destination.appendable
, with formatted text appended.IOException
- if an error occurs.public abstract javax.measure.Unit<? extends javax.measure.Quantity> parseProductUnit(CharSequence csq, ParsePosition pos) throws javax.measure.format.ParserException
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.javax.measure.format.ParserException
public abstract javax.measure.Unit<? extends javax.measure.Quantity> parseSingleUnit(CharSequence csq, ParsePosition pos) throws javax.measure.format.ParserException
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.javax.measure.format.ParserException
public abstract void label(javax.measure.Unit<?> unit, String label)
label
in interface javax.measure.format.UnitFormat
label
in class AbstractUnitFormat
unit
- the unit being labelled.label
- the new label for this unit.IllegalArgumentException
- if the label is not a isValidIdentifier(String)
valid identifier.public boolean isLocaleSensitive()
public abstract void alias(javax.measure.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
).unit
- the unit to format.toAppendTo
- where the text is to be appendedpos
- the field position (not used).toAppendTo
public final javax.measure.Unit<?> parseObject(String source, ParsePosition pos) throws javax.measure.format.ParserException
java.text.Format
).source
- the string source, part of which should be parsed.pos
- the cursor position.null
if the string cannot be parsed.javax.measure.format.ParserException
protected static boolean isAllASCII(String input)
Copyright © 2005–2017 Units of Measurement project. All rights reserved.