org.mindswap.pellet.utils
Class SetUtils

java.lang.Object
  extended by org.mindswap.pellet.utils.SetUtils

public class SetUtils
extends java.lang.Object

Utility functions for {#link java.util.Set Set}s.

Author:
Evren Sirin

Field Summary
static java.util.Set<?> EMPTY_SET
           
 
Constructor Summary
SetUtils()
           
 
Method Summary
static
<T> java.util.Set<T>
add(T o, java.util.Set<T> set)
          Adds the given object to the set but saves memory space by allocating only the required amount for small sets.
static
<T> java.util.Set<T>
binary(T o1, T o2)
           
static
<T> java.util.Set<T>
create(java.util.Collection<T> coll)
          Creates a set containing all the elements in the collection
static
<T> java.util.Set<T>
create(T... elems)
          Creates a list containing all the elements in the array
static
<T> java.util.Set<T>
difference(java.util.Collection<T> c1, java.util.Collection<? extends java.lang.Object> c2)
          Returns the difference of two sets.
static
<T> java.util.Set<T>
emptySet()
           
static
<T> boolean
equals(java.util.Set<T> s1, java.util.Set<T> s2)
          Checks if one set is equal of another one
static
<T> java.util.Set<T>
intersection(java.util.Collection<? extends java.util.Collection<? extends T>> coll)
          Returns the intersection of all the collections given in a collection.
static
<T> java.util.Set<T>
intersection(java.util.Collection<? extends T> c1, java.util.Collection<? extends T> c2)
          Returns the intersection of two collections
static boolean intersects(java.util.Collection<?> c1, java.util.Collection<?> c2)
          Checks if two collections have any elements in common
static
<T> java.util.Set<T>
remove(java.lang.Object o, java.util.Set<T> set)
           
static
<T> java.util.Set<T>
singleton(T o)
           
static boolean subset(java.util.Set<?> sub, java.util.Set<?> sup)
          Checks if one set is subset of another one
static
<T> java.util.Set<T>
union(java.util.Collection<? extends java.util.Collection<? extends T>> coll)
          Returns the union of all the sets given in a collection.
static
<T> java.util.Set<T>
union(java.util.Collection<? extends T> c1, java.util.Collection<? extends T> c2)
          Returns the union of two collections
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_SET

public static final java.util.Set<?> EMPTY_SET
Constructor Detail

SetUtils

public SetUtils()
Method Detail

add

public static <T> java.util.Set<T> add(T o,
                                       java.util.Set<T> set)
Adds the given object to the set but saves memory space by allocating only the required amount for small sets. The idea is to use the specialized empty set and singleton set implementations (which are immutable) for the sets of size 0 and 1. If the set is empty a new singleton set is created, if set has one element we create a new set with two elements, otherwise we simply add the element to the given set.This technique is most useful if the expected set size is 0 or 1.

Parameters:
o -
set -
Returns:

emptySet

public static final <T> java.util.Set<T> emptySet()

remove

public static <T> java.util.Set<T> remove(java.lang.Object o,
                                          java.util.Set<T> set)

singleton

public static final <T> java.util.Set<T> singleton(T o)

binary

public static final <T> java.util.Set<T> binary(T o1,
                                                T o2)

union

public static <T> java.util.Set<T> union(java.util.Collection<? extends java.util.Collection<? extends T>> coll)
Returns the union of all the sets given in a collection.

Parameters:
coll - A Collection of sets

union

public static <T> java.util.Set<T> union(java.util.Collection<? extends T> c1,
                                         java.util.Collection<? extends T> c2)
Returns the union of two collections

Parameters:
coll - A Collection of sets

intersection

public static <T> java.util.Set<T> intersection(java.util.Collection<? extends java.util.Collection<? extends T>> coll)
Returns the intersection of all the collections given in a collection.

Parameters:
coll - A Collection of sets

intersection

public static <T> java.util.Set<T> intersection(java.util.Collection<? extends T> c1,
                                                java.util.Collection<? extends T> c2)
Returns the intersection of two collections

Parameters:
coll - A Collection of sets

intersects

public static boolean intersects(java.util.Collection<?> c1,
                                 java.util.Collection<?> c2)
Checks if two collections have any elements in common


subset

public static boolean subset(java.util.Set<?> sub,
                             java.util.Set<?> sup)
Checks if one set is subset of another one

Parameters:
sub -
sup -
Returns:

equals

public static <T> boolean equals(java.util.Set<T> s1,
                                 java.util.Set<T> s2)
Checks if one set is equal of another one

Parameters:
sub -
sup -
Returns:

difference

public static <T> java.util.Set<T> difference(java.util.Collection<T> c1,
                                              java.util.Collection<? extends java.lang.Object> c2)
Returns the difference of two sets. All the elements of second set is removed from the first set

Parameters:
coll - A Collection of sets

create

public static <T> java.util.Set<T> create(T... elems)
Creates a list containing all the elements in the array

Parameters:
elements -
Returns:

create

public static <T> java.util.Set<T> create(java.util.Collection<T> coll)
Creates a set containing all the elements in the collection

Parameters:
elements -
Returns:


Copyright © 2004 Evren Sirin. All Rights Reserved.