public class

DisjointSets

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.collect.DisjointSets<T>

Class Overview

This type represents disjoint sets.

The following operations define what a disjoint set is:

  • The add1 operation creates a new set with that value, unless an existing set containing that value already exists.
  • The add2 operation adds two "connected elements": they must reside in the same set. If those two elements currently reside in two separate sets, those sets are merged.

This class does not override hashCode/equals. Internally, HashSet objects are used. Therefore, there is no guarantee provided on elements ordering.

Objects of this class are serializable at the condition that T is serializable.

Summary

Public Constructors
DisjointSets()
Create a new "disjoint sets" object
Public Methods
boolean add(T v)
Create a set and add the provided value, unless a set with the value already exists.
boolean add(T a, T b)
Add two linked values to the same set, potentially merging two existing sets into one.
void clear()
Clear all sets.
int getCountOfValues()
Retrieve the count of elements existing in all the sets managed by this object.
Collection<Set<T>> getSets()
Retrieve a read-only view of the current disjoint sets managed by this object.
Set<T> getValues()
Retrieve the values stored in all the sets managed by this object.
boolean isEmpty()
Determine whether this object contains at least one set.
int size()
Retrieve the count of sets.
String toString()
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public DisjointSets ()

Create a new "disjoint sets" object

Public Methods

public boolean add (T v)

Create a set and add the provided value, unless a set with the value already exists.

Parameters
v a value
Returns
  • true if a new set was created to accommodate the provided value; false if the provided value was already present in an existing set

public boolean add (T a, T b)

Add two linked values to the same set, potentially merging two existing sets into one.

Parameters
a first value
b second value
Returns
  • true if the sets were modified; false if nothing changed

public void clear ()

Clear all sets.

public int getCountOfValues ()

Retrieve the count of elements existing in all the sets managed by this object.

public Collection<Set<T>> getSets ()

Retrieve a read-only view of the current disjoint sets managed by this object.

public Set<T> getValues ()

Retrieve the values stored in all the sets managed by this object.

public boolean isEmpty ()

Determine whether this object contains at least one set.

public int size ()

Retrieve the count of sets.

public String toString ()