Documentation of 'com.jstatcom.model.SymbolTable' Java class
SymbolTable
com.jstatcom.model

Class SymbolTable



  • public class SymbolTable
    extends java.lang.Object
    This class contains a sorted collection of Symbol objects that can easily be accessed.

    This class is thread-save. All access to mutable data is synchronized.

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      java.lang.String NAME
      Identifier of this table (always upper case).
      static XmlFormat<SymbolTable> SymbolTable_XML
      XML format field for (de)serialization.
    • Constructor Summary

      Constructors 
      Constructor and Description
      SymbolTable(java.lang.String name)
      Creates an empty symbol table with name, and no parent.
      SymbolTable(java.lang.String name, boolean addToTree)
      Creates an empty symbol table with name, and no parent.
      SymbolTable(java.lang.String name, SymbolTable parentTable)
      Creates an empty symbol table with name and a parent table.
      SymbolTable(java.lang.String name, SymbolTable parentTable, boolean addToTree)
      Creates an empty symbol table with name and a parent table.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void clear()
      Removes all elements from this collection.
      boolean contains(java.lang.String symbolName)
      Gets whether this symbol table contains a symbol with name symbolName.
      Symbol get(JSCTypeDef def)
      Gets the symbol with def.name.
      JSCData getJSCData(JSCTypeDef def)
      Gets the JSCData stored in the symbol with given def.name.
      java.lang.String getName()
      Gets the name of this symbol table.
      SymbolTable getParentTable()
      Gets the symbol table that is referenced as a parent of this table.
      Symbol getSymbol(java.lang.String name)
      Gets the symbol with the given name or null if none is contained with the given name.
      SymbolTableTreeNode getSymbolTableNode()
      Gets the symbol table node that represents this table in a SymbolTree.
      boolean isEmpty()
      Gets whether this list is empty.
      java.util.Iterator iterator()
      Gets an Iterator for the symbols stored in this collection.
      boolean remove(java.lang.String name)
      Removes the symbol with name from this collection.
      void set(JSCData data)
      Adds a new JSCData object to the collection.
      void set(JSCData[] data)
      Adds an array of JSCData objects to the collection.
      void set(java.lang.String symbolName, JSCData data)
      Adds a new JSCData object to the collection.
      void setSymbol(Symbol symbol)
      Puts a new symbol into the collection.
      void setSymbolTable(SymbolTable table)
      Sets the contents of table to this symbol table by applying the following rules: if a symbol is only part of table but not of this, then a new symbol with the same name is created in this table and the reference to the underlying JSCData instance is copied if table and this contain symbols with the same name, then the reference to the underlying JSCData instance is copied from the symbol of the argument table to this table all symbols that are part of this table but not of the argument table are left untouched
      void setSymbolTableNode(SymbolTableTreeNode node)
      Sets the symbol table node that represents this table in a SymbolTree.
      int size()
      Gets the number of stored symbols in this collection.
      java.lang.String toString()
      Returns a string that represents the value of this object.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NAME

        public final java.lang.String NAME
        Identifier of this table (always upper case).
      • SymbolTable_XML

        public static final XmlFormat<SymbolTable> SymbolTable_XML
        XML format field for (de)serialization.
    • Constructor Detail

      • SymbolTable

        public SymbolTable(java.lang.String name)
        Creates an empty symbol table with name, and no parent. It will be added to the symbol tree.
        Parameters:
        name - the identifier of that SymbolTable
      • SymbolTable

        public SymbolTable(java.lang.String name,
                           boolean addToTree)
        Creates an empty symbol table with name, and no parent. It can optionally be added to the symbol tree.
        Parameters:
        name - the identifier of that SymbolTable
        addToTree - if true then this table will be added to the symbol tree, otherwise it will not be added
      • SymbolTable

        public SymbolTable(java.lang.String name,
                           SymbolTable parentTable)
        Creates an empty symbol table with name and a parent table. It will be added to the symbol tree.
        Parameters:
        name - the identifier of that SymbolTable
        parentTable - the parent table, will be parent node in symbol tree
      • SymbolTable

        public SymbolTable(java.lang.String name,
                           SymbolTable parentTable,
                           boolean addToTree)
        Creates an empty symbol table with name and a parent table. It can optionally be added to the symbol tree.
        Parameters:
        name - the identifier of that SymbolTable
        parentTable - the parent table, will be parent node in symbol tree
        addToTree - if true then this table will be added to the symbol tree, otherwise it will not be added
    • Method Detail

      • set

        public final void set(JSCData[] data)
        Adds an array of JSCData objects to the collection.
        Parameters:
        data - the JSCData array to put
        Throws:
        java.lang.IllegalArgumentException - if (data == null)
        or if a symbol with data[i].getName() but with a different type already exists
      • set

        public final void set(JSCData data)
        Adds a new JSCData object to the collection. If a symbol with the same name as data is already contained, data will be set for that symbol. If no symbol of data.getName() is contained, then a new symbol will be created and added.
        Parameters:
        data - the JSCData object to put
        Throws:
        java.lang.IllegalArgumentException - if (data == null)
        or if a symbol with data.getName() but with a different type already exists
      • set

        public final void set(java.lang.String symbolName,
                              JSCData data)
        Adds a new JSCData object to the collection. If a symbol with the name symbolName is already contained, data will be set for that symbol. If no symbol of symbolName is contained, then a new symbol will be created and added.
        Parameters:
        symbolName - the name of the symbol to be created
        data - the JSCData object to put
        Throws:
        java.lang.IllegalArgumentException - if (data == null || symbolName == null)
        or if a symbol with symbolName but with a different type already exists
        or if symbolName is not a valid name as defined in JSCConstants
      • setSymbol

        public final void setSymbol(Symbol symbol)
        Puts a new symbol into the collection. The symbol is put on a position that keeps the underlying collection alphabetically sorted without respect to the case. If a symbol with the same name is alread contained, then the data and listeners are copied to the existing symbol.
        Parameters:
        symbol - the Symbol object to put
        Throws:
        java.lang.IllegalArgumentException - if (symbol == null)
      • clear

        public final void clear()
        Removes all elements from this collection.

        Usage Note:
        Removing a symbol from the SymbolTable does not affect any SymbolListeners attached to that symbol. They are still notified about changes in the removed symbol and not informed if a new symbol with name is added. You might consider calling removeAllSymbolListeners before that symbol is removed if this is not what you want.

      • contains

        public final boolean contains(java.lang.String symbolName)
        Gets whether this symbol table contains a symbol with name symbolName.
        Parameters:
        symbolName - the name of the symbol to check for
        Returns:
        true if contained, false otherwise
      • getSymbol

        public final Symbol getSymbol(java.lang.String name)
        Gets the symbol with the given name or null if none is contained with the given name.

        Usage Note:
        Pleae notice the difference to the typesave get method. This does not create a new symbol if it is not contained yet, because it is not known, which type the new symbol should have.

        Parameters:
        name - the identifier for the symbol
        Returns:
        the symbol that was stored or a new empty symbol
        Throws:
        java.lang.IllegalArgumentException - if (name == null)
      • get

        public final Symbol get(JSCTypeDef def)
        Gets the symbol with def.name. If a symbol with that name does not yet exist an empty symbol of the given type is created, added and returned.
        Parameters:
        def - the type definition for the symbol
        Returns:
        the symbol that was stored or a new empty symbol
        Throws:
        java.lang.IllegalArgumentException - if (def == null)
        java.lang.RuntimeException - if the retrieved symbol has a different type
      • getJSCData

        public final JSCData getJSCData(JSCTypeDef def)
        Gets the JSCData stored in the symbol with given def.name. If a symbol with that name does not yet exist, a symbol of the given type is created, added and an empty JSCData object is returned.

        Instead of calling this method, one of the convenience methods for special JSCDataTypes can be used.

        Parameters:
        def - the type definition for the symbol
        Returns:
        the JSCData that was stored or a new empty data object
        Throws:
        java.lang.IllegalArgumentException - if (def == null)
        java.lang.RuntimeException - if the retrieved symbol has a different type
      • getName

        public final java.lang.String getName()
        Gets the name of this symbol table.
        Returns:
        the name
      • isEmpty

        public final boolean isEmpty()
        Gets whether this list is empty.
        Returns:
        true if no elements are contained, false otherwise
      • iterator

        public final java.util.Iterator iterator()
        Gets an Iterator for the symbols stored in this collection. The iterator is guaranteed to walk through all stored symbols in alphabetical order, starting with the lowest.

        Usage Note:
        Clients must deal with synchronization while traversing this iterator, because this can change during that operation. The simplest way is to lock this symbol table during the entire traversal. If clients can make sure that no other threads access this symbol table during traversal, locking can be ommitted.

        Returns:
        an Iterator for all symbols
      • remove

        public final boolean remove(java.lang.String name)
        Removes the symbol with name from this collection. The case of the name makes no difference.

        Usage Note:
        Removing a symbol from the SymbolTable does not affect any SymbolListeners attached to that symbol. They are still notified about changes in the removed symbol and not informed if a new symbol with name is added. You might consider calling removeAllSymbolListeners before that symbol is removed if this is not what you want.

        Parameters:
        name - the identifier for the symbol to remove.
        Returns:
        true if this list contained the specified element
        Throws:
        java.lang.IllegalArgumentException - if (name == null)
        See Also:
        Symbol.equals(java.lang.Object)
      • size

        public final int size()
        Gets the number of stored symbols in this collection.
        Returns:
        the size
      • toString

        public final java.lang.String toString()
        Returns a string that represents the value of this object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of the receiver
      • getParentTable

        public final SymbolTable getParentTable()
        Gets the symbol table that is referenced as a parent of this table.
        Returns:
        a symbol table
      • setSymbolTableNode

        public void setSymbolTableNode(SymbolTableTreeNode node)
        Sets the symbol table node that represents this table in a SymbolTree.
        Parameters:
        node - to representthis table
      • getSymbolTableNode

        public SymbolTableTreeNode getSymbolTableNode()
        Gets the symbol table node that represents this table in a SymbolTree.
        Returns:
        node representing this table
      • setSymbolTable

        public void setSymbolTable(SymbolTable table)
        Sets the contents of table to this symbol table by applying the following rules:
        • if a symbol is only part of table but not of this, then a new symbol with the same name is created in this table and the reference to the underlying JSCData instance is copied
        • if table and this contain symbols with the same name, then the reference to the underlying JSCData instance is copied from the symbol of the argument table to this table
        • all symbols that are part of this table but not of the argument table are left untouched

        This operation does not change the argument symbol table, but by copying references its symbols might be affected by operations on this table afterwards.

        This method does not copy any listeners from table to this. Listeners of this table are not changed by this operation, except that they are notified via events in case of relevant changes.

        Parameters:
        table - the symbol table from which symbol are copied to this table
        Throws:
        java.lang.IllegalArgumentException - if (table == null)

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.