Class EBNFUnitFormat

  • All Implemented Interfaces:
    javax.measure.format.UnitFormat

    public class EBNFUnitFormat
    extends AbstractUnitFormat

    This class represents the local neutral 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> ")" )
    Since:
    1.0
    Version:
    1.1, $Date: 2018-04-05 $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String BUNDLE_NAME
      Name of the resource bundle
      private static EBNFUnitFormat DEFAULT_INSTANCE
      Default locale instance.
      private SymbolMap symbolMap
      The symbol map used by this instance to map between Units and Strings, etc...
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Appendable format​(javax.measure.Unit<?> unit, java.lang.Appendable appendable)
      Formats the specified unit.
      static EBNFUnitFormat getInstance()
      Returns the instance for the current default locale (non-ascii characters are allowed)
      static EBNFUnitFormat getInstance​(SymbolMap symbols)
      Returns an instance for the given symbol map.
      protected SymbolMap getSymbols()
      Get the symbol map used by this instance to map between Units and Strings, etc...
      boolean isLocaleSensitive()  
      javax.measure.Unit<?> parse​(java.lang.CharSequence csq)  
      protected javax.measure.Unit<?> parse​(java.lang.CharSequence csq, int index)
      Parses a portion of the specified CharSequence from the specified position to produce a unit.
      protected javax.measure.Unit<? extends javax.measure.Quantity<?>> 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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BUNDLE_NAME

        private static final java.lang.String BUNDLE_NAME
        Name of the resource bundle
        See Also:
        Constant Field Values
      • DEFAULT_INSTANCE

        private static final EBNFUnitFormat DEFAULT_INSTANCE
        Default locale instance. If the default locale is changed after the class is initialized, this instance will no longer be used.
      • symbolMap

        private final transient SymbolMap symbolMap
        The symbol map used by this instance to map between Units and Strings, etc...
    • Constructor Detail

      • EBNFUnitFormat

        EBNFUnitFormat()
        Base constructor.
      • EBNFUnitFormat

        private EBNFUnitFormat​(SymbolMap symbols)
        Private constructor.
        Parameters:
        symbols - the symbol mapping.
    • Method Detail

      • getInstance

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

        public static EBNFUnitFormat getInstance​(SymbolMap symbols)
        Returns an instance for the given symbol map.
      • getSymbols

        protected SymbolMap getSymbols()
        Get the symbol map used by this instance to map between Units and Strings, etc...
        Specified by:
        getSymbols in class AbstractUnitFormat
        Returns:
        SymbolMap the current symbol map
      • format

        public java.lang.Appendable format​(javax.measure.Unit<?> unit,
                                           java.lang.Appendable appendable)
                                    throws java.io.IOException
        Description copied from class: AbstractUnitFormat
        Formats the specified unit.
        Specified by:
        format in interface javax.measure.format.UnitFormat
        Specified by:
        format in class AbstractUnitFormat
        Parameters:
        unit - the unit to format.
        appendable - the appendable destination.
        Returns:
        The appendable destination passed in as appendable, with formatted text appended.
        Throws:
        java.io.IOException - if an error occurs.
      • parse

        protected javax.measure.Unit<? extends javax.measure.Quantity<?>> parse​(java.lang.CharSequence csq,
                                                                                java.text.ParsePosition cursor)
                                                                         throws javax.measure.format.ParserException
        Description copied from class: AbstractUnitFormat
        Parses a portion of the specified CharSequence from the specified position to produce a unit. If there is no unit to parse AbstractUnit.ONE is returned.
        Specified by:
        parse in class AbstractUnitFormat
        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:
        javax.measure.format.ParserException
      • parse

        protected javax.measure.Unit<?> parse​(java.lang.CharSequence csq,
                                              int index)
                                       throws java.lang.IllegalArgumentException
        Description copied from class: AbstractUnitFormat
        Parses a portion of the specified CharSequence from the specified position to produce a unit. If there is no unit to parse AbstractUnit.ONE is returned.
        Specified by:
        parse in class AbstractUnitFormat
        Parameters:
        csq - the CharSequence to parse.
        index - 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).
      • parse

        public javax.measure.Unit<?> parse​(java.lang.CharSequence csq)
                                    throws javax.measure.format.ParserException
        Throws:
        javax.measure.format.ParserException
      • isLocaleSensitive

        public boolean isLocaleSensitive()