javax.measure.unit.format
Class LocalFormat

java.lang.Object
  extended by java.text.Format
      extended by javax.measure.unit.UnitFormat
          extended by javax.measure.unit.format.LocalFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class LocalFormat
extends UnitFormat

This class represents the local sensitive format.

Here is the grammar for Units in Extended Backus-Naur Form (EBNF)

Note that the grammar has been left-factored to be suitable for use by a top-down parser generator such as JavaCC

Lexical Entities:
<sign> := "+" | "-"
<digit> := "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<superscript_digit> := "⁰" | "¹" | "²" | "³" | "⁴" | "⁵" | "⁶" | "⁷" | "⁸" | "⁹"
<integer> := (<digit>)+
<number> := (<sign>)? (<digit>)* (".")? (<digit>)+ (("e" | "E") (<sign>)? (<digit>)+)?
<exponent> := ( "^" ( <sign> )? <integer> )
| ( "^(" (<sign>)? <integer> ( "/" (<sign>)? <integer> )? ")" )
| ( <superscript_digit> )+
<initial_char> := ? Any Unicode character excluding the following: ASCII control & whitespace (\u0000 - \u0020), decimal digits '0'-'9', '(' (\u0028), ')' (\u0029), '*' (\u002A), '+' (\u002B), '-' (\u002D), '.' (\u002E), '/' (\u005C), ':' (\u003A), '^' (\u005E), '²' (\u00B2), '³' (\u00B3), '·' (\u00B7), '¹' (\u00B9), '⁰' (\u2070), '⁴' (\u2074), '⁵' (\u2075), '⁶' (\u2076), '⁷' (\u2077), '⁸' (\u2078), '⁹' (\u2079) ?
<unit_identifier> := <initial_char> ( <initial_char> | <digit> )*
Non-Terminals:
<unit_expr> := <compound_expr>
<compound_expr> := <add_expr> ( ":" <add_expr> )*
<add_expr> := ( <number> <sign> )? <mul_expr> ( <sign> <number> )?
<mul_expr> := <exponent_expr> ( ( ( "*" | "·" ) <exponent_expr> ) | ( "/" <exponent_expr> ) )*
<exponent_expr> := ( <atomic_expr> ( <exponent> )? )
| (<integer> "^" <atomic_expr>)
| ( ( "log" ( <integer> )? ) | "ln" ) "(" <add_expr> ")" )
<atomic_expr> := <number>
| <unit_identifier>
| ( "(" <add_expr> ")" )

Version:
1.0
Author:
Eric Russell
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
java.text.Format.Field
 
Method Summary
 java.lang.Appendable format(Unit<?> unit, java.lang.Appendable appendable)
          Formats the specified unit.
static LocalFormat getInstance()
          Returns the instance for the current default locale (non-ascii characters are allowed)
static LocalFormat getInstance(java.util.Locale locale)
          Returns an instance for the given locale.
static LocalFormat getInstance(SymbolMap symbols)
          Returns an instance for the given symbol map.
 SymbolMap getSymbols()
          Get the symbol map used by this instance to map between Units and Strings, etc...
 Unit<?> parse(java.lang.CharSequence csq, java.text.ParsePosition cursor)
          Parses a portion of the specified CharSequence from the specified position to produce a unit.
 
Methods inherited from class javax.measure.unit.UnitFormat
format, format, getStandard, parseObject
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static LocalFormat getInstance()
Returns the instance for the current default locale (non-ascii characters are allowed)


getInstance

public static LocalFormat getInstance(java.util.Locale locale)
Returns an instance for the given locale.

Parameters:
locale -

getInstance

public static LocalFormat getInstance(SymbolMap symbols)
Returns an instance for the given symbol map.


getSymbols

public SymbolMap getSymbols()
Get the symbol map used by this instance to map between Units and Strings, etc...

Returns:
SymbolMap the current symbol map

format

public java.lang.Appendable format(Unit<?> unit,
                                   java.lang.Appendable appendable)
                            throws java.io.IOException
Description copied from class: UnitFormat
Formats the specified unit.

Specified by:
format in class UnitFormat
Parameters:
unit - the unit to format.
appendable - the appendable destination.
Throws:
java.io.IOException - if an error occurs.

parse

public Unit<?> parse(java.lang.CharSequence csq,
                     java.text.ParsePosition cursor)
              throws java.lang.IllegalArgumentException
Description copied from class: UnitFormat
Parses a portion of the specified CharSequence from the specified position to produce a unit. If there is no unit to parse Unit.ONE is returned.

Specified by:
parse in class UnitFormat
Parameters:
csq - the CharSequence to parse.
cursor - the cursor holding the current parsing index.
Returns:
the unit parsed from the specified character sub-sequence.
Throws:
java.lang.IllegalArgumentException - if any problem occurs while parsing the specified character sequence (e.g. illegal syntax).


Copyright © 2009 JScience. All Rights Reserved.