Class Map2<K,V>

java.lang.Object
components.map.MapSecondary<K,V>
components.map.Map2<K,V>
Type Parameters:
K - type of Map domain (key) entries
V - type of Map range (associated value) entries
All Implemented Interfaces:
Map<K,V>, MapKernel<K,V>, Standard<Map<K,V>>, Iterable<Map.Pair<K,V>>

public class Map2<K,V> extends MapSecondary<K,V>
Map represented as a Queue of pairs with implementations of primary methods.
Representation Invariant (concrete invariant of $this):
for all key1, key2: K, value1, value2: V, str1, str2: string of (key, value)
    where (str1 * <(key1, value1)> is prefix of $this.pairsQueue and
           str2 * <(key2, value2)> is prefix of $this.pairsQueue and
           str1 /= str2)
  (key1 /= key2)
Abstraction Relation (interpretation mapping between $this and this):
this = entries($this.pairsQueue)
  • Constructor Details

    • Map2

      public Map2()
      No-argument constructor.
  • Method Details

    • newInstance

      public final Map<K,V> newInstance()
      Description copied from interface: Standard
      Returns a new object with the same dynamic type as this, having an initial value. If the type T has a no-argument constructor, then the value of the new returned object satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then the value of the new returned object satisfies the contract of the constructor call that was used to initialize this .
      Returns:
      new object "like" this with an initial value
    • clear

      public final void clear()
      Description copied from interface: Standard
      Resets this to an initial value. If the type T has a no-argument constructor, then this satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then this satisfies the contract of the constructor call that was used to initialize #this.
    • transferFrom

      public final void transferFrom(Map<K,V> source)
      Description copied from interface: Standard
      Sets this to the incoming value of source, and resets source to an initial value; the declaration notwithstanding, the dynamic type of source must be the same as the dynamic type of this. If the type T has a no-argument constructor, then source satisfies the contract of the no-argument constructor for T. If T does not have a no-argument constructor, then source satisfies the contract of the constructor call that was used to initialize #source.
      Parameters:
      source - object whose value is to be transferred
    • add

      public final void add(K key, V value)
      Description copied from interface: MapKernel
      Adds the pair (key, value) to this.
      Parameters:
      key - the key to be added
      value - the associated value to be added
    • remove

      public final Map.Pair<K,V> remove(K key)
      Description copied from interface: MapKernel
      Removes the pair whose first component is key and returns it.
      Parameters:
      key - the key to be removed
      Returns:
      the pair removed
    • removeAny

      public final Map.Pair<K,V> removeAny()
      Description copied from interface: MapKernel
      Removes and returns an arbitrary pair from this.
      Returns:
      the pair removed from this
    • value

      public final V value(K key)
      Description copied from interface: MapKernel
      Reports the value associated with key in this.
      Parameters:
      key - the key whose associated value is to be reported
      Returns:
      the value associated with key
    • hasKey

      public final boolean hasKey(K key)
      Description copied from interface: MapKernel
      Reports whether there is a pair in this whose first component is key.
      Parameters:
      key - the key to be checked
      Returns:
      true iff there is a pair in this whose first component is key
    • size

      public final int size()
      Description copied from interface: MapKernel
      Reports size of this.
      Returns:
      the number of pairs in this
    • iterator

      public final Iterator<Map.Pair<K,V>> iterator()