Package jmri.jmrit.logixng
Interface SymbolTable
-
- All Known Implementing Classes:
DefaultSymbolTable
public interface SymbolTable
A symbol table
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
SymbolTable.InitialValueType
An enum that defines the types of initial value.static interface
SymbolTable.Symbol
The definition of the symbolstatic class
SymbolTable.SymbolNotFound
static class
SymbolTable.Type
static class
SymbolTable.VariableData
Data for a variable.
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.Logger
log
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
createSymbols(java.util.Collection<? extends SymbolTable.VariableData> symbolDefinitions)
Add new symbols to the symbol tablevoid
createSymbols(SymbolTable symbolTable, java.util.Collection<? extends SymbolTable.VariableData> symbolDefinitions)
Add new symbols to the symbol table.static java.lang.Object
getInitialValue(SymbolTable.Type type, java.lang.String name, SymbolTable.InitialValueType initialType, java.lang.String initialData, SymbolTable symbolTable, java.util.Map<java.lang.String,SymbolTable.Symbol> symbols)
Stack
getStack()
Get the stack.java.util.Map<java.lang.String,SymbolTable.Symbol>
getSymbols()
The list of symbols in the tablejava.util.Map<java.lang.String,java.lang.Object>
getSymbolValues()
The list of symbols and their values in the tablejava.lang.Object
getValue(java.lang.String name)
Get the value of a symbolStack.ValueAndType
getValueAndType(java.lang.String name)
Get the value and type of a symbol.boolean
hasValue(java.lang.String name)
Is the symbol in the symbol table?void
printSymbolTable(java.io.PrintWriter stream)
Print the symbol table on a streamstatic void
printVariable(org.slf4j.Logger log, java.lang.String pad, java.lang.String name, java.lang.Object value, boolean expandArraysAndMaps, boolean showClassName, java.lang.String headerName, java.lang.String headerValue)
Print a variablevoid
removeSymbols(java.util.Collection<? extends SymbolTable.VariableData> symbolDefinitions)
Removes symbols from the symbol tablevoid
setValue(java.lang.String name, java.lang.Object value)
Set the value of a symbolstatic boolean
validateName(java.lang.String name)
Validates the name of a symbolstatic java.lang.Object
validateStrictTyping(SymbolTable.InitialValueType type, java.lang.Object oldValue, java.lang.Object newValue)
Validates that the value can be assigned to a local or global variable of the specified type if strict typing is enforced.
-
-
-
Field Detail
-
log
static final org.slf4j.Logger log
-
-
Method Detail
-
getSymbols
java.util.Map<java.lang.String,SymbolTable.Symbol> getSymbols()
The list of symbols in the table- Returns:
- the symbols
-
getSymbolValues
java.util.Map<java.lang.String,java.lang.Object> getSymbolValues()
The list of symbols and their values in the table- Returns:
- the name of the symbols and their values
-
getValue
java.lang.Object getValue(java.lang.String name)
Get the value of a symbol- Parameters:
name
- the name- Returns:
- the value
-
getValueAndType
Stack.ValueAndType getValueAndType(java.lang.String name)
Get the value and type of a symbol. This method does not lookup global variables.- Parameters:
name
- the name- Returns:
- the value and type
-
hasValue
boolean hasValue(java.lang.String name)
Is the symbol in the symbol table?- Parameters:
name
- the name- Returns:
- true if the symbol exists, false otherwise
-
setValue
void setValue(java.lang.String name, java.lang.Object value)
Set the value of a symbol- Parameters:
name
- the namevalue
- the value
-
createSymbols
void createSymbols(java.util.Collection<? extends SymbolTable.VariableData> symbolDefinitions) throws JmriException
Add new symbols to the symbol table- Parameters:
symbolDefinitions
- the definitions of the new symbols- Throws:
JmriException
- if an exception is thrown
-
createSymbols
void createSymbols(SymbolTable symbolTable, java.util.Collection<? extends SymbolTable.VariableData> symbolDefinitions) throws JmriException
Add new symbols to the symbol table. This method is used for parameters, when new symbols might be created that uses symbols from a previous symbol table.- Parameters:
symbolTable
- the symbol table to get existing symbols fromsymbolDefinitions
- the definitions of the new symbols- Throws:
JmriException
- if an exception is thrown
-
removeSymbols
void removeSymbols(java.util.Collection<? extends SymbolTable.VariableData> symbolDefinitions) throws JmriException
Removes symbols from the symbol table- Parameters:
symbolDefinitions
- the definitions of the symbols to be removed- Throws:
JmriException
- if an exception is thrown
-
printSymbolTable
void printSymbolTable(java.io.PrintWriter stream)
Print the symbol table on a stream- Parameters:
stream
- the stream
-
validateName
static boolean validateName(java.lang.String name)
Validates the name of a symbol- Parameters:
name
- the name- Returns:
- true if the name is valid, false otherwise
-
getStack
Stack getStack()
Get the stack. This method is only used internally by DefaultSymbolTable.- Returns:
- the stack
-
printVariable
static void printVariable(org.slf4j.Logger log, java.lang.String pad, java.lang.String name, java.lang.Object value, boolean expandArraysAndMaps, boolean showClassName, java.lang.String headerName, java.lang.String headerValue)
Print a variable- Parameters:
log
- the loggerpad
- the paddingname
- the namevalue
- the valueexpandArraysAndMaps
- true if arrays and maps should be expanded, false otherwiseshowClassName
- true if class name should be shownheaderName
- header for the variable nameheaderValue
- header for the variable value
-
getInitialValue
static java.lang.Object getInitialValue(SymbolTable.Type type, java.lang.String name, SymbolTable.InitialValueType initialType, java.lang.String initialData, SymbolTable symbolTable, java.util.Map<java.lang.String,SymbolTable.Symbol> symbols) throws ParserException, JmriException
- Throws:
ParserException
JmriException
-
validateStrictTyping
static java.lang.Object validateStrictTyping(SymbolTable.InitialValueType type, java.lang.Object oldValue, java.lang.Object newValue) throws java.lang.NumberFormatException
Validates that the value can be assigned to a local or global variable of the specified type if strict typing is enforced. The caller must check first if this method should be called or not.- Parameters:
type
- the typeoldValue
- the old valuenewValue
- the new value- Returns:
- the value to assign. It might be converted if needed.
- Throws:
java.lang.NumberFormatException
-
-