Package ints

Class IntMap<E>

  • Type Parameters:
    E - the type of values in this map

    public class IntMap<E>
    extends java.lang.Object

    Class IntMap represents a map with integer keys and generic type values.

    Class IntMap is not thread-safe.

    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all keys from this map.
      boolean contains​(int key)
      Returns true if the map contains the specified key, and returns false otherwise.
      E get​(int key)
      Returns the value for the specified key or null if the specified key is not present in this map.
      int key​(int index)
      Returns the specified key.
      int[] keys()
      Returns an array containing the keys in this map.
      E put​(int key, E value)
      Adds the specified key and value to this map.
      E remove​(int key)
      Removes the specified key from this map, and returns the value previously associated with the key or null if no such value exists.
      int size()
      Returns the number of keys in this map.
      java.lang.String toString()
      Returns java.util.Arrays.toString(this.keys()).
      java.util.List<E> values()
      Returns a list containing the values in this map.
      • Methods inherited from class java.lang.Object

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

      • IntMap

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

      • 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 E put​(int key,
                     E value)
        Adds the specified key and value to this map. If there exists a value in the map for the specified key, the old value is replaced with the specified value. The indexing of keys immediately before and after this method is invoked may differ if this map is changed by this operation.
        Parameters:
        key - the key
        value - the value
        Returns:
        the previous value associated with the key, or null if there did not exist a value for the specified key
      • remove

        public E remove​(int key)
        Removes the specified key from this map, and returns the value previously associated with the key or null if no such value exists. The indexing of keys immediately before and after this method is invoked may differ if this map is changed by this operation.
        Parameters:
        key - a key index
        Returns:
        the previous value associated with the key, or null if there did not exist a value for the specified key
      • 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:
        java.lang.IndexOutOfBoundsException - if index < 0 || index >= this.size()
      • get

        public E get​(int key)
        Returns the value for the specified key or null if the specified key is not present in this map.
        Parameters:
        key - the key
        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 java.util.List<E> values()
        Returns a list containing the values in this map. The returned array will satisfy: this.get(this.keys()[j])==this.values.get(j) for each j satisfying (0 <= j && j < this.size()).
        Returns:
        an array containing the values in this map
      • toString

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