Package com.tangosol.util
Class SubSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
com.tangosol.util.SubSet<E>
- All Implemented Interfaces:
 Cloneable,Iterable<E>,Collection<E>,Set<E>
Implements a set which is based on another set, which is assumed to be
 immutable. The SubSet is assumed to be a subset of the underlying set, and
 optimizes for both remove and retain operations. If the underlying (original)
 set is sorted, the SubSet's 
iterator() will iterate items in the
 ascending order.
 This implementation is not thread-safe.
- Author:
 - cp 2003.01.29
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classIterator for the contents of a subset in the "removed" mode. - 
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Object[]An empty immutable array.protected booleanToggles between whether the modifications are removed or retained.The removed or retained items.The underlying set (assumed immutable). - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> col) voidclear()clone()Clone the subset.booleanbooleancontainsAll(Collection<?> col) Get a mutable set of items that are removed in the subset.Get a mutable set of items that are retained in the subset.Determine what items were in the original set.Determine what items were removed from the subset.Determine what items were added to the subset.instantiateModificationSet(int cSize) Instantiate a new modification set containing either removed or retained items.booleanisEmpty()booleanDetermine if the set has been modified.booleanDetermine if the SubSet is tracking retained items versus removed items.iterator()booleanbooleanremoveAll(Collection<?> col) voidreset()Discard the changes to the set ("rollback").protected voidresetState(Set setOrig, Set setMod, boolean fRetained) Reset the state of the subset according to the specified parameters.voidresolve()Apply the changes to the underlying set ("commit").booleanretainAll(Collection<?> col) protected voidretainAllInternal(Collection colOuter, Collection colMatch, Set setExclude) Instantiate a new retained set with all elements in the specified collection that also exist in the providedcolMatchcollection and are not excluded.intsize()Object[]toArray()Object[]Methods inherited from class java.util.AbstractSet
equals, hashCodeMethods inherited from class java.util.AbstractCollection
toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
spliterator 
- 
Field Details
- 
EMPTY_ARRAY
An empty immutable array. - 
m_setOrig
The underlying set (assumed immutable). - 
m_setMod
The removed or retained items. - 
m_fRetained
protected boolean m_fRetainedToggles between whether the modifications are removed or retained. 
 - 
 - 
Constructor Details
- 
SubSet
Construct this set based on an existing set.- Parameters:
 set- the set to base this subset on
 
 - 
 - 
Method Details
- 
getOriginal
Determine what items were in the original set.- Returns:
 - the set used to construct this SubSet
 
 - 
isModified
public boolean isModified()Determine if the set has been modified.- Returns:
 - true if any items have been removed
 
 - 
isTrackingRetained
public boolean isTrackingRetained()Determine if the SubSet is tracking retained items versus removed items.- Returns:
 - true if the SubSet is tracking just the retained items, false if the SubSet is tracking just the removed items
 
 - 
getRetained
Determine what items were added to the subset. Do not modify the returned set.- Returns:
 - a set of retained items
 
 - 
getRemoved
Determine what items were removed from the subset.- Returns:
 - an immutable set of removed items
 
 - 
instantiateModificationSet
Instantiate a new modification set containing either removed or retained items.- Parameters:
 cSize- an initial size of the modification set
 - 
ensureRetained
Get a mutable set of items that are retained in the subset.- Returns:
 - a mutable set of retained items
 
 - 
ensureRemoved
Get a mutable set of items that are removed in the subset.- Returns:
 - a mutable set of removed items
 
 - 
resolve
public void resolve()Apply the changes to the underlying set ("commit"). - 
reset
public void reset()Discard the changes to the set ("rollback"). - 
resetState
Reset the state of the subset according to the specified parameters.- Parameters:
 setOrig- the new original setsetMod- the set of removed or retained entries, depending on thefRetainedflagfRetained- if truesetModcontains the retained entries; otherwise the removed entries
 - 
iterator
 - 
isEmpty
public boolean isEmpty()- Specified by:
 isEmptyin interfaceCollection<E>- Specified by:
 isEmptyin interfaceSet<E>- Overrides:
 isEmptyin classAbstractCollection<E>
 - 
size
public int size()- Specified by:
 sizein interfaceCollection<E>- Specified by:
 sizein interfaceSet<E>- Specified by:
 sizein classAbstractCollection<E>
 - 
contains
- Specified by:
 containsin interfaceCollection<E>- Specified by:
 containsin interfaceSet<E>- Overrides:
 containsin classAbstractCollection<E>
 - 
containsAll
- Specified by:
 containsAllin interfaceCollection<E>- Specified by:
 containsAllin interfaceSet<E>- Overrides:
 containsAllin classAbstractCollection<E>
 - 
add
- Specified by:
 addin interfaceCollection<E>- Specified by:
 addin interfaceSet<E>- Overrides:
 addin classAbstractCollection<E>
 - 
addAll
- Specified by:
 addAllin interfaceCollection<E>- Specified by:
 addAllin interfaceSet<E>- Overrides:
 addAllin classAbstractCollection<E>
 - 
remove
- Specified by:
 removein interfaceCollection<E>- Specified by:
 removein interfaceSet<E>- Overrides:
 removein classAbstractCollection<E>
 - 
removeAll
- Specified by:
 removeAllin interfaceCollection<E>- Specified by:
 removeAllin interfaceSet<E>- Overrides:
 removeAllin classAbstractSet<E>
 - 
retainAll
- Specified by:
 retainAllin interfaceCollection<E>- Specified by:
 retainAllin interfaceSet<E>- Overrides:
 retainAllin classAbstractCollection<E>
 - 
clear
public void clear()- Specified by:
 clearin interfaceCollection<E>- Specified by:
 clearin interfaceSet<E>- Overrides:
 clearin classAbstractCollection<E>
 - 
toArray
- Specified by:
 toArrayin interfaceCollection<E>- Specified by:
 toArrayin interfaceSet<E>- Overrides:
 toArrayin classAbstractCollection<E>
 - 
toArray
- Specified by:
 toArrayin interfaceCollection<E>- Specified by:
 toArrayin interfaceSet<E>- Overrides:
 toArrayin classAbstractCollection<E>
 - 
clone
Clone the subset. - 
retainAllInternal
Instantiate a new retained set with all elements in the specified collection that also exist in the providedcolMatchcollection and are not excluded.- Parameters:
 colOuter- collection to iteratecolMatch- each element in colOuter should be present in this collection such that(colOuter ∩ colMatch)setExclude- optional set of excluded elements
 
 -