org.geotools.util
Class DisjointSet

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended byorg.geotools.util.DisjointSet
All Implemented Interfaces:
java.util.Collection, java.io.Serializable, java.util.Set

public class DisjointSet
extends java.util.AbstractSet
implements java.io.Serializable

A set which is disjoint from others s. Two sets are disjoint (or mutually exclusive

 DisjointSet set0 = new DisjointSet(true); // Used as the trash set.
 DisjointSet set1 = new DisjointSet(set0);
 DisjointSet set2 = new DisjointSet(set0);
 
Disjoint sets are thread-safe.

Since:
2.0
Version:
$Id: DisjointSet.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Constructor Summary
DisjointSet()
          Construct a initially empty set.
DisjointSet(boolean hasTrash)
          Construct a initially empty set with an optional trash set.
DisjointSet(DisjointSet disjointSet)
          Construct a new set mutually exclusive with the specified set.
 
Method Summary
 boolean add(java.lang.Object element)
          Ensures that this collection contains the specified element.
 boolean addAll(java.util.Collection c)
          Adds all of the elements in the specified collection to this set.
 void clear()
          Removes all of the elements from this set.
 boolean contains(java.lang.Object element)
          Returns if this set contains the specified element.
 boolean containsAll(java.util.Collection c)
          Returns if this set contains all of the elements in the specified collection.
 boolean equals(java.lang.Object set)
          Compare this set with the specified object for equality.
 java.util.Set getTrash()
          Returns the trash set, or if there is none.
 int hashCode()
          Returns an hash value for this set.
 java.util.Iterator iterator()
          Returns an iterator over the elements in this collection.
 boolean remove(java.lang.Object element)
          Removes a single instance of the specified element from this set, if it is present.
 boolean removeAll(java.util.Collection c)
          Removes from this set all of its elements that are contained in the specified collection.
 boolean retainAll(java.util.Collection c)
          Retains only the elements in this set that are contained in the specified collection.
 int size()
          Returns the number of elements in this set.
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this collection.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Returns an array containing all of the elements in this collection.
 java.lang.String toString()
          Returns a string representation of this set.
 
Methods inherited from class java.util.AbstractCollection
isEmpty
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
isEmpty
 

Constructor Detail

DisjointSet

public DisjointSet()
Construct a initially empty set. There is initially no other set mutually exclusive with this one. Mutually exclusive sets must be created using the constructor with this newly created set as argument.

s constructed using this constructor has no trash. All remove operations on this set really remove all references to the removed element, like a usual Set. This is opposed to moving the element to a "trash" set, which is allowed by the constructor.


DisjointSet

public DisjointSet(boolean hasTrash)
Construct a initially empty set with an optional trash set. There is initially no other set mutually exclusive with this one. Mutually exclusive sets must be created using the constructor with this newly created set as argument.

Parameters:
hasTrash - If , all remove operations will add removed elements to a trash set (thus, really just moving the element to the trash). If , there is no trash and this constructor behave like the no-argument constructor.
See Also:
getTrash()

DisjointSet

public DisjointSet(DisjointSet disjointSet)
Construct a new set mutually exclusive with the specified set. All sets mutually exclusive with will also be mutually exclusive with the newly created set. If has a trash set, the newly created set will use the same trash (i.e. all operations will really move the element to the trash set). Otherwise, the new have no trash.

Parameters:
disjointSet - The set to be disjoint from.
Method Detail

getTrash

public java.util.Set getTrash()
Returns the trash set, or if there is none. The trash set receive all elements removed from this set.


size

public int size()
Returns the number of elements in this set. The size of this set may change as a result of adding elements to a mutually exclusive set.

Specified by:
size in interface java.util.Set

contains

public boolean contains(java.lang.Object element)
Returns if this set contains the specified element.

Specified by:
contains in interface java.util.Set
Parameters:
element - Object to be checked for containment in this set.
Returns:
if this set contains the specified element.

add

public boolean add(java.lang.Object element)
Ensures that this collection contains the specified element. Adding an element to this set will remove it from any mutually exclusive set.

Specified by:
add in interface java.util.Set
Parameters:
element - Element whose presence in this set is to be ensured.
Returns:
if the set changed as a result of the call.

remove

public boolean remove(java.lang.Object element)
Removes a single instance of the specified element from this set, if it is present. If this has a trash set, the removed element will be added to the trash set.

Specified by:
remove in interface java.util.Set
Parameters:
element - Element to be removed from this set.
Returns:
if the set changed as a result of the call.

containsAll

public boolean containsAll(java.util.Collection c)
Returns if this set contains all of the elements in the specified collection.

Specified by:
containsAll in interface java.util.Set
Parameters:
c - collection to be checked for containment in this collection.
Returns:
if this set contains all of the elements in the specified collection.

addAll

public boolean addAll(java.util.Collection c)
Adds all of the elements in the specified collection to this set. All of the elements will be removed from mutually exclusive sets.

Specified by:
addAll in interface java.util.Set
Parameters:
c - collection whose elements are to be added to this set.
Returns:
if this set changed as a result of the call.

removeAll

public boolean removeAll(java.util.Collection c)
Removes from this set all of its elements that are contained in the specified collection. If this has a trash set, all removed elements will be added to the trash set.

Specified by:
removeAll in interface java.util.Set
Parameters:
c - elements to be removed from this set.
Returns:
if this set changed as a result of the call.

retainAll

public boolean retainAll(java.util.Collection c)
Retains only the elements in this set that are contained in the specified collection. If this has a trash set, all removed elements will be added to the trash set.

Specified by:
retainAll in interface java.util.Set
Parameters:
c - elements to be retained in this collection.
Returns:
if this collection changed as a result of the call.

clear

public void clear()
Removes all of the elements from this set. If this has a trash set, all removed elements will be added to the trash set.

Specified by:
clear in interface java.util.Set

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements in this collection.

Specified by:
iterator in interface java.util.Set

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this collection.

Specified by:
toArray in interface java.util.Set
Returns:
an array containing all of the elements in this set.

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Returns an array containing all of the elements in this collection.

Specified by:
toArray in interface java.util.Set
Parameters:
a - The array into which the elements of the set 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 set.

toString

public java.lang.String toString()
Returns a string representation of this set.


hashCode

public int hashCode()
Returns an hash value for this set.

Specified by:
hashCode in interface java.util.Set

equals

public boolean equals(java.lang.Object set)
Compare this set with the specified object for equality.

Specified by:
equals in interface java.util.Set


Copyright © GeoTools. All Rights Reserved.