Package com.blackrook.archetext.struct
Class HashDequeMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,Deque<V>>
-
- com.blackrook.archetext.struct.HashDequeMap<K,V>
-
- Type Parameters:
K
- the key type.V
- the value type stored.
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,Deque<V>>
public class HashDequeMap<K,V> extends HashMap<K,Deque<V>>
A hash map that stores deques of a particular type.- Author:
- Matthew Tropiano
- See Also:
- Serialized Form
-
-
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 HashDequeMap()
Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(K key, V value)
Adds a value to the end of a deque.void
addFirst(K key, V value)
Adds a value to the beginning of a deque.void
addLast(K key, V value)
Adds a value to the end of a deque.protected Deque<V>
create()
Called to create a new Deque implementation that gets stored in the table.V
peekFirst(K key)
Returns the value at the beginning of a deque.V
peekLast(K key)
Returns the value at the end of a deque.V
poll(K key)
Removes a value from the front of a deque.V
pollFirst(K key)
Removes a value from the beginning of a deque.V
pollLast(K key)
Removes a value from the end of a deque.V
pop(K key)
Removes a value from the front of a deque.void
push(K key, V value)
Adds a value to the front of a deque.V
removeFirst(K key)
Removes a value from the beginning of a deque.V
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 Detail
-
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 Detail
-
create
protected Deque<V> create()
Called to create a new Deque implementation that gets stored in the table. By default, this callsnew LinkedList<>()
.- Returns:
- a new deque.
-
addFirst
public void addFirst(K key, V value)
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:
Deque.addFirst(Object)
-
addLast
public void addLast(K key, V value)
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:
Deque.addLast(Object)
-
removeFirst
public V removeFirst(K key)
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:
Deque.removeFirst()
-
removeLast
public V removeLast(K key)
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:
Deque.removeLast()
-
pollFirst
public V pollFirst(K key)
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:
Deque.pollFirst()
-
pollLast
public V pollLast(K key)
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:
Deque.pollLast()
-
peekFirst
public V peekFirst(K key)
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:
Deque.peekFirst()
-
peekLast
public V peekLast(K key)
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:
Deque.peekLast()
-
add
public boolean add(K key, V value)
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:
Deque.add(Object)
-
removeValue
public boolean removeValue(K key, V value)
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:
Deque.remove(Object)
-
pop
public V pop(K key)
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:
Deque.pop()
-
poll
public V poll(K key)
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:
Deque.poll()
-
push
public void push(K key, V value)
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:
Deque.push(Object)
-
-