K - the type of keys maintained by this mapV - the type of mapped valuespublic class StackedHashMap<K,V>
extends java.util.AbstractMap<K,V>
HashMap implementation.
This implementation is useful if you want to add and/or remove mappings to a map, but also want to return to a previous state of the map easily.
HashMap| Modifier and Type | Field and Description |
|---|---|
protected java.util.Deque<java.util.HashMap<K,V>> |
stack |
| Constructor and Description |
|---|
StackedHashMap()
Constructs a new
StackedHashMap. |
StackedHashMap(java.util.Map<? extends K,? extends V> m)
Constructs a new
StackedHashMap with the same mappings as the supplied Map. |
| Modifier and Type | Method and Description |
|---|---|
void |
clearStack()
Clears the stack.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
java.util.HashMap<K,V> |
peek()
Retrieves, but does not remove, the top element (
HashMap) from the stack. |
java.util.HashMap<K,V> |
pop()
Pops the top element (
HashMap) from the stack. |
void |
push()
Pushes a new element (
HashMap) onto the stack. |
V |
put(K key,
V value) |
int |
stackSize()
Returns the number of elements (
HashMaps) on the stack. |
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, valuespublic void push()
HashMap) onto the stack.public java.util.HashMap<K,V> pop()
HashMap) from the stack. Note that the initial element cannot be popped from the stack.java.lang.IllegalStateException - if there is only 1 element on the stackpublic java.util.HashMap<K,V> peek()
HashMap) from the stack.public int stackSize()
HashMaps) on the stack. There will always be at least {code 1} element on the stack.public void clearStack()
1 element (HashMap) on the stack without any mappings.