E - The type of elements in this set.public class DisjointSet<E> extends AbstractSet<E> implements Serializable
DisjointSets. Two sets are disjoint (or mutually
exclusive) if their intersection is the empty set. Adding an element to a DisjointSet remove it from any other mutually exclusive DisjointSet. Optionnaly, DisjointSets may also have a trash set receiving removed elements. The example below creates 3
mutually exclusive sets with a trash:
Disjoint sets are thread-safe.DisjointSet set0 = new DisjointSet(true); // Used as the trash set. DisjointSet set1 = new DisjointSet(set0); DisjointSet set2 = new DisjointSet(set0);
| Constructor and Description |
|---|
DisjointSet()
Construct a initially empty set.
|
DisjointSet(boolean hasTrash)
Construct a initially empty set with an optional trash set.
|
DisjointSet(DisjointSet<E> disjointSet)
Construct a new set mutually exclusive with the specified set.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E element)
Ensures that this collection contains the specified element.
|
boolean |
addAll(Collection<? extends E> 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(Object element)
Returns
true if this set contains the specified element. |
boolean |
containsAll(Collection<?> c)
Returns
true if this set contains all of the elements in the specified collection. |
boolean |
equals(Object set)
Compare this set with the specified object for equality.
|
Set<E> |
getTrash()
Returns the trash set, or
null if there is none. |
int |
hashCode()
Returns an hash value for this set.
|
Iterator<E> |
iterator()
Returns an iterator over the elements in this collection.
|
boolean |
remove(Object element)
Removes a single instance of the specified element from this set, if it is present.
|
boolean |
removeAll(Collection<?> c)
Removes from this set all of its elements that are contained in the specified collection.
|
boolean |
retainAll(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.
|
Object[] |
toArray()
Returns an array containing all of the elements in this collection.
|
<T> T[] |
toArray(T[] a)
Returns an array containing all of the elements in this collection.
|
String |
toString()
Returns a string representation of this set.
|
isEmptyisEmpty, spliteratorparallelStream, removeIf, streampublic DisjointSet()
DisjointSet(DisjointSet)
constructor with this newly created set as argument.
DisjointSets 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
DisjointSet(true) constructor.
public DisjointSet(boolean hasTrash)
DisjointSet(DisjointSet) constructor with this newly created set as argument.hasTrash - If true, all remove operations will add removed
elements to a trash set (thus, really just moving the element to the trash). If false, there is no trash and this constructor behave like the no-argument constructor.getTrash()public DisjointSet(DisjointSet<E> disjointSet)
disjointSet will also be mutually exclusive with the newly created set. If
disjointSet has a trash set, the newly created set will use the same trash (i.e. all
remove operations will really move the element to the trash set). Otherwise, the new
DisjointSet have no trash.disjointSet - The set to be disjoint from.public Set<E> getTrash()
null if there is none. The trash set receive all elements
removed from this set.null if none.public int size()
size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>public boolean contains(Object element)
true if this set contains the specified element.contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>element - Object to be checked for containment in this set.true if this set contains the specified element.public boolean add(E element)
add in interface Collection<E>add in interface Set<E>add in class AbstractCollection<E>element - Element whose presence in this set is to be ensured.true if the set changed as a result of the call.public boolean remove(Object element)
DisjointSet has a trash set, the removed element will be added to the trash set.remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>element - Element to be removed from this set.true if the set changed as a result of the call.public boolean containsAll(Collection<?> c)
true if this set contains all of the elements in the specified collection.containsAll in interface Collection<E>containsAll in interface Set<E>containsAll in class AbstractCollection<E>c - collection to be checked for containment in this collection.true if this set contains all of the elements in the specified collection.public boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E>addAll in interface Set<E>addAll in class AbstractCollection<E>c - collection whose elements are to be added to this set.true if this set changed as a result of the call.public boolean removeAll(Collection<?> c)
DisjointSet has a trash set, all removed elements will be added to the trash
set.removeAll in interface Collection<E>removeAll in interface Set<E>removeAll in class AbstractSet<E>c - elements to be removed from this set.true if this set changed as a result of the call.public boolean retainAll(Collection<?> c)
DisjointSet has a trash set, all removed elements will be added to the trash set.retainAll in interface Collection<E>retainAll in interface Set<E>retainAll in class AbstractCollection<E>c - elements to be retained in this collection.true if this collection changed as a result of the call.public void clear()
DisjointSet has a trash set, all
removed elements will be added to the trash set.clear in interface Collection<E>clear in interface Set<E>clear in class AbstractCollection<E>public Object[] toArray()
toArray in interface Collection<E>toArray in interface Set<E>toArray in class AbstractCollection<E>public <T> T[] toArray(T[] a)
toArray in interface Collection<E>toArray in interface Set<E>toArray in class AbstractCollection<E>T - The type of elements in the array.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.public String toString()
toString in class AbstractCollection<E>public int hashCode()
hashCode in interface Collection<E>hashCode in interface Set<E>hashCode in class AbstractSet<E>public boolean equals(Object set)
equals in interface Collection<E>equals in interface Set<E>equals in class AbstractSet<E>set - The object to compare with this set for equality.Copyright © 1996–2019 Geotools. All rights reserved.