Class ReadOnlySegmentAwareMap<K,​V>

  • All Implemented Interfaces:
    Map<K,​V>

    public class ReadOnlySegmentAwareMap<K,​V>
    extends org.infinispan.commons.util.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 Detail

      • map

        protected final Map<K,​V> map
      • allowedSegments

        protected final org.infinispan.commons.util.IntSet allowedSegments
      • segmentAwareKeySet

        protected Set<K> segmentAwareKeySet
      • segmentAwareEntrySet

        protected Set<Map.Entry<K,​V>> segmentAwareEntrySet
    • Constructor Detail

      • ReadOnlySegmentAwareMap

        public ReadOnlySegmentAwareMap​(Map<K,​V> map,
                                       ConsistentHash ch,
                                       org.infinispan.commons.util.IntSet allowedSegments)
    • Method Detail

      • delegate

        protected Map<K,​V> delegate()
        Specified by:
        delegate in class org.infinispan.commons.util.AbstractDelegatingMap<K,​V>
      • keyAllowed

        protected boolean keyAllowed​(Object key)
      • containsKey

        public boolean containsKey​(Object key)
        Specified by:
        containsKey in interface Map<K,​V>
        Overrides:
        containsKey in class org.infinispan.commons.util.AbstractDelegatingMap<K,​V>
      • containsValue

        public boolean containsValue​(Object value)
        Specified by:
        containsValue in interface Map<K,​V>
        Overrides:
        containsValue in class org.infinispan.commons.util.AbstractDelegatingMap<K,​V>
      • get

        public V get​(Object key)
        Specified by:
        get in interface Map<K,​V>
        Overrides:
        get in class org.infinispan.commons.util.AbstractDelegatingMap<K,​V>
      • entrySet

        public Set<Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface Map<K,​V>
        Overrides:
        entrySet in class org.infinispan.commons.util.AbstractDelegatingMap<K,​V>
      • 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).

        Specified by:
        isEmpty in interface Map<K,​V>
        Overrides:
        isEmpty in class org.infinispan.commons.util.AbstractDelegatingMap<K,​V>
      • keySet

        public Set<K> keySet()
        Specified by:
        keySet in interface Map<K,​V>
        Overrides:
        keySet in class org.infinispan.commons.util.AbstractDelegatingMap<K,​V>
      • 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).

        Specified by:
        size in interface Map<K,​V>
        Overrides:
        size in class org.infinispan.commons.util.AbstractDelegatingMap<K,​V>
      • values

        public 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.
        Specified by:
        values in interface Map<K,​V>
        Overrides:
        values in class org.infinispan.commons.util.AbstractDelegatingMap<K,​V>