- java.lang.Object
-
- edu.uiuc.ncsa.security.core.state.SStack<V>
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
EnvStack
public abstract class SStack<V extends STable<? extends SKey,? extends SThing>> extends Object implements Serializable
A stateful stack of things, such as functions. This is the method by which local state is preserved. The zero-th element is the current local table. It is used for entries., hence the prefix of S for it and things related to it.Usage
Create a subclass as needed for your objects. This involves an
SStack
,STable
,SKey
and anSThing
.How state is managed
If we had the following QDL:f(x)->x^2; block[f(x)->x^3;...]
ThenSStack
subclass for functions inside the block would look liketable entry 0 f(x)->x^3 1 f(x)->x^2
Calls toget(SKey)
would peek at 0 and return f(x)->x^3 inside the block. This is how local state overrides the parent state. Blocks of course can be for loops, functions, conditionals etc. Were there no entry for f(x) in the block, thenSStack
would return f(x)->x^2.Created by Jeff Gaynor
on 11/8/21 at 6:27 AM- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SStack.ROMap
A read-only map that virtualizes this stack.
-
Constructor Summary
Constructors Constructor Description SStack()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addTables(SStack sStack)
Take an SStack and prepend in the correct order to the front of the stack.List<SKey>
allKeys()
Returns the a list of keys (including redundancies) for this stack.void
append(V v)
Append the table to the end of the stack -- this sets the root for the table.void
appendTables(SStack sStack)
Similar toaddTables(SStack)
, but this appends them to the existing set of tables.void
clear()
Clears the entire stack and resets it.SStack
clone()
boolean
containsKey(SKey key)
boolean
containsKey(SKey key, int startTableIndex)
Check that a specific key is in a table starting at the index.SThing
get(SKey key)
Get the value from someplace in the stack.List<? extends SThing>
getAll()
Get all of the values from all tables.This returns a flat list.Map<String,String>
getAsMap()
Get a read only virtualization of this stack as a map.STable<? extends SKey,? extends SThing>
getLocal()
Get the local table for this stack.STable<? extends SKey,? extends SThing>
getRoot()
Since all new tables are added at 0, the initial one, called the root, is last.List<STable<? extends SKey,? extends SThing>>
getStack()
boolean
isEmpty()
Set<SKey>
keySet()
Returns the unique set of keys over the tables.SThing
localGet(SKey key)
Only returns a non-null element if it is defined in the local (index 0) table.boolean
localHas(SKey xkey)
SThing
localPut(SThing value)
Only add this to the local state.void
localRemove(SKey key)
Removes only the most local entry.abstract SStack
newInstance()
abstract STable
newTableInstance()
SThing
nonlocalGet(SKey key)
searches for the entry every place except the most local state.STable<SKey,SThing>
peek()
STable<SKey,SThing>
pop()
Remove the most local table.void
push(STable<? extends SKey,? extends SThing> sTable)
void
pushNewTable()
SThing
put(SKey sKey, SThing xThing)
SThing
put(SThing value)
void
remove(SKey key)
Removes all references from all tables.void
setStack(List<STable<? extends SKey,? extends SThing>> stack)
int
size()
String
toString()
String
toString(boolean showKeys)
-
-
-
Method Detail
-
clear
public void clear()
Clears the entire stack and resets it.
-
addTables
public void addTables(SStack sStack)
Take an SStack and prepend in the correct order to the front of the stack. If SStack is [A,B,C,...] And the existing stack is [P,Q,...] the result is [A,B,C,...,P,Q,...] This is needed when, e.g., creating new local state for function reference resolution
Note:get(SKey)
starts from index 0, so local overrides are first!- Parameters:
sStack
-
-
appendTables
public void appendTables(SStack sStack)
Similar toaddTables(SStack)
, but this appends them to the existing set of tables. If SStack is [A,B,C,...] And the existing stack is [P,Q,...] the result is [P,Q,...,A,B,C,...,]
Note:get(SKey)
starts from index 0, so local overrides are first!- Parameters:
sStack
-
-
newInstance
public abstract SStack newInstance()
-
newTableInstance
public abstract STable newTableInstance()
-
append
public void append(V v)
Append the table to the end of the stack -- this sets the root for the table.- Parameters:
v
-
-
containsKey
public boolean containsKey(SKey key, int startTableIndex)
Check that a specific key is in a table starting at the index. This lets you, e.g., skip local state if the start index is positive.- Parameters:
key
-startTableIndex
-- Returns:
-
containsKey
public boolean containsKey(SKey key)
-
localGet
public SThing localGet(SKey key)
Only returns a non-null element if it is defined in the local (index 0) table.- Parameters:
key
-- Returns:
-
getLocal
public STable<? extends SKey,? extends SThing> getLocal()
Get the local table for this stack.- Returns:
-
localHas
public boolean localHas(SKey xkey)
-
get
public SThing get(SKey key)
Get the value from someplace in the stack. This returns first found so manages the overrides in the scope. Note that local calls (e.g.localGet(SKey)
only look in the current scope.- Parameters:
key
-- Returns:
-
nonlocalGet
public SThing nonlocalGet(SKey key)
searches for the entry every place except the most local state.- Parameters:
key
-- Returns:
-
getAll
public List<? extends SThing> getAll()
Get all of the values from all tables.This returns a flat list.- Returns:
-
getRoot
public STable<? extends SKey,? extends SThing> getRoot()
Since all new tables are added at 0, the initial one, called the root, is last. This gets the rootSTable
.- Returns:
-
isEmpty
public boolean isEmpty()
-
pushNewTable
public void pushNewTable()
-
localPut
public SThing localPut(SThing value)
Only add this to the local state.- Parameters:
value
-- Returns:
-
localRemove
public void localRemove(SKey key)
Removes only the most local entry.- Parameters:
key
-
-
remove
public void remove(SKey key)
Removes all references from all tables. This includes all overrides so at the end of this operation there are no references any place.- Parameters:
key
-
-
size
public int size()
-
toString
public String toString(boolean showKeys)
-
allKeys
public List<SKey> allKeys()
Returns the a list of keys (including redundancies) for this stack.- Returns:
-
-