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:
java.lang.Iterable<E>
,java.util.Collection<E>
- Direct Known Subclasses:
ReadOnlySegmentAwareEntryCollection
public class ReadOnlySegmentAwareCollection<E> extends AbstractDelegatingCollection<E>
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
Fields Modifier and Type Field Description protected IntSet
allowedSegments
protected ConsistentHash
ch
protected java.util.Collection<E>
set
-
Constructor Summary
Constructors Constructor Description ReadOnlySegmentAwareCollection(java.util.Collection<E> set, ConsistentHash ch, IntSet allowedSegments)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
protected java.util.Collection<E>
delegate()
boolean
isEmpty()
Checks if the provided set is empty.java.util.Iterator<E>
iterator()
int
size()
Returns the size of the read only set.protected boolean
valueAllowed(java.lang.Object obj)
-
Methods inherited from class org.infinispan.commons.util.AbstractDelegatingCollection
add, addAll, clear, forEach, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
-
-
-
-
Field Detail
-
set
protected final java.util.Collection<E> set
-
ch
protected final ConsistentHash ch
-
allowedSegments
protected final IntSet allowedSegments
-
-
Constructor Detail
-
ReadOnlySegmentAwareCollection
public ReadOnlySegmentAwareCollection(java.util.Collection<E> set, ConsistentHash ch, IntSet allowedSegments)
-
-
Method Detail
-
delegate
protected java.util.Collection<E> delegate()
- Specified by:
delegate
in classAbstractDelegatingCollection<E>
-
valueAllowed
protected boolean valueAllowed(java.lang.Object obj)
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection<E>
- Overrides:
contains
in classAbstractDelegatingCollection<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAll
in interfacejava.util.Collection<E>
- Overrides:
containsAll
in 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:
isEmpty
in interfacejava.util.Collection<E>
- Overrides:
isEmpty
in 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:
size
in interfacejava.util.Collection<E>
- Overrides:
size
in classAbstractDelegatingCollection<E>
-
-