Class ConcurrentSkipListIntObjMultimap<V>

java.lang.Object
io.netty.util.concurrent.ConcurrentSkipListIntObjMultimap<V>
Type Parameters:
V - the type of mapped values
All Implemented Interfaces:
Iterable<ConcurrentSkipListIntObjMultimap.IntEntry<V>>

public class ConcurrentSkipListIntObjMultimap<V> extends Object implements Iterable<ConcurrentSkipListIntObjMultimap.IntEntry<V>>
A scalable concurrent multimap implementation. The map is sorted according to the natural ordering of its int keys.

This class implements a concurrent variant of SkipLists providing expected average log(n) time cost for the containsKey, get, put and remove operations and their variants. Insertion, removal, update, and access operations safely execute concurrently by multiple threads.

This class is a multimap, which means the same key can be associated with multiple values. Each such instance will be represented by a separate IntEntry. There is no defined ordering for the values mapped to the same key.

As a multimap, certain atomic operations like putIfPresent, compute, or computeIfPresent, cannot be supported. Likewise, some get-like operations cannot be supported.

Iterators and spliterators are weakly consistent.

All IntEntry pairs returned by methods in this class represent snapshots of mappings at the time they were produced. They do not support the Entry.setValue method. (Note however that it is possible to change mappings in the associated map using put, putIfAbsent, or replace, depending on exactly which effect you need.)

Beware that bulk operations putAll, equals, toArray, containsValue, and clear are not guaranteed to be performed atomically. For example, an iterator operating concurrently with a putAll operation might view only some of the added elements.

This class does not permit the use of null values because some null return values cannot be reliably distinguished from the absence of elements.

  • Constructor Details

    • ConcurrentSkipListIntObjMultimap

      public ConcurrentSkipListIntObjMultimap(int noKey)
      Constructs a new, empty map, sorted according to the natural ordering of the keys.
      Parameters:
      noKey - The value to use as a sentinel for signaling the absence of a key.
  • Method Details

    • containsKey

      public boolean containsKey(int key)
      Returns true if this map contains a mapping for the specified key.
      Parameters:
      key - key whose presence in this map is to be tested
      Returns:
      true if this map contains a mapping for the specified key
      Throws:
      ClassCastException - if the specified key cannot be compared with the keys currently in the map
      NullPointerException - if the specified key is null
    • get

      public V get(int key)
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

      More formally, if this map contains a mapping from a key k to a value v such that key compares equal to k according to the map's ordering, then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

      Throws:
      ClassCastException - if the specified key cannot be compared with the keys currently in the map
      NullPointerException - if the specified key is null
    • getOrDefault

      public V getOrDefault(int key, V defaultValue)
      Returns the value to which the specified key is mapped, or the given defaultValue if this map contains no mapping for the key.
      Parameters:
      key - the key
      defaultValue - the value to return if this map contains no mapping for the given key
      Returns:
      the mapping for the key, if present; else the defaultValue
      Throws:
      NullPointerException - if the specified key is null
      Since:
      1.8
    • put

      public void put(int key, V value)
      Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      Throws:
      ClassCastException - if the specified key cannot be compared with the keys currently in the map
      NullPointerException - if the specified key or value is null
    • remove

      public V remove(int key)
      Removes the mapping for the specified key from this map if present.
      Parameters:
      key - key for which mapping should be removed
      Returns:
      the previous value associated with the specified key, or null if there was no mapping for the key
      Throws:
      ClassCastException - if the specified key cannot be compared with the keys currently in the map
      NullPointerException - if the specified key is null
    • containsValue

      public boolean containsValue(Object value)
      Returns true if this map maps one or more keys to the specified value. This operation requires time linear in the map size. Additionally, it is possible for the map to change during execution of this method, in which case the returned result may be inaccurate.
      Parameters:
      value - value whose presence in this map is to be tested
      Returns:
      true if a mapping to value exists; false otherwise
      Throws:
      NullPointerException - if the specified value is null
    • size

      public int size()
      Get the approximate size of the collection.
    • isEmpty

      public boolean isEmpty()
      Check if the collection is empty.
    • clear

      public void clear()
      Removes all of the mappings from this map.
    • remove

      public boolean remove(int key, Object value)
      Remove the specific entry with the given key and value, if it exist.
      Throws:
      ClassCastException - if the specified key cannot be compared with the keys currently in the map
      NullPointerException - if the specified key is null
    • replace

      public boolean replace(int key, V oldValue, V newValue)
      Replace the specific entry with the given key and value, with the given replacement value, if such an entry exist.
      Throws:
      ClassCastException - if the specified key cannot be compared with the keys currently in the map
      NullPointerException - if any of the arguments are null
    • firstKey

      public int firstKey()
    • lastKey

      public int lastKey()
    • lowerEntry

      public ConcurrentSkipListIntObjMultimap.IntEntry<V> lowerEntry(int key)
      Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key. The returned entry does not support the Entry.setValue method.
      Throws:
      NullPointerException - if the specified key is null
    • lowerKey

      public int lowerKey(int key)
      Throws:
      NullPointerException - if the specified key is null
    • floorEntry

      public ConcurrentSkipListIntObjMultimap.IntEntry<V> floorEntry(int key)
      Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key. The returned entry does not support the Entry.setValue method.
      Parameters:
      key - the key
      Throws:
      NullPointerException - if the specified key is null
    • floorKey

      public int floorKey(int key)
      Parameters:
      key - the key
      Throws:
      NullPointerException - if the specified key is null
    • ceilingEntry

      public ConcurrentSkipListIntObjMultimap.IntEntry<V> ceilingEntry(int key)
      Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such entry. The returned entry does not support the Entry.setValue method.
      Throws:
      NullPointerException - if the specified key is null
    • ceilingKey

      public int ceilingKey(int key)
      Throws:
      NullPointerException - if the specified key is null
    • higherEntry

      public ConcurrentSkipListIntObjMultimap.IntEntry<V> higherEntry(int key)
      Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key. The returned entry does not support the Entry.setValue method.
      Parameters:
      key - the key
      Throws:
      NullPointerException - if the specified key is null
    • higherKey

      public int higherKey(int key)
      Parameters:
      key - the key
      Throws:
      NullPointerException - if the specified key is null
    • firstEntry

      Returns a key-value mapping associated with the least key in this map, or null if the map is empty. The returned entry does not support the Entry.setValue method.
    • lastEntry

      Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty. The returned entry does not support the Entry.setValue method.
    • pollFirstEntry

      public ConcurrentSkipListIntObjMultimap.IntEntry<V> pollFirstEntry()
      Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty. The returned entry does not support the Entry.setValue method.
    • pollLastEntry

      Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty. The returned entry does not support the Entry.setValue method.
    • pollCeilingEntry

      public ConcurrentSkipListIntObjMultimap.IntEntry<V> pollCeilingEntry(int key)
    • iterator

      Specified by:
      iterator in interface Iterable<V>
    • forEach

      public void forEach(BiConsumer<Integer, ? super V> action)
    • replaceAll

      public void replaceAll(BiFunction<Integer, ? super V, ? extends V> function)