Class SortedIntMap<V>

java.lang.Object
com.deco2800.game.utils.SortedIntMap<V>
Type Parameters:
V - Class type to map
All Implemented Interfaces:
java.lang.Iterable<V>

public class SortedIntMap<V>
extends java.lang.Object
implements java.lang.Iterable<V>
A map sorted by the value of key with O(1) iteration. put/get/contains are O(n). useful when we don't modify values often, but want to iterate quickly.
  • Constructor Summary

    Constructors 
    Constructor Description
    SortedIntMap​(int capacity)
    Create a sorted intmap with the specified capacity
  • Method Summary

    Modifier and Type Method Description
    void clear()
    Clear the map
    boolean contains​(V value)  
    boolean containsKey​(int key)  
    void forEach​(java.util.function.Consumer<? super V> action)  
    V get​(int key)
    Get value from map
    java.util.Iterator<V> iterator()  
    void put​(int key, V value)
    Put key, value pair in map
    java.util.Spliterator<V> spliterator()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SortedIntMap

      public SortedIntMap​(int capacity)
      Create a sorted intmap with the specified capacity
      Parameters:
      capacity - initial capacity
  • Method Details

    • containsKey

      public boolean containsKey​(int key)
      Parameters:
      key - map key
      Returns:
      true if map contains key
    • contains

      public boolean contains​(V value)
      Parameters:
      value - value in map
      Returns:
      true if map contains value
    • put

      public void put​(int key, V value)
      Put key, value pair in map
      Parameters:
      key - key
      value - value
    • get

      public V get​(int key)
      Get value from map
      Parameters:
      key - map key
      Returns:
      map value or null if not found
    • clear

      public void clear()
      Clear the map
    • iterator

      public java.util.Iterator<V> iterator()
      Specified by:
      iterator in interface java.lang.Iterable<V>
    • forEach

      public void forEach​(java.util.function.Consumer<? super V> action)
      Specified by:
      forEach in interface java.lang.Iterable<V>
    • spliterator

      public java.util.Spliterator<V> spliterator()
      Specified by:
      spliterator in interface java.lang.Iterable<V>