Class DisjointSets<T>

java.lang.Object
com.pnfsoftware.jeb.util.collect.DisjointSets<T>
Type Parameters:
T -

@Ser public class DisjointSets<T> extends Object
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.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new "disjoint sets" object
  • Method Summary

    Modifier and Type
    Method
    Description
    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 all sets.
    int
    Retrieve the count of elements existing in all the sets managed by this object.
    Retrieve a read-only view of the current disjoint sets managed by this object.
    Retrieve the values stored in all the sets managed by this object.
    boolean
    Determine whether this object contains at least one set.
    int
    Retrieve the count of sets.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DisjointSets

      public DisjointSets()
      Create a new "disjoint sets" object
  • Method Details

    • clear

      public void clear()
      Clear all sets.
    • isEmpty

      public boolean isEmpty()
      Determine whether this object contains at least one set.
      Returns:
    • size

      public int size()
      Retrieve the count of sets.
      Returns:
    • getCountOfValues

      public int getCountOfValues()
      Retrieve the count of elements existing in all the sets managed by this object.
      Returns:
    • getValues

      public Set<T> getValues()
      Retrieve the values stored in all the sets managed by this object.
      Returns:
    • getSets

      public Collection<Set<T>> getSets()
      Retrieve a read-only view of the current disjoint sets managed by this object.
      Returns:
    • add

      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
    • add

      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
    • toString

      public String toString()
      Overrides:
      toString in class Object