Package org.infinispan.distribution.util
Class ReadOnlySegmentAwareCollection<E>
java.lang.Object
org.infinispan.commons.util.AbstractDelegatingCollection<E>
org.infinispan.distribution.util.ReadOnlySegmentAwareCollection<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>
- Direct Known Subclasses:
ReadOnlySegmentAwareEntryCollection
Set implementation that shows a read only view of the provided set by only allowing
entries that map to a given segment using the provided consistent hash.
This set is useful when you don't want to copy an entire set but only need to see values from the given segments.
Note many operations are not constant time when using this set. Please check the method you are using to see if it will perform differently than normally expected.
- Since:
- 7.2
- Author:
- wburns
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final IntSetprotected final Collection<E>protected final LocalizedCacheTopology -
Constructor Summary
ConstructorsConstructorDescriptionReadOnlySegmentAwareCollection(Collection<E> set, LocalizedCacheTopology topology, IntSet allowedSegments) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleancontainsAll(Collection<?> c) protected Collection<E>delegate()booleanisEmpty()Checks if the provided set is empty.iterator()intsize()Returns the size of the read only set.protected booleanvalueAllowed(Object obj) Methods inherited from class org.infinispan.commons.util.AbstractDelegatingCollection
add, addAll, clear, forEach, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArrayMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, toArray
-
Field Details
-
set
-
topology
-
allowedSegments
-
-
Constructor Details
-
ReadOnlySegmentAwareCollection
public ReadOnlySegmentAwareCollection(Collection<E> set, LocalizedCacheTopology topology, IntSet allowedSegments)
-
-
Method Details
-
delegate
- Specified by:
delegatein classAbstractDelegatingCollection<E>
-
valueAllowed
-
contains
- Specified by:
containsin interfaceCollection<E>- Overrides:
containsin classAbstractDelegatingCollection<E>
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>- Overrides:
containsAllin classAbstractDelegatingCollection<E>
-
isEmpty
public boolean isEmpty()Checks if the provided set is empty. This is done by iterating over all of the values 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:
isEmptyin interfaceCollection<E>- Overrides:
isEmptyin classAbstractDelegatingCollection<E>
-
size
public int size()Returns the size of the read only set. This is done by iterating over all of the values counting all that are in the segments.If you are using this method to verify if the set is empty, you should instead use the
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:
sizein interfaceCollection<E>- Overrides:
sizein classAbstractDelegatingCollection<E>
-
iterator
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Overrides:
iteratorin classAbstractDelegatingCollection<E>
-