Class ReadOnlySegmentAwareMap<K,V>
- java.lang.Object
-
- org.infinispan.commons.util.AbstractDelegatingMap<K,V>
-
- org.infinispan.distribution.util.ReadOnlySegmentAwareMap<K,V>
-
- All Implemented Interfaces:
java.util.Map<K,V>
public class ReadOnlySegmentAwareMap<K,V> extends AbstractDelegatingMap<K,V>
Map implementation that shows a read only view of the provided entry by only allowing entries whose key maps to a given segment using the provided consistent hash.Any operation that would modify this map will throw an
UnsupportedOperationException
This map is useful when you don't want to copy an entire map but only need to see entries from the given segments.
Note many operations are not constant time when using this map. The
values()
method is not supported as well. Please check\ the method you are using to see if it will perform differently than normally expected.- Since:
- 7.2
- Author:
- wburns
-
-
Field Summary
Fields Modifier and Type Field Description protected IntSet
allowedSegments
protected ConsistentHash
ch
protected java.util.Map<K,V>
map
protected java.util.Set<java.util.Map.Entry<K,V>>
segmentAwareEntrySet
protected java.util.Set<K>
segmentAwareKeySet
-
Constructor Summary
Constructors Constructor Description ReadOnlySegmentAwareMap(java.util.Map<K,V> map, ConsistentHash ch, IntSet allowedSegments)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(java.lang.Object key)
boolean
containsValue(java.lang.Object value)
protected java.util.Map<K,V>
delegate()
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
V
get(java.lang.Object key)
boolean
isEmpty()
Checks if the provided map is empty.protected boolean
keyAllowed(java.lang.Object key)
java.util.Set<K>
keySet()
int
size()
Returns the size of the read only map.java.lang.String
toString()
java.util.Collection<V>
values()
NOTE: this method is not supported.-
Methods inherited from class org.infinispan.commons.util.AbstractDelegatingMap
clear, compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
ch
protected final ConsistentHash ch
-
allowedSegments
protected final IntSet allowedSegments
-
segmentAwareKeySet
protected java.util.Set<K> segmentAwareKeySet
-
-
Constructor Detail
-
ReadOnlySegmentAwareMap
public ReadOnlySegmentAwareMap(java.util.Map<K,V> map, ConsistentHash ch, IntSet allowedSegments)
-
-
Method Detail
-
delegate
protected java.util.Map<K,V> delegate()
- Specified by:
delegate
in classAbstractDelegatingMap<K,V>
-
keyAllowed
protected boolean keyAllowed(java.lang.Object key)
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKey
in interfacejava.util.Map<K,V>
- Overrides:
containsKey
in classAbstractDelegatingMap<K,V>
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValue
in interfacejava.util.Map<K,V>
- Overrides:
containsValue
in classAbstractDelegatingMap<K,V>
-
get
public V get(java.lang.Object key)
-
isEmpty
public boolean isEmpty()
Checks if the provided map is empty. This is done by iterating over all of the keys until it can find a key that maps to a given segment.This method should always be preferred over checking the size to see if it is empty.
This time complexity for this method between O(1) to O(N).
-
keySet
public java.util.Set<K> keySet()
-
size
public int size()
Returns the size of the read only map. This is done by iterating over all of the keys counting all that are in the segments.If you are using this method to verify if the map is empty, you should instead use the
ReadOnlySegmentAwareEntryMap#isEmpty()
as it will perform better if the size is only used for this purpose.This time complexity for this method is always O(N).
-
values
public java.util.Collection<V> values()
NOTE: this method is not supported. Due to the nature of this map, we don't want to copy the underlying value collection. Thus almost any operation will require O(N) and therefore this method is not provided.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-