Class Int3HashMap<V>

java.lang.Object
de.tomatengames.util.map.Int3HashMap<V>
Type Parameters:
V - The type of the values.
All Implemented Interfaces:
Iterable<Int3Entry<V>>

public final class Int3HashMap<V> extends Object implements Iterable<Int3Entry<V>>
A HashMap-like data structure that maps (int, int, int) keys to object values. Equality of keys is checked by using the == operator

This map does not allow null values. This implementation does not allow concurrent modifications.

Since:
1.3
  • Constructor Details

    • Int3HashMap

      public Int3HashMap()
      Creates a new and empty Int3HashMap.
    • Int3HashMap

      public Int3HashMap(Int3HashMap<V> map)
      Creates a new Int3HashMap that contains all the mappings of the specified map.
      Parameters:
      map - The mappings that should be cloned.
  • Method Details

    • size

      public long size()
      Returns the number of entries in this map.
      Returns:
      The number of entries.
    • isEmpty

      public boolean isEmpty()
      Returns if this map does not contain any entry.
      Returns:
      If this map has no entries.
    • put

      public V put(int key1, int key2, int key3, V value)
      Associates the specified key with the specified value. If the key is already present in this map, the previous value is replaced.
      Parameters:
      key1 - A component of the key of the new mapping.
      key2 - A component of the key of the new mapping.
      key3 - A component of the key of the new mapping.
      value - The value of the new mapping. Must not null.
      Returns:
      The value that was previously mapped to the key. If the key was not present in this map, null is returned.
      Throws:
      IllegalArgumentException - If the value is null.
    • putIfAbsent

      public V putIfAbsent(int key1, int key2, int key3, V value)
      Associates the specified key with the specified value. If the key is already present in this map, nothing happens.
      Parameters:
      key1 - A component of the key of the new mapping.
      key2 - A component of the key of the new mapping.
      key3 - A component of the key of the new mapping.
      value - The value of the new mapping. Must not null.
      Returns:
      The value that was previously mapped to the key. If null, the new value has been put into the map. Otherwise, the previous value is still present.
      Throws:
      IllegalArgumentException - If the value is null.
    • get

      public V get(int key1, int key2, int key3)
      Returns the value that is mapped to the specified key.
      Parameters:
      key1 - A component of the key whose value should be returned.
      key2 - A component of the key whose value should be returned.
      key3 - A component of the key whose value should be returned.
      Returns:
      The value that the specified key is mapped to. If this map does not contain the key, null is returned.
    • containsKey

      public boolean containsKey(int key1, int key2, int key3)
      Returns if the specified key is present in this map. This method is semantically equivalent to
      get(key) != null
      Parameters:
      key1 - A component of the key that should be checked.
      key2 - A component of the key that should be checked.
      key3 - A component of the key that should be checked.
      Returns:
      If the specified key is present in this map.
    • remove

      public V remove(int key1, int key2, int key3)
      Removes the entry with the specified key from this map. If the map does not contain the key, nothing happens.
      Parameters:
      key1 - A component of the key of the entry that should be removed.
      key2 - A component of the key of the entry that should be removed.
      key3 - A component of the key of the entry that should be removed.
      Returns:
      The value of the entry that was removed. If no entry was removed, null is returned.
    • clear

      public void clear()
      Removes all entries from this map.
    • forEach

      public void forEach(Consumer<? super Int3Entry<V>> action)
      Specified by:
      forEach in interface Iterable<V>
    • putAll

      public void putAll(Int3HashMap<V> otherMap)
      Puts all mappings of the specified map into this map. Keys that are present in both maps are replaced in this map. If the specified map is null or this map, nothing happens.
      Parameters:
      otherMap - The map whose mappings should be put into this map. May be null.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • iterator

      public Iterator<Int3Entry<V>> iterator()
      Specified by:
      iterator in interface Iterable<V>