Class CopyOnWriteSortedMap<K,V extends @Nullable Object>
- Type Parameters:
K- The type of keys.V- The type of values.
- All Implemented Interfaces:
Map<K,,V> NavigableMap<K,,V> SortedMap<K,V>
PersistentMap backend, snapshots and modifying operations are both cheap (O(1) for the former,
usually O(log n) for the latter).
There are two usage patterns for this map. First, you can keep one instance of of the map
which you modify, and eventually call getSnapshot() to take immutable snapshots. Second,
you can use an instance of the map and create copies of it with the copyOf(CopyOnWriteSortedMap) method (these copies are O(1)). Then you can modify both the old
and the new instance, but modifications to one of it won't be reflected by the other.
All collection views returned my methods of this map are live views and change if this map is
modified. However, they currently do not support any modifying operations. All iterators produced
by the collection views iterate over an immutable snapshot of the map taken at iterator creation
time and thus do not reflect intermediate changes to the map. The iterators also don't support
the Iterator.remove() method. Thus it is safe to iterate over the map while changing it.
This implementation is thread-safe and lock free, but does not guarantee freedom of starvation. Bulk operations are not atomic.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.common.collect.ForwardingNavigableMap
ForwardingNavigableMap.StandardDescendingMap, ForwardingNavigableMap.StandardNavigableKeySetNested classes/interfaces inherited from class com.google.common.collect.ForwardingSortedMap
ForwardingSortedMap.StandardKeySetNested classes/interfaces inherited from class com.google.common.collect.ForwardingMap
ForwardingMap.StandardEntrySet, ForwardingMap.StandardValues -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()SeeMap.clear().static <K extends Comparable<? super K>,V>
CopyOnWriteSortedMap<K,V> copyOf(CopyOnWriteSortedMap<K, V> pMap) Create a new map instance containing all entries of the given map.static <K extends Comparable<? super K>,V>
CopyOnWriteSortedMap<K,V> copyOf(PersistentSortedMap<K, V> pMap) Create a new map instance with an initial content of the given map.protected NavigableMap<K,V> delegate()entrySet()Return a immutable snapshot of the current state of the map.keySet()This method is not starvation free, and thus not strictly guaranteed to terminate in presence of concurrent modifying operations.This method is not starvation free, and thus not strictly guaranteed to terminate in presence of concurrent modifying operations.@Nullable VThis method is not starvation free, and thus not strictly guaranteed to terminate in presence of concurrent modifying operations.voidThis method is not atomic! It inserts all keys one after the other, and in between each operation arbitrary operations from other threads might get executed.@Nullable VThis method is not starvation free, and thus not strictly guaranteed to terminate in presence of concurrent modifying operations.values()Methods inherited from class com.google.common.collect.ForwardingNavigableMap
ceilingEntry, ceilingKey, descendingKeySet, descendingMap, firstEntry, floorEntry, floorKey, headMap, higherEntry, higherKey, lastEntry, lowerEntry, lowerKey, navigableKeySet, standardCeilingEntry, standardCeilingKey, standardDescendingKeySet, standardFirstEntry, standardFirstKey, standardFloorEntry, standardFloorKey, standardHeadMap, standardHigherEntry, standardHigherKey, standardLastEntry, standardLastKey, standardLowerEntry, standardLowerKey, standardPollFirstEntry, standardPollLastEntry, standardSubMap, standardTailMap, subMap, tailMapMethods inherited from class com.google.common.collect.ForwardingSortedMap
comparator, firstKey, lastKey, standardContainsKeyMethods inherited from class com.google.common.collect.ForwardingMap
containsKey, containsValue, equals, get, hashCode, isEmpty, size, standardClear, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToStringMethods inherited from class com.google.common.collect.ForwardingObject
toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, sizeMethods inherited from interface java.util.SortedMap
comparator, firstKey, lastKey
-
Method Details
-
copyOf
public static <K extends Comparable<? super K>,V> CopyOnWriteSortedMap<K,V> copyOf(PersistentSortedMap<K, V> pMap) Create a new map instance with an initial content of the given map. To create an empty instance, get an empty instance of your favoritePersistentSortedMapimplementation and pass it to this method. -
copyOf
public static <K extends Comparable<? super K>,V> CopyOnWriteSortedMap<K,V> copyOf(CopyOnWriteSortedMap<K, V> pMap) Create a new map instance containing all entries of the given map. The snapshot of the given map is created atomically. Changes to the new map don't reflect in the given map and vice-versa. -
delegate
- Specified by:
delegatein classForwardingNavigableMap<K,V extends @Nullable Object>
-
getSnapshot
Return a immutable snapshot of the current state of the map. -
put
This method is not starvation free, and thus not strictly guaranteed to terminate in presence of concurrent modifying operations. -
remove
This method is not starvation free, and thus not strictly guaranteed to terminate in presence of concurrent modifying operations. -
pollFirstEntry
This method is not starvation free, and thus not strictly guaranteed to terminate in presence of concurrent modifying operations.- Specified by:
pollFirstEntryin interfaceNavigableMap<K,V extends @Nullable Object> - Overrides:
pollFirstEntryin classForwardingNavigableMap<K,V extends @Nullable Object> - See Also:
-
pollLastEntry
This method is not starvation free, and thus not strictly guaranteed to terminate in presence of concurrent modifying operations.- Specified by:
pollLastEntryin interfaceNavigableMap<K,V extends @Nullable Object> - Overrides:
pollLastEntryin classForwardingNavigableMap<K,V extends @Nullable Object> - See Also:
-
putAll
This method is not atomic! It inserts all keys one after the other, and in between each operation arbitrary operations from other threads might get executed.This method is not starvation free, and thus not strictly guaranteed to terminate in presence of concurrent modifying operations.
-
clear
public void clear()SeeMap.clear(). -
entrySet
-
keySet
-
values
-
headMap
-
tailMap
-
subMap
-