com.hazelcast.util.collection

## Class Long2ObjectHashMap<V>

- java.lang.Object
- - com.hazelcast.util.collection.Long2ObjectHashMap<V>

- Type Parameters:
    `V` - values stored in the `Map`
  All Implemented Interfaces:
    Map<Long,V>

      public class Long2ObjectHashMap<V>
      extends Object
      implements Map<Long,V>

  `Map` implementation specialised for `long` keys using open addressing and linear probing for cache efficient access.

  NOTE: This map doesn't support `null` keys and values.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `Long2ObjectHashMap.KeyIterator` Adds an unboxed next() method to the standard Iterator interface.
    `class` | `Long2ObjectHashMap.KeySet` Adds non-boxing methods to the standard Set interface.

    - ### Nested classes/interfaces inherited from interface java.util.Map

      `Map.Entry<K,V>`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_INITIAL_CAPACITY` The default initial capacity for constructors not explicitly supplying it
    `static double` | `DEFAULT_LOAD_FACTOR` The default load factor for constructors not explicitly supplying it

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Long2ObjectHashMap()`
    `Long2ObjectHashMap(int initialCapacity)`
    `Long2ObjectHashMap(int initialCapacity, double loadFactor)` Construct a new map allowing a configuration for initial capacity and load factor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `capacity()` Get the total capacity for the map to which the load factor with be a fraction of.
    `void` | `clear()`
    `void` | `compact()` Compact the `Map` backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.
    `V` | `computeIfAbsent(long key, LongFunction<? extends V> mappingFunction)` Get a value for a given key, or if it does ot exist then default the value via a `LongFunction` and put it in the map.
    `boolean` | `containsKey(long key)` Overloaded version of `Map.containsKey(Object)` that takes a primitive long key.
    `boolean` | `containsKey(Object key)`
    `boolean` | `containsValue(Object value)`
    `Set<Map.Entry<Long,V>>` | `entrySet()` This set's iterator also implements `Map.Entry` so the `next()` method can just return the iterator instance itself with no heap allocation.
    `V` | `get(long key)` Overloaded version of `Map.get(Object)` that takes a primitive long key.
    `V` | `get(Object key)`
    `boolean` | `isEmpty()`
    `Long2ObjectHashMap.KeySet` | `keySet()`
    `double` | `loadFactor()` Get the load factor beyond which the map will increase size.
    `V` | `put(long key, V value)` Overloaded version of `Map.put(Object, Object)` that takes a primitive long key.
    `V` | `put(Long key, V value)`
    `void` | `putAll(Map<? extends Long,? extends V> map)`
    `V` | `remove(long key)` Overloaded version of `Map.remove(Object)` that takes a primitive long key.
    `V` | `remove(Object key)`
    `int` | `resizeThreshold()` Get the actual threshold which when reached the map resize.
    `int` | `size()`
    `String` | `toString()`
    `Collection<V>` | `values()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Map

      `compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll`

- - ### Field Detail

    - #### DEFAULT_LOAD_FACTOR

          public static final double DEFAULT_LOAD_FACTOR

      The default load factor for constructors not explicitly supplying it
      See Also:
        Constant Field Values

    - #### DEFAULT_INITIAL_CAPACITY

          public static final int DEFAULT_INITIAL_CAPACITY

      The default initial capacity for constructors not explicitly supplying it
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Long2ObjectHashMap

          public Long2ObjectHashMap()

    - #### Long2ObjectHashMap

          public Long2ObjectHashMap(int initialCapacity)

    - #### Long2ObjectHashMap

          public Long2ObjectHashMap(int initialCapacity,
                                    double loadFactor)

      Construct a new map allowing a configuration for initial capacity and load factor.
      Parameters:
        `initialCapacity` - for the backing array
        `loadFactor` - limit for resizing on puts

  - ### Method Detail

    - #### loadFactor

          public double loadFactor()

      Get the load factor beyond which the map will increase size.
      Returns:
        load factor for when the map should increase size.

    - #### capacity

          public int capacity()

      Get the total capacity for the map to which the load factor with be a fraction of.
      Returns:
        the total capacity for the map.

    - #### resizeThreshold

          public int resizeThreshold()

      Get the actual threshold which when reached the map resize. This is a function of the current capacity and load factor.
      Returns:
        the threshold when the map will resize.

    - #### size

          public int size()

      Specified by:
        `size` in interface `Map<Long,V>`

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `Map<Long,V>`

    - #### containsKey

          public boolean containsKey(Object key)

      Specified by:
        `containsKey` in interface `Map<Long,V>`

    - #### containsKey

          public boolean containsKey(long key)

      Overloaded version of `Map.containsKey(Object)` that takes a primitive long key.
      Parameters:
        `key` - for indexing the `Map`
      Returns:
        true if the key is found otherwise false.

    - #### containsValue

          public boolean containsValue(Object value)

      Specified by:
        `containsValue` in interface `Map<Long,V>`

    - #### get

          public V get(Object key)

      Specified by:
        `get` in interface `Map<Long,V>`

    - #### get

          public V get(long key)

      Overloaded version of `Map.get(Object)` that takes a primitive long key.
      Parameters:
        `key` - for indexing the `Map`
      Returns:
        the value if found otherwise null

    - #### computeIfAbsent

          public V computeIfAbsent(long key,
                                   LongFunction<? extends V> mappingFunction)

      Get a value for a given key, or if it does ot exist then default the value via a `LongFunction` and put it in the map.
      Parameters:
        `key` - to search on.
        `mappingFunction` - to provide a value if the get returns null.
      Returns:
        the value if found otherwise the default.

    - #### put

          public V put(Long key,
                       V value)

      Specified by:
        `put` in interface `Map<Long,V>`

    - #### put

          public V put(long key,
                       V value)

      Overloaded version of `Map.put(Object, Object)` that takes a primitive long key.
      Parameters:
        `key` - for indexing the `Map`
        `value` - to be inserted in the `Map`
      Returns:
        the previous value if found otherwise null

    - #### remove

          public V remove(Object key)

      Specified by:
        `remove` in interface `Map<Long,V>`

    - #### remove

          public V remove(long key)

      Overloaded version of `Map.remove(Object)` that takes a primitive long key.
      Parameters:
        `key` - for indexing the `Map`
      Returns:
        the value if found otherwise null

    - #### clear

          public void clear()

      Specified by:
        `clear` in interface `Map<Long,V>`

    - #### compact

          public void compact()

      Compact the `Map` backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.

    - #### putAll

          public void putAll(Map<? extends Long,? extends V> map)

      Specified by:
        `putAll` in interface `Map<Long,V>`

    - #### keySet

          public Long2ObjectHashMap.KeySet keySet()

      Specified by:
        `keySet` in interface `Map<Long,V>`

    - #### values

          public Collection<V> values()

      Specified by:
        `values` in interface `Map<Long,V>`

    - #### entrySet

          public Set<Map.Entry<Long,V>> entrySet()

      This set's iterator also implements `Map.Entry` so the `next()` method can just return the iterator instance itself with no heap allocation. This characteristic makes the set unusable wherever the returned entries are retained (such as `coll.addAll(entrySet)`.
      Specified by:
        `entrySet` in interface `Map<Long,V>`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2020. All rights reserved.