Class IntHashMap<V>

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

public final class IntHashMap<V> extends Object implements Iterable<IntEntry<V>>
A HashMap-like data structure that maps 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

    • IntHashMap

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

      public IntHashMap(IntHashMap<V> map)
      Creates a new IntHashMap 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 key, 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:
      key - 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 key, V value)
      Associates the specified key with the specified value. If the key is already present in this map, nothing happens.
      Parameters:
      key - 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 key)
      Returns the value that is mapped to the specified key.
      Parameters:
      key - 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 key)
      Returns if the specified key is present in this map. This method is semantically equivalent to
      get(key) != null
      Parameters:
      key - The key that should be checked.
      Returns:
      If the specified key is present in this map.
    • remove

      public V remove(int key)
      Removes the entry with the specified key from this map. If the map does not contain the key, nothing happens.
      Parameters:
      key - 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 IntEntry<V>> action)
      Specified by:
      forEach in interface Iterable<V>
    • putAll

      public void putAll(IntHashMap<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<IntEntry<V>> iterator()
      Specified by:
      iterator in interface Iterable<V>