org.metasyntactic.utilities
Class SetUtilities

java.lang.Object
  |
  +--org.metasyntactic.utilities.SetUtilities

public class SetUtilities
extends java.lang.Object

A set is a collection of distinguishable objects, called its members or elements. If an object x is a member of a set S, we write x ∈ S (read "x is a member of S" or, more briefly, "x is in S"). If x is not a member of S, we write x ∉ S. We can describe a set by explicitly listing its members as a list inside braces. For example, we can define a set S to contain precisely the numbers 1, 2, and 3 by writing S = {1, 2, 3}. Since 2 is a member of the set S we can write 2 ∈ S, and since 4 is not a member, we have 4 ∉ S. A set cannot contain the same object more then once, and its elements are not ordered. Two sets A and B are equal, written A = B, if they contain the same elements. For example, {1, 2, 3, 1} = {1, 2, 3} = {3, 2, 1}.

We adopt special notations for frequently encountered sets.

For any set A, we have AA. For two sets A and B, we have A = B if and only if AB and BA. For any three sets A, B, and C, if AB and BC, then AC. For any set A we have ∅ ⊆ A.


Method Summary
static java.util.Set difference(java.util.Collection c1, java.util.Collection c2)
           The difference of sets A and B is the set
static java.util.Set difference(java.util.TreeSet c1, java.util.TreeSet c2)
           
static java.util.Set intersection(java.util.Collection c1, java.util.Collection c2)
           The intersection of sets A and B is the set
static java.util.Set intersection(java.util.TreeSet c1, java.util.TreeSet c2)
           
static void main(java.lang.String[] args)
           
static java.util.Set powerSet(java.util.Set s)
          The set of all subsets of a set S, including the empty set and the set S itself, is denoted 2S and is called the power set of S.
static java.lang.String toString(java.util.Set s)
          A singleton is a Set with only one element.
static java.util.Set union(java.util.Collection c1, java.util.Collection c2)
           The union of sets A and B is the set
static java.util.Set union(java.util.TreeSet c1, java.util.TreeSet c2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

intersection

public static java.util.Set intersection(java.util.Collection c1,
                                         java.util.Collection c2)

The intersection of sets A and B is the set

AB = {x | x ∈ A and x ∈ B}.

Note! Neither set is affected by this operation. To make this set equal to the intersection of itself and c use retainAll(Collection c)

Returns:
The set equal to the intersection of this set and c
See Also:
#retainAll(Collection c)

intersection

public static java.util.Set intersection(java.util.TreeSet c1,
                                         java.util.TreeSet c2)

union

public static java.util.Set union(java.util.Collection c1,
                                  java.util.Collection c2)

The union of sets A and B is the set

AB = {x | x ∈ A or x ∈ B}.

Note! Neither set is affected by this operation. TO make this set equal to the union of itself and c use addAll(Collection c)

Returns:
the set equal to the union of this and c
See Also:
#addAll(Collection c)

union

public static java.util.Set union(java.util.TreeSet c1,
                                  java.util.TreeSet c2)

difference

public static java.util.Set difference(java.util.Collection c1,
                                       java.util.Collection c2)

The difference of sets A and B is the set

A - B = {x | x ∈ A and x ∉ B}.

Note! Neither set is affected by this operation. To make this set equal to the difference of itself and c use removeAll(Collection c)

Returns:
the Set equal to the difference of this and c
See Also:
#removeAll(Collection c)

difference

public static java.util.Set difference(java.util.TreeSet c1,
                                       java.util.TreeSet c2)

powerSet

public static java.util.Set powerSet(java.util.Set s)
The set of all subsets of a set S, including the empty set and the set S itself, is denoted 2S and is called the power set of S. For example, 2{a, b} = {∅, {a}, {b}, {a, b}}. The power set of a finite set S has cardinality 2|S|.

Note! powerSet does not convert this set into a power set. It merely returns the powerset of this set

Returns:
the powerset of this Set

toString

public static java.lang.String toString(java.util.Set s)
A singleton is a Set with only one element.


main

public static void main(java.lang.String[] args)