Package ints

Class IntIntMap

java.lang.Object
ints.IntIntMap

public class IntIntMap extends Object

Class IntIntMap represents a map with integer keys and integer values.

Class IntIntMap is not thread-safe.

  • Constructor Summary

    Constructors
    Constructor
    Description
    IntIntMap(int capacity)
    Creates a new IntMap instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all keys from this map.
    boolean
    contains(int key)
    Returns true if the map contains the specified key, and returns false otherwise.
    int
    get(int key, int sentinel)
    Returns the value for the specified key or the specified sentinel value if the specified key is not present in this map.
    int
    key(int index)
    Returns the specified key.
    int[]
    Returns an array containing the keys in this map.
    boolean
    put(int key, int value)
    Adds the specified key and value to this map.
    boolean
    remove(int key)
    Removes the specified key from this map.
    int
    Returns the number of keys in this map.
    Returns java.util.Arrays.toString(this.keys()).
    int[]
    Returns an array containing the values in this map.

    Methods inherited from class java.lang.Object

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

    • IntIntMap

      public IntIntMap(int capacity)
      Creates a new IntMap instance.
      Parameters:
      capacity - the initial capacity of this map
      Throws:
      IllegalArgumentException - if capacity < 0 || (capacity > (1 << 30))
  • Method Details

    • clear

      public void clear()
      Removes all keys from this map.
    • contains

      public boolean contains(int key)
      Returns true if the map contains the specified key, and returns false otherwise.
      Parameters:
      key - a key
      Returns:
      true if the map contains the specified key
    • put

      public boolean put(int key, int value)
      Adds the specified key and value to this map. Returns true if this map was changed by the operation, and returns false otherwise. The indexing of keys immediately before and after this method is invoked may differ if this map was changed by the operation.
      Parameters:
      key - they key
      value - the value
      Returns:
      true if this map was changed by the operation
    • remove

      public boolean remove(int key)
      Removes the specified key from this map. Returns true if this map was changed by the operation, and returns false otherwise. The indexing of keys immediately before and after this method is invoked may differ if this map was changed by the operation.
      Parameters:
      key - a key index
      Returns:
      true if this map was changed by the operation
    • key

      public int key(int index)
      Returns the specified key.
      Parameters:
      index - an index of a key in this map
      Returns:
      the specified key
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >= this.size()
    • get

      public int get(int key, int sentinel)
      Returns the value for the specified key or the specified sentinel value if the specified key is not present in this map.
      Parameters:
      key - the key
      sentinel - the value to be returned if the specified key is not present in this map
      Returns:
      the specified value
    • size

      public int size()
      Returns the number of keys in this map.
      Returns:
      the number of keys in this map
    • keys

      public int[] keys()
      Returns an array containing the keys in this map. The returned array will satisfy: this.toArray()[j]==this.key(j) for each j satisfying (0 <= j && j < this.size()).
      Returns:
      an array containing the keys in this map
    • values

      public int[] values()
      Returns an array containing the values in this map. The returned array will satisfy: this.toArray()[j]==this.value(this.key(j)) for each j satisfying (0 <= j && j < this.size()).
      Returns:
      an array containing the values in this map
    • toString

      public String toString()
      Returns java.util.Arrays.toString(this.keys()).
      Overrides:
      toString in class Object
      Returns:
      java.util.Arrays.toString(this.keys())