Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


com.tangosol.util
Class SubSet

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractSet
          extended by com.tangosol.util.SubSet

All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.Set

public class SubSet
extends java.util.AbstractSet
implements java.lang.Cloneable, java.io.Serializable

Implements a set which is based on another set, which is assumed to be immutable. Unlike DeltaSet, the SubSet is assumed to be a subset of the underlying set, and optimizes for both remove and retain operations.

Version:
1.00, 2003-01-29
Author:
Cameron Purdy

Nested Class Summary
protected  class SubSet.SubSetIterator
          Iterator for the contents of a subset in the "removed" mode.

 

Constructor Summary
SubSet(java.util.Set set)
          Construct this set based on an existing set.

 

Method Summary
 boolean add(java.lang.Object o)
          Ensures that this Collection contains the specified element.
 boolean addAll(java.util.Collection col)
          Adds all of the elements in the specified collection to this collection.
 void clear()
          Removes all of the elements from this Collection.
 java.lang.Object clone()
          Clone the subset.
 boolean contains(java.lang.Object o)
          Returns true if this Collection contains the specified element.
 boolean containsAll(java.util.Collection col)
          Returns true if this collection contains all of the elements in the specified collection.
protected  java.util.Set ensureRemoved()
          Get a mutable set of items that are removed in the subset.
protected  java.util.Set ensureRetained()
          Get a mutable set of items that are retained in the subset.
 java.util.Set getOriginal()
          Determine what items were in the original set.
 java.util.Set getRemoved()
          Determine what items were removed from the subset.
 java.util.Set getRetained()
          Determine what items were added to the subset.
protected  java.util.Set instantiateModificationSet(int cSize)
          Instantiate a new modification set containing either removed or retained items.
 boolean isEmpty()
          Determine if the SubSet is empty.
 boolean isModified()
          Determine if the set has been modified.
 boolean isTrackingRemoved()
          Determine if the SubSet is tracking removed items versus retained items.
 boolean isTrackingRetained()
          Determine if the SubSet is tracking retained items versus removed items.
 java.util.Iterator iterator()
          Returns an Iterator over the elements contained in this Collection.
 boolean remove(java.lang.Object o)
          Removes a single instance of the specified element from this Collection, if it is present (optional operation).
 boolean removeAll(java.util.Collection col)
          Removes all this collection's elements that are also contained in the specified collection (optional operation).
 void reset()
          Discard the changes to the set ("rollback").
protected  void resetState(java.util.Set setOrig, java.util.Set setMod, boolean fRetained)
          Reset the state of the subset according to the specified parameters.
 void resolve()
          Apply the changes to the underlying set ("commit").
 boolean retainAll(java.util.Collection col)
          Retains only the elements in this collection that are contained in the specified collection (optional operation).
protected  void retainAllInternal(java.util.Collection colOuter, java.util.Collection colMatch, java.util.Set setExclude)
          Instantiate a new retained set with all elements in the specified collection that also exist in the provided colMatch collection and are not excluded.
 int size()
          Returns the number of elements in this Collection.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this Set.
 java.lang.Object[] toArray(java.lang.Object[] ao)
          Returns an array with a runtime type is that of the specified array and that contains all of the elements in this collection.

 

Methods inherited from class java.util.AbstractSet
equals, hashCode

 

Methods inherited from class java.util.AbstractCollection
toString

 

Constructor Detail

SubSet

public SubSet(java.util.Set set)
Construct this set based on an existing set.
Parameters:
set - the set to base this subset on

Method Detail

getOriginal

public java.util.Set 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

public java.util.Set getRetained()
Determine what items were added to the subset. Do not modify the returned set.
Returns:
a set of retained items

isTrackingRemoved

public boolean isTrackingRemoved()
Determine if the SubSet is tracking removed items versus retained items.
Returns:
true if the SubSet is tracking just the removed items, false if the SubSet is tracking just the retained items

getRemoved

public java.util.Set getRemoved()
Determine what items were removed from the subset.
Returns:
an immutable set of removed items

instantiateModificationSet

protected java.util.Set instantiateModificationSet(int cSize)
Instantiate a new modification set containing either removed or retained items.
Parameters:
cSize - an initial size of the modification set

ensureRetained

protected java.util.Set ensureRetained()
Get a mutable set of items that are retained in the subset.
Returns:
a mutable set of retained items

ensureRemoved

protected java.util.Set 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

protected void resetState(java.util.Set setOrig,
                          java.util.Set setMod,
                          boolean fRetained)
Reset the state of the subset according to the specified parameters.
Parameters:
setOrig - the new original set
setMod - the set of removed or retained entries, depending on the fRetained flag
fRetained - if true setMod contains the retained entries; otherwise the removed entries

iterator

public java.util.Iterator iterator()
Returns an Iterator over the elements contained in this Collection.
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in interface java.util.Set
Specified by:
iterator in class java.util.AbstractCollection
Returns:
an Iterator over the elements contained in this Collection

isEmpty

public boolean isEmpty()
Determine if the SubSet is empty.
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.Set
Overrides:
isEmpty in class java.util.AbstractCollection
Returns:
true iff the SubSet is empty

size

public int size()
Returns the number of elements in this Collection.
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.Set
Specified by:
size in class java.util.AbstractCollection
Returns:
the number of elements in this Collection

contains

public boolean contains(java.lang.Object o)
Returns true if this Collection contains the specified element. More formally, returns true if and only if this Collection contains at least one element e such that (o==null ? e==null : o.equals(e)).
Specified by:
contains in interface java.util.Collection
Specified by:
contains in interface java.util.Set
Overrides:
contains in class java.util.AbstractCollection
Parameters:
o - the object to search for in the set
Returns:
true if this set contains the specified object

containsAll

public boolean containsAll(java.util.Collection col)
Returns true if this collection contains all of the elements in the specified collection.
Specified by:
containsAll in interface java.util.Collection
Specified by:
containsAll in interface java.util.Set
Overrides:
containsAll in class java.util.AbstractCollection
Parameters:
col - collection to be checked for containment in this collection
Returns:
true if this collection contains all of the elements in the specified collection

add

public boolean add(java.lang.Object o)
Ensures that this Collection contains the specified element.
Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.Set
Overrides:
add in class java.util.AbstractCollection
Parameters:
o - element whose presence in this Collection is to be ensured
Returns:
true if the Collection changed as a result of the call

addAll

public boolean addAll(java.util.Collection col)
Adds all of the elements in the specified collection to this collection.
Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.Set
Overrides:
addAll in class java.util.AbstractCollection
Parameters:
col - collection of elements to be inserted into this collection
Returns:
true if this collection changed as a result of the call

remove

public boolean remove(java.lang.Object o)
Removes a single instance of the specified element from this Collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the Collection contains one or more such elements. Returns true if the Collection contained the specified element (or equivalently, if the Collection changed as a result of the call).
Specified by:
remove in interface java.util.Collection
Specified by:
remove in interface java.util.Set
Overrides:
remove in class java.util.AbstractCollection
Parameters:
o - element to be removed from this Collection, if present
Returns:
true if the Collection contained the specified element

removeAll

public boolean removeAll(java.util.Collection col)
Removes all this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.
Specified by:
removeAll in interface java.util.Collection
Specified by:
removeAll in interface java.util.Set
Overrides:
removeAll in class java.util.AbstractSet
Parameters:
col - elements to be removed from this collection
Returns:
true if this collection changed as a result of the call

retainAll

public boolean retainAll(java.util.Collection col)
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.
Specified by:
retainAll in interface java.util.Collection
Specified by:
retainAll in interface java.util.Set
Overrides:
retainAll in class java.util.AbstractCollection
Parameters:
col - elements to be retained in this collection.
Returns:
true if this collection changed as a result of the call

clear

public void clear()
Removes all of the elements from this Collection.
Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.Set
Overrides:
clear in class java.util.AbstractCollection

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this Set. Obeys the general contract of Collection.toArray.
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class java.util.AbstractCollection
Returns:
an Object array containing all of the elements in this Set

toArray

public java.lang.Object[] toArray(java.lang.Object[] ao)
Returns an array with a runtime type is that of the specified array and that contains all of the elements in this collection. If the collection fits in the specified array, it is returned there = in. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.

If the collection fits in the specified array with room to spare (i.e., the array has more elements than the collection), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the collection only if the caller knows that the collection does not contain any null elements.)

Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.Set
Overrides:
toArray in class java.util.AbstractCollection
Parameters:
ao - the array into which the elements of the collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose
Returns:
an array containing the elements of the collection
Throws:
java.lang.ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this collection

clone

public java.lang.Object clone()
Clone the subset.
Returns:
a clone of this subset

retainAllInternal

protected void retainAllInternal(java.util.Collection colOuter,
                                 java.util.Collection colMatch,
                                 java.util.Set setExclude)
Instantiate a new retained set with all elements in the specified collection that also exist in the provided colMatch collection and are not excluded.
Parameters:
colOuter - collection to iterate
colMatch - each element in colOuter should be present in this collection such that (colOuter ∩ colMatch)
setExclude - optional set of excluded elements

Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.