Class ConcurrentSkipListIntObjMultimap<V>
- Type Parameters:
V- the type of mapped values
- All Implemented Interfaces:
Iterable<ConcurrentSkipListIntObjMultimap.IntEntry<V>>
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe multimap entry type with primitiveintkeys. -
Constructor Summary
ConstructorsConstructorDescriptionConcurrentSkipListIntObjMultimap(int noKey) Constructs a new, empty map, sorted according to the natural ordering of the keys. -
Method Summary
Modifier and TypeMethodDescriptionceilingEntry(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(Object value) Returnstrueif this map maps one or more keys to the specified value.Returns a key-value mapping associated with the least key in this map, ornullif the map is empty.intfirstKey()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(BiConsumer<Integer, ? super V> action) get(int key) Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.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.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.iterator()Returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.intlastKey()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) pollCeilingEntry(int key) Removes and returns a key-value mapping associated with the least key in this map, ornullif the map is empty.Removes and returns a key-value mapping associated with the greatest key in this map, ornullif the map is empty.voidAssociates the specified value with the specified key in this map.remove(int key) Removes the mapping for the specified key from this map if present.booleanRemove the specific entry with the given key and value, if it exist.booleanReplace the specific entry with the given key and value, with the given replacement value, if such an entry exist.voidreplaceAll(BiFunction<Integer, ? super V, ? extends V> function) intsize()Get the approximate size of the collection.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
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) 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:
ClassCastException- if the specified key cannot be compared with the keys currently in the mapNullPointerException- if the specified key is null
-
get
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:
ClassCastException- if the specified key cannot be compared with the keys currently in the mapNullPointerException- if the specified key is null
-
getOrDefault
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:
NullPointerException- if the specified key is null- Since:
- 1.8
-
put
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:
ClassCastException- if the specified key cannot be compared with the keys currently in the mapNullPointerException- if the specified key or value is null
-
remove
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:
ClassCastException- if the specified key cannot be compared with the keys currently in the mapNullPointerException- if the specified key is null
-
containsValue
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:
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
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 mapNullPointerException- if the specified key is null
-
replace
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 mapNullPointerException- if any of the arguments are null
-
firstKey
public int firstKey() -
lastKey
public int lastKey() -
lowerEntry
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:
NullPointerException- if the specified key is null
-
lowerKey
public int lowerKey(int key) - Throws:
NullPointerException- if the specified key is null
-
floorEntry
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:
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
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:
NullPointerException- if the specified key is null
-
ceilingKey
public int ceilingKey(int key) - Throws:
NullPointerException- if the specified key is null
-
higherEntry
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:
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, ornullif the map is empty. The returned entry does not support theEntry.setValuemethod. -
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
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
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
-
iterator
-
forEach
-
replaceAll
-