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>
A stacked
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.
- Since:
- 2.0.0
- See Also:
-
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> -
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs a newStackedHashMap
.StackedHashMap
(Map<? extends K, ? extends V> m) Constructs a newStackedHashMap
with the same mappings as the suppliedMap
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the stack.entrySet()
peek()
Retrieves, but does not remove, the top element (HashMap
) from the stack.pop()
Pops the top element (HashMap
) from the stack.void
push()
Pushes a new element (HashMap
) onto the stack.int
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
-
Field Details
-
stack
-
-
Constructor Details
-
StackedHashMap
public StackedHashMap()Constructs a newStackedHashMap
. -
StackedHashMap
Constructs a newStackedHashMap
with the same mappings as the suppliedMap
.- Parameters:
m
- the map whose mappings are to be placed in this stacked map
-
-
Method Details
-
push
public void push()Pushes a new element (HashMap
) onto the stack. -
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
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. -
put
-
entrySet
-