K
- the type of keys maintained by this mapV
- the type of mapped valuespublic class StackedHashMap<K,V> extends 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
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
StackedHashMap()
Constructs a new
StackedHashMap . |
StackedHashMap(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.
|
Set<Map.Entry<K,V>> |
entrySet() |
HashMap<K,V> |
peek()
Retrieves, but does not remove, the top element (
HashMap ) from the stack. |
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 (
HashMap s) on the stack. |
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public void push()
HashMap
) onto the stack.public HashMap<K,V> pop()
HashMap
) from the stack. Note that the initial element cannot be popped from the stack.IllegalStateException
- if there is only 1
element on the stackpublic HashMap<K,V> peek()
HashMap
) from the stack.public int stackSize()
HashMap
s) 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.