CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

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:
Serializable, Cloneable, Iterable, Collection, Set

public class SubSet
extends AbstractSet
implements Cloneable, 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.
 
Constructor Summary
SubSet(Set set)
          Construct this set based on an existing set.
 
Method Summary
 boolean add(Object o)
          Ensures that this Collection contains the specified element.
 boolean addAll(Collection col)
          Adds all of the elements in the specified collection to this collection.
 void clear()
          Removes all of the elements from this Collection.
 Object clone()
          Clone the subset.
 boolean contains(Object o)
          Returns true if this Collection contains the specified element.
 boolean containsAll(Collection col)
          Returns true if this collection contains all of the elements in the specified collection.
protected  Set ensureRemoved()
          Get a mutable set of items that are removed in the subset.
protected  Set ensureRetained()
          Get a mutable set of items that are retained in the subset.
 Set getOriginal()
          Determine what items were in the original set.
 Set getRemoved()
          Determine what items were removed from the subset.
 Set getRetained()
          Determine what items were added to the subset.
 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.
 Iterator iterator()
          Returns an Iterator over the elements contained in this Collection.
 boolean remove(Object o)
          Removes a single instance of the specified element from this Collection, if it is present (optional operation).
 boolean removeAll(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").
 void resolve()
          Apply the changes to the underlying set ("commit").
 boolean retainAll(Collection col)
          Retains only the elements in this collection that are contained in the specified collection (optional operation).
 int size()
          Returns the number of elements in this Collection.
 Object[] toArray()
          Returns an array containing all of the elements in this Set.
 Object[] toArray(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(Set set)
Construct this set based on an existing set.

Parameters:
set - the set to base this subset on
Method Detail

getOriginal

public 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 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 Set getRemoved()
Determine what items were removed from the subset.

Returns:
an immutable set of removed items

ensureRetained

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

Returns:
a mutable set of retained items

ensureRemoved

protected 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").


iterator

public Iterator iterator()
Returns an Iterator over the elements contained in this Collection.

Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface Set
Specified by:
iterator in class 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 Collection
Specified by:
isEmpty in interface Set
Overrides:
isEmpty in class 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 Collection
Specified by:
size in interface Set
Specified by:
size in class AbstractCollection
Returns:
the number of elements in this Collection

contains

public boolean contains(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 Collection
Specified by:
contains in interface Set
Overrides:
contains in class AbstractCollection
Parameters:
o - the object to search for in the set
Returns:
true if this set contains the specified object

containsAll

public boolean containsAll(Collection col)
Returns true if this collection contains all of the elements in the specified collection.

Specified by:
containsAll in interface Collection
Specified by:
containsAll in interface Set
Overrides:
containsAll in class 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(Object o)
Ensures that this Collection contains the specified element.

Specified by:
add in interface Collection
Specified by:
add in interface Set
Overrides:
add in class 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(Collection col)
Adds all of the elements in the specified collection to this collection.

Specified by:
addAll in interface Collection
Specified by:
addAll in interface Set
Overrides:
addAll in class 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(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 Collection
Specified by:
remove in interface Set
Overrides:
remove in class 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(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 Collection
Specified by:
removeAll in interface Set
Overrides:
removeAll in class 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(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 Collection
Specified by:
retainAll in interface Set
Overrides:
retainAll in class 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 Collection
Specified by:
clear in interface Set
Overrides:
clear in class AbstractCollection

toArray

public 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 Collection
Specified by:
toArray in interface Set
Overrides:
toArray in class AbstractCollection
Returns:
an Object array containing all of the elements in this Set

toArray

public Object[] toArray(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 Collection
Specified by:
toArray in interface Set
Overrides:
toArray in class 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:
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 Object clone()
Clone the subset.

Returns:
a clone of this subset

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation