|
JScience v2.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavolution.lang.TextFormat<Unit>
org.jscience.physics.units.UnitFormat
public abstract class UnitFormat
This is the abstract base class for all unit formats.
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:
Unit.valueOf("m°C") == SI.MILLI(SI.CELSIUS)
Unit.valueOf("kW") == SI.KILO(SI.WATT)
Unit.valueOf("ft") == SI.METER.multiply(0.3048)
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javolution.lang.TextFormat |
|---|
TextFormat.Cursor |
| Field Summary | |
|---|---|
static UnitFormat |
ASCII
Holds the ASCII unit format. |
static UnitFormat |
HTML
Holds the HTML unit format. |
static UnitFormat |
STANDARD
Holds the standard unit format. |
| Constructor Summary | |
|---|---|
protected |
UnitFormat()
Base constructor. |
| Method Summary | |
|---|---|
static UnitFormat |
current()
Returns the local unit format
(default STANDARD). |
static boolean |
isUnitIdentifierPart(char ch)
Determines if the specified character may be part of a unit identifier. |
java.lang.CharSequence |
labelFor(Unit unit)
Returns the label for the specified unit. |
Unit |
parse(java.lang.CharSequence csq,
TextFormat.Cursor pos)
Parses text to produce an unit. |
static void |
setCurrent(UnitFormat format)
Sets the local unit format. |
Unit |
unitFor(java.lang.CharSequence label)
Returns the unit identified by the specified name (symbol, label or alias). |
| Methods inherited from class javolution.lang.TextFormat |
|---|
format, format, parse |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final UnitFormat STANDARD
0080-00FF) supported by the majority of fonts.
For example: cm³·A²/kg
public static final UnitFormat ASCII
0000-007F exclusively.
For example: cm^3*kg^-1*A^2
public static final UnitFormat HTML
cm<sup>3</sup>·kg<sup>-1
</sup>·A<sup>2</sup>
(cm3·kg-1·A2)
| Constructor Detail |
|---|
protected UnitFormat()
| Method Detail |
|---|
public static UnitFormat current()
local unit format
(default STANDARD).
public static void setCurrent(UnitFormat format)
local unit format.
format - the new local/global unit format.public static boolean isUnitIdentifierPart(char ch)
ch - the character to be tested.
true if the character may be part of a unit
identifier; false otherwise.
public Unit parse(java.lang.CharSequence csq,
TextFormat.Cursor pos)
The expected form of the character sequence is:
{<name>{<power>{<root>}}}
For examples:
HTML tags are ignored (e.g. <sup>...</sup>).
Escape sequences are considered as separators (e.g. ·).
Space characters are ignored.
Any level of parenthesis can be used.
parse in class TextFormat<Unit>csq - the CharSequence to parse.pos - an object holding the parsing index and error position.
Unit parsed from the character sequence.
java.lang.IllegalArgumentException - if the character sequence contains
an illegal syntax.Character.isSpaceChar(char)public java.lang.CharSequence labelFor(Unit unit)
unit - the unit for which the label is searched for.
[K+273.15], [m*0.01]) or
null if the unit has no intrinsic label (e.g.
ProductUnit).unitFor(java.lang.CharSequence)public Unit unitFor(java.lang.CharSequence label)
label - the label, alias, or symbol identifying the unit.
null if the identification fails.labelFor(org.jscience.physics.units.Unit)
|
JScience v2.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||