Package org.hawaiiframework.util
Class StackedHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.hawaiiframework.util.StackedHashMap<K,V>
-
- Type Parameters:
K
- the type of keys maintained by this mapV
- the type of mapped values
- All Implemented Interfaces:
Map<K,V>
public class StackedHashMap<K,V> extends AbstractMap<K,V>
A stackedHashMap
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.
- Since:
- 2.0.0
- Author:
- Marcel Overdijk
- See Also:
HashMap
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description StackedHashMap()
Constructs a newStackedHashMap
.StackedHashMap(Map<? extends K,? extends V> m)
Constructs a newStackedHashMap
with the same mappings as the suppliedMap
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
push
public void push()
Pushes a new element (HashMap
) onto the stack.
-
pop
public HashMap<K,V> pop()
Pops the top element (HashMap
) from the stack. Note that the initial element cannot be popped from the stack.- Returns:
- the top element of the stack
- Throws:
IllegalStateException
- if there is only1
element on the stack
-
peek
public HashMap<K,V> peek()
Retrieves, but does not remove, the top element (HashMap
) from the stack.- Returns:
- the top element of the stack
-
stackSize
public int stackSize()
Returns the number of elements (HashMap
s) on the stack. There will always be at least {code 1} element on the stack.- Returns:
- the number of elements on the stack
-
clearStack
public void clearStack()
Clears the stack. After clearing the stack there will be1
element (HashMap
) on the stack without any mappings.
-
-