Class SymbolTable
- java.lang.Object
-
- com.jstatcom.model.SymbolTable
-
public class SymbolTable extends java.lang.ObjectThis class contains a sorted collection ofSymbolobjects 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.StringNAMEIdentifier of this table (always upper case).static XmlFormat<SymbolTable>SymbolTable_XMLXML format field for (de)serialization.
-
Constructor Summary
Constructors Constructor and Description SymbolTable(java.lang.String name)Creates an empty symbol table withname, and no parent.SymbolTable(java.lang.String name, boolean addToTree)Creates an empty symbol table withname, and no parent.SymbolTable(java.lang.String name, SymbolTable parentTable)Creates an empty symbol table withnameand a parent table.SymbolTable(java.lang.String name, SymbolTable parentTable, boolean addToTree)Creates an empty symbol table withnameand a parent table.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Removes all elements from this collection.booleancontains(java.lang.String symbolName)Gets whether this symbol table contains a symbol with namesymbolName.Symbolget(JSCTypeDef def)Gets the symbol withdef.name.JSCDatagetJSCData(JSCTypeDef def)Gets theJSCDatastored in the symbol with givendef.name.java.lang.StringgetName()Gets the name of this symbol table.SymbolTablegetParentTable()Gets the symbol table that is referenced as a parent of this table.SymbolgetSymbol(java.lang.String name)Gets the symbol with the givennameornullif none is contained with the given name.SymbolTableTreeNodegetSymbolTableNode()Gets the symbol table node that represents this table in aSymbolTree.booleanisEmpty()Gets whether this list is empty.java.util.Iteratoriterator()Gets anIteratorfor the symbols stored in this collection.booleanremove(java.lang.String name)Removes the symbol withnamefrom this collection.voidset(JSCData data)Adds a newJSCDataobject to the collection.voidset(JSCData[] data)Adds an array ofJSCDataobjects to the collection.voidset(java.lang.String symbolName, JSCData data)Adds a newJSCDataobject to the collection.voidsetSymbol(Symbol symbol)Puts a new symbol into the collection.voidsetSymbolTable(SymbolTable table)Sets the contents oftableto this symbol table by applying the following rules: if a symbol is only part oftablebut not ofthis, then a new symbol with the same name is created in this table and the reference to the underlyingJSCDatainstance is copied iftableandthiscontain symbols with the same name, then the reference to the underlyingJSCDatainstance 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 untouchedvoidsetSymbolTableNode(SymbolTableTreeNode node)Sets the symbol table node that represents this table in aSymbolTree.intsize()Gets the number of stored symbols in this collection.java.lang.StringtoString()Returns a string that represents the value of this object.
-
-
-
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 withname, and no parent. It will be added to the symbol tree.- Parameters:
name- the identifier of thatSymbolTable
-
SymbolTable
public SymbolTable(java.lang.String name, boolean addToTree)Creates an empty symbol table withname, and no parent. It can optionally be added to the symbol tree.- Parameters:
name- the identifier of thatSymbolTableaddToTree- iftruethen 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 withnameand a parent table. It will be added to the symbol tree.- Parameters:
name- the identifier of thatSymbolTableparentTable- 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 withnameand a parent table. It can optionally be added to the symbol tree.- Parameters:
name- the identifier of thatSymbolTableparentTable- the parent table, will be parent node in symbol treeaddToTree- iftruethen 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 ofJSCDataobjects to the collection.- Parameters:
data- theJSCDataarray to put- Throws:
java.lang.IllegalArgumentException-if (data == null)
or if a symbol withdata[i].getName()but with a different type already exists
-
set
public final void set(JSCData data)
Adds a newJSCDataobject to the collection. If a symbol with the same name asdatais already contained,datawill be set for that symbol. If no symbol ofdata.getName()is contained, then a new symbol will be created and added.- Parameters:
data- theJSCDataobject to put- Throws:
java.lang.IllegalArgumentException-if (data == null)
or if a symbol withdata.getName()but with a different type already exists
-
set
public final void set(java.lang.String symbolName, JSCData data)Adds a newJSCDataobject to the collection. If a symbol with the namesymbolNameis already contained,datawill be set for that symbol. If no symbol ofsymbolNameis contained, then a new symbol will be created and added.- Parameters:
symbolName- the name of the symbol to be createddata- theJSCDataobject to put- Throws:
java.lang.IllegalArgumentException-if (data == null || symbolName == null)
or if a symbol withsymbolNamebut with a different type already exists
or ifsymbolNameis not a valid name as defined inJSCConstants
-
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- theSymbolobject 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 theSymbolTabledoes not affect anySymbolListenersattached to that symbol. They are still notified about changes in the removed symbol and not informed if a new symbol withnameis added. You might consider callingremoveAllSymbolListenersbefore 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 namesymbolName.- Parameters:
symbolName- the name of the symbol to check for- Returns:
trueif contained,falseotherwise
-
getSymbol
public final Symbol getSymbol(java.lang.String name)
Gets the symbol with the givennameornullif none is contained with the given name.Usage Note:
Pleae notice the difference to the typesavegetmethod. 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 withdef.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 theJSCDatastored in the symbol with givendef.name. If a symbol with that name does not yet exist, a symbol of the given type is created, added and an emptyJSCDataobject is returned.Instead of calling this method, one of the convenience methods for special
JSCDataTypescan be used.- Parameters:
def- the type definition for the symbol- Returns:
- the
JSCDatathat 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:
trueif no elements are contained,falseotherwise
-
iterator
public final java.util.Iterator iterator()
Gets anIteratorfor 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, becausethiscan 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
Iteratorfor all symbols
-
remove
public final boolean remove(java.lang.String name)
Removes the symbol withnamefrom this collection. The case of the name makes no difference.Usage Note:
Removing a symbol from theSymbolTabledoes not affect anySymbolListenersattached to that symbol. They are still notified about changes in the removed symbol and not informed if a new symbol withnameis added. You might consider callingremoveAllSymbolListenersbefore that symbol is removed if this is not what you want.- Parameters:
name- the identifier for the symbol to remove.- Returns:
trueif 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:
toStringin classjava.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 aSymbolTree.- Parameters:
node- to representthis table
-
getSymbolTableNode
public SymbolTableTreeNode getSymbolTableNode()
Gets the symbol table node that represents this table in aSymbolTree.- Returns:
- node representing this table
-
setSymbolTable
public void setSymbolTable(SymbolTable table)
Sets the contents oftableto this symbol table by applying the following rules:- if a symbol is only part of
tablebut not ofthis, then a new symbol with the same name is created in this table and the reference to the underlyingJSCDatainstance is copied - if
tableandthiscontain symbols with the same name, then the reference to the underlyingJSCDatainstance 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
tabletothis. 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)
- if a symbol is only part of
-
-
DMelt 3.0 © DataMelt by jWork.ORG