Package ucar.units

Class UnitDBImpl

    • Constructor Detail

      • UnitDBImpl

        protected UnitDBImpl​(int nameCount,
                             int symbolCount)
        Constructs from the expected number of names and symbols. The sizes will be used to construct the initial database but will not limit its growth.
        Parameters:
        nameCount - The expected number of names (including plurals and aliases).
        symbolCount - The expected number of symbols.
    • Method Detail

      • add

        public void add​(UnitDBImpl that)
                 throws UnitExistsException
        Adds all the entries in another UnitDBImpl to this database.
        Parameters:
        that - The other UnitDBImpl.
        Throws:
        UnitExistsException - Attempt to redefine an existing entry.
      • nameCount

        public int nameCount()
        Return the number of names in this database
        Returns:
        The total number of names, plurals, and aliases.
      • symbolCount

        public int symbolCount()
        Return the number of symbols in this database.
        Returns:
        The number of symbols in this database.
      • addAlias

        public final void addAlias​(String alias,
                                   String name,
                                   String symbol,
                                   String plural)
                            throws NoSuchUnitException,
                                   UnitExistsException
        Adds an alias for a unit already in the database.
        Specified by:
        addAlias in interface UnitDB
        Parameters:
        alias - The alias to be added to the database. May be null.
        name - The name of the unit to have an alias added to the database.
        symbol - The symbol to be added. May be null.
        plural - The plural form of the alias. If null , then regular plural-forming rules are followed.
        Throws:
        NoSuchUnitException - The unit is not in the database.
        UnitExistsException - Another unit with the same alias is already in the database.
      • get

        public Unit get​(String id)
        Gets a unit by either name, plural, or symbol. Retrieving the unit by symbol is attempted before retrieving the unit by name because symbol comparisons are case sensitive and, hence, should be more robust.
        Specified by:
        get in interface UnitDB
        Parameters:
        id - The id to be matched.
        Returns:
        The unit whose name, plural, or symbol matches or null if no such unit was found.
      • getByName

        public Unit getByName​(String name)
        Gets a unit by name.
        Specified by:
        getByName in interface UnitDB
        Parameters:
        name - The name to be matched.
        Returns:
        The unit whose name, plural, or alias matches or null if no such unit was found.
      • getBySymbol

        public Unit getBySymbol​(String symbol)
        Gets a unit by symbol.
        Specified by:
        getBySymbol in interface UnitDB
        Parameters:
        symbol - The symbol to be matched.
        Returns:
        The unit whose symbol matches or null if no such unit was found.
      • toString

        public String toString()
        Returns the string representation of this database.
        Specified by:
        toString in interface UnitDB
        Overrides:
        toString in class Object
        Returns:
        The string representation of this database.
      • getIterator

        public final Iterator<Unit> getIterator()
        Gets an iterator over the units in the database.
        Specified by:
        getIterator in interface UnitDB
        Returns:
        An iterator over the units in the database. The iterator's next() method returns objects of type Unit.