Class HashDequeMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,Deque<V>>
com.blackrook.rookscript.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:
  • 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

      protected Deque<V> create()
      Called to create a new Deque implementation that gets stored in the table. By default, this calls new 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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: