Class ConcurrentSkipListIntObjMultimap<V>
- java.lang.Object
-
- io.netty.util.concurrent.ConcurrentSkipListIntObjMultimap<V>
-
- Type Parameters:
V- the type of mapped values
- All Implemented Interfaces:
java.lang.Iterable<ConcurrentSkipListIntObjMultimap.IntEntry<V>>
public class ConcurrentSkipListIntObjMultimap<V> extends java.lang.Object implements java.lang.Iterable<ConcurrentSkipListIntObjMultimap.IntEntry<V>>
A scalable concurrent multimap implementation. The map is sorted according to the natural ordering of itsintkeys.This class implements a concurrent variant of SkipLists providing expected average log(n) time cost for the
containsKey,get,putandremoveoperations 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, orcomputeIfPresent, cannot be supported. Likewise, some get-like operations cannot be supported.Iterators and spliterators are weakly consistent.
All
IntEntrypairs returned by methods in this class represent snapshots of mappings at the time they were produced. They do not support theEntry.setValuemethod. (Note however that it is possible to change mappings in the associated map usingput,putIfAbsent, orreplace, depending on exactly which effect you need.)Beware that bulk operations
putAll,equals,toArray,containsValue, andclearare not guaranteed to be performed atomically. For example, an iterator operating concurrently with aputAlloperation might view only some of the added elements.This class does not permit the use of
nullvalues because some null return values cannot be reliably distinguished from the absence of elements.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConcurrentSkipListIntObjMultimap.IntEntry<V>The multimap entry type with primitiveintkeys.
-
Constructor Summary
Constructors Constructor Description ConcurrentSkipListIntObjMultimap(int noKey)Constructs a new, empty map, sorted according to the natural ordering of the keys.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConcurrentSkipListIntObjMultimap.IntEntry<V>ceilingEntry(int key)Returns a key-value mapping associated with the least key greater than or equal to the given key, ornullif there is no such entry.intceilingKey(int key)voidclear()Removes all of the mappings from this map.booleancontainsKey(int key)Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(java.lang.Object value)Returnstrueif this map maps one or more keys to the specified value.ConcurrentSkipListIntObjMultimap.IntEntry<V>firstEntry()Returns a key-value mapping associated with the least key in this map, ornullif the map is empty.intfirstKey()ConcurrentSkipListIntObjMultimap.IntEntry<V>floorEntry(int key)Returns a key-value mapping associated with the greatest key less than or equal to the given key, ornullif there is no such key.intfloorKey(int key)voidforEach(java.util.function.BiConsumer<java.lang.Integer,? super V> action)Vget(int key)Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.VgetOrDefault(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.ConcurrentSkipListIntObjMultimap.IntEntry<V>higherEntry(int key)Returns a key-value mapping associated with the least key strictly greater than the given key, ornullif there is no such key.inthigherKey(int key)booleanisEmpty()Check if the collection is empty.java.util.Iterator<ConcurrentSkipListIntObjMultimap.IntEntry<V>>iterator()ConcurrentSkipListIntObjMultimap.IntEntry<V>lastEntry()Returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.intlastKey()ConcurrentSkipListIntObjMultimap.IntEntry<V>lowerEntry(int key)Returns a key-value mapping associated with the greatest key strictly less than the given key, ornullif there is no such key.intlowerKey(int key)ConcurrentSkipListIntObjMultimap.IntEntry<V>pollCeilingEntry(int key)ConcurrentSkipListIntObjMultimap.IntEntry<V>pollFirstEntry()Removes and returns a key-value mapping associated with the least key in this map, ornullif the map is empty.ConcurrentSkipListIntObjMultimap.IntEntry<V>pollLastEntry()Removes and returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.voidput(int key, V value)Associates the specified value with the specified key in this map.Vremove(int key)Removes the mapping for the specified key from this map if present.booleanremove(int key, java.lang.Object value)Remove the specific entry with the given key and value, if it exist.booleanreplace(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.voidreplaceAll(java.util.function.BiFunction<java.lang.Integer,? super V,? extends V> function)intsize()Get the approximate size of the collection.
-
-
-
Method Detail
-
containsKey
public boolean containsKey(int key)
Returnstrueif this map contains a mapping for the specified key.- Parameters:
key- key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key- Throws:
java.lang.ClassCastException- if the specified key cannot be compared with the keys currently in the mapjava.lang.NullPointerException- if the specified key is null
-
get
public V get(int key)
Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch thatkeycompares equal tokaccording to the map's ordering, then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)- Throws:
java.lang.ClassCastException- if the specified key cannot be compared with the keys currently in the mapjava.lang.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 keydefaultValue- 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:
java.lang.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 associatedvalue- value to be associated with the specified key- Throws:
java.lang.ClassCastException- if the specified key cannot be compared with the keys currently in the mapjava.lang.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
nullif there was no mapping for the key - Throws:
java.lang.ClassCastException- if the specified key cannot be compared with the keys currently in the mapjava.lang.NullPointerException- if the specified key is null
-
containsValue
public boolean containsValue(java.lang.Object value)
Returnstrueif 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:
trueif a mapping tovalueexists;falseotherwise- Throws:
java.lang.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, java.lang.Object value)Remove the specific entry with the given key and value, if it exist.- Throws:
java.lang.ClassCastException- if the specified key cannot be compared with the keys currently in the mapjava.lang.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:
java.lang.ClassCastException- if the specified key cannot be compared with the keys currently in the mapjava.lang.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, ornullif there is no such key. The returned entry does not support theEntry.setValuemethod.- Throws:
java.lang.NullPointerException- if the specified key is null
-
lowerKey
public int lowerKey(int key)
- Throws:
java.lang.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, ornullif there is no such key. The returned entry does not support theEntry.setValuemethod.- Parameters:
key- the key- Throws:
java.lang.NullPointerException- if the specified key is null
-
floorKey
public int floorKey(int key)
- Parameters:
key- the key- Throws:
java.lang.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, ornullif there is no such entry. The returned entry does not support theEntry.setValuemethod.- Throws:
java.lang.NullPointerException- if the specified key is null
-
ceilingKey
public int ceilingKey(int key)
- Throws:
java.lang.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, ornullif there is no such key. The returned entry does not support theEntry.setValuemethod.- Parameters:
key- the key- Throws:
java.lang.NullPointerException- if the specified key is null
-
higherKey
public int higherKey(int key)
- Parameters:
key- the key- Throws:
java.lang.NullPointerException- if the specified key is null
-
firstEntry
public ConcurrentSkipListIntObjMultimap.IntEntry<V> firstEntry()
Returns a key-value mapping associated with the least key in this map, ornullif the map is empty. The returned entry does not support theEntry.setValuemethod.
-
lastEntry
public ConcurrentSkipListIntObjMultimap.IntEntry<V> lastEntry()
Returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty. The returned entry does not support theEntry.setValuemethod.
-
pollFirstEntry
public ConcurrentSkipListIntObjMultimap.IntEntry<V> pollFirstEntry()
Removes and returns a key-value mapping associated with the least key in this map, ornullif the map is empty. The returned entry does not support theEntry.setValuemethod.
-
pollLastEntry
public ConcurrentSkipListIntObjMultimap.IntEntry<V> pollLastEntry()
Removes and returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty. The returned entry does not support theEntry.setValuemethod.
-
pollCeilingEntry
public ConcurrentSkipListIntObjMultimap.IntEntry<V> pollCeilingEntry(int key)
-
iterator
public java.util.Iterator<ConcurrentSkipListIntObjMultimap.IntEntry<V>> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<V>
-
forEach
public void forEach(java.util.function.BiConsumer<java.lang.Integer,? super V> action)
-
-