Package com.blackrook.small.struct
Class HashDequeMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,Deque<V>>
com.blackrook.small.struct.HashDequeMap<K,V>
- Type Parameters:
K
- the key type.V
- the value type stored.
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,
Deque<V>>
A hash map that stores deques of a particular type.
- Author:
- Matthew Tropiano
- 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> -
Constructor Summary
ConstructorDescriptionCreates a new HashDequeMap that has default capacity and load factor.HashDequeMap
(int initialCapacity) Creates a new HashDequeMap that has a specific capacity and default load factor.HashDequeMap
(int initialCapacity, float loadFactor) Creates a new HashDequeMap that has a specific capacity and default load factor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds a value to the end of a deque.void
Adds a value to the beginning of a deque.void
Adds a value to the end of a deque.create()
Called to create a new Deque implementation that gets stored in the table.Returns the value at the beginning of a deque.Returns the value at the end of a deque.Removes a value from the front of a deque.Removes a value from the beginning of a deque.Removes a value from the end of a deque.Removes a value from the front of a deque.void
Adds a value to the front of a deque.removeFirst
(K key) Removes a value from the beginning of a deque.removeLast
(K key) Removes a value from the end of a deque.boolean
removeValue
(K key, V value) Removes a value from a deque.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
HashDequeMap
public HashDequeMap()Creates a new HashDequeMap that has default capacity and load factor. -
HashDequeMap
public HashDequeMap(int initialCapacity) Creates a new HashDequeMap that has a specific capacity and default load factor.- Parameters:
initialCapacity
- the initial capacity.
-
HashDequeMap
public HashDequeMap(int initialCapacity, float loadFactor) Creates a new HashDequeMap that has a specific capacity and default load factor.- Parameters:
initialCapacity
- the initial capacity.loadFactor
- the load factor.
-
-
Method Details
-
create
Called to create a new Deque implementation that gets stored in the table. By default, this callsnew LinkedList%lt;>()
.- Returns:
- a new deque.
-
addFirst
Adds a value to the beginning of a deque. If no corresponding deque, this creates a new deque.- Parameters:
key
- the key.value
- the value.- See Also:
-
addLast
Adds a value to the end of a deque. If no corresponding deque, this creates a new deque.- Parameters:
key
- the key.value
- the value.- See Also:
-
removeFirst
Removes a value from the beginning of a deque. If no corresponding deque, this throws an exception.- Parameters:
key
- the key.- Returns:
- the element removed.
- Throws:
NoSuchElementException
- if the key does not correspond to an existing deque.- See Also:
-
removeLast
Removes a value from the end of a deque. If no corresponding deque, this throws an exception.- Parameters:
key
- the key.- Returns:
- the element removed.
- Throws:
NoSuchElementException
- if the key does not correspond to an existing deque.- See Also:
-
pollFirst
Removes a value from the beginning of a deque. If no corresponding deque, this returns null.- Parameters:
key
- the key.- Returns:
- the element removed, or null if no element.
- See Also:
-
pollLast
Removes a value from the end of a deque. If no corresponding deque, this returns null.- Parameters:
key
- the key.- Returns:
- the element removed, or null if no element.
- See Also:
-
peekFirst
Returns the value at the beginning of a deque. If no corresponding deque, this returns null.- Parameters:
key
- the key.- Returns:
- the element found, or null if no element.
- See Also:
-
peekLast
Returns the value at the end of a deque. If no corresponding deque, this returns null.- Parameters:
key
- the key.- Returns:
- the element found, or null if no element.
- See Also:
-
add
Adds a value to the end of a deque. If no corresponding deque, this creates a new deque.- Parameters:
key
- the key.value
- the value.- Returns:
- true (as specified by
Collection.add(Object)
) - See Also:
-
removeValue
Removes a value from a deque. If no corresponding deque, this returns false.- Parameters:
key
- the key.value
- the value to remove.- Returns:
true
if an element was removed as a result of this call- Throws:
ClassCastException
- if the class of the specified element is incompatible with the deque (optional)NullPointerException
- if the specified element is null and this deque does not permit null elements (optional)- See Also:
-
pop
Removes a value from the front of a deque. If no corresponding deque, this throws an exception.- Parameters:
key
- the key.- Returns:
- the element removed.
- Throws:
NoSuchElementException
- if the key does not correspond to an existing deque.- See Also:
-
poll
Removes a value from the front of a deque. If no corresponding deque, this returns null.- Parameters:
key
- the key.- Returns:
- the element removed, or null if no element.
- See Also:
-
push
Adds a value to the front of a deque. If no corresponding deque, this creates it.- Parameters:
key
- the key.value
- the value.- See Also:
-