com.aliasi.util
Class SmallSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by com.aliasi.util.SmallSet<E>
Type Parameters:
E - the type of object stored in the set
All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>

public abstract class SmallSet<E>
extends AbstractSet<E>

The SmallSet class implements immutable instances the Set interface tailored for sets with a small number of members. The sets created are included as member variables for very small sets and backed by arrays for larger sets. Although SmallSet does not support the Set.add(Object) method, it provides its own union(SmallSet) operation, which produces a new small set that is the result of unioning the set to which it is applied to the small set in the argument. There are no public constructors. Instaces are created using a family of create factory method in order to construct an appropriate representation based on the size of set being created.

Since:
LingPipe1.0
Version:
3.9.1
Author:
Bob Carpenter

Method Summary
static
<F> SmallSet<F>
create()
          Return an empty small set.
static
<F> SmallSet<F>
create(F member)
          Return a singleton empty set containing the specified member.
static
<F> SmallSet<F>
create(F[] members)
          Return a set consisting of members drawn from the specified array of members.
static
<F> SmallSet<F>
create(F member1, F member2)
          Return a set containing the two specified members.
static
<F> SmallSet<F>
create(F member, Set<? extends F> set)
          Return a small set containing the member and set of members specified in the arguments.
static
<F> SmallSet<F>
create(Set<? extends F> members)
          Return a small set containing the members specified in the set argument.
static
<F> SmallSet<F>
create(Set<? extends F> set1, Set<? extends F> set2)
          Return a small set containing all of the members of both specified sets.
abstract  SmallSet<E> union(SmallSet<? extends E> that)
          Returns the union of this set with the specified set, without modifying either this set or the specified set.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, size, toArray, toArray
 

Method Detail

union

public abstract SmallSet<E> union(SmallSet<? extends E> that)
Returns the union of this set with the specified set, without modifying either this set or the specified set.

Parameters:
that - Small set of elements to union with this set.
Returns:
The small set consisting of all of the elements in this set and the specified set.

create

public static <F> SmallSet<F> create()
Return an empty small set.

Type Parameters:
F - the type of object stored in the set
Returns:
Empty small set.

create

public static <F> SmallSet<F> create(F member)
Return a singleton empty set containing the specified member.

Type Parameters:
F - the type of object stored in the set
Parameters:
member - Single member of the returned set.
Returns:
Singleton small set consisting of the specified member.

create

public static <F> SmallSet<F> create(F member1,
                                     F member2)
Return a set containing the two specified members. The result will be a singleton or a pair, depending on whether the specified object are equal.

Type Parameters:
F - the type of object stored in the set
Parameters:
member1 - First member of set.
member2 - Second member of set.
Returns:
Small set containing only the specified members.

create

public static <F> SmallSet<F> create(F[] members)
Return a set consisting of members drawn from the specified array of members. The cardinality of the resulting set depends on whether pairs of specified members are equal. For zero, one and two-element input arrays, it returns the same result as create(), create(Object), and create(Object,Object), respectively.

Type Parameters:
F - the type of object stored in the set
Parameters:
members - Array of members for the resulting set.
Returns:
Small set consisting of specified members.

create

public static <F> SmallSet<F> create(Set<? extends F> members)
Return a small set containing the members specified in the set argument. The members of the set will be copied, so subsequent changes to the specified member set will not be reflected in the created set.

Type Parameters:
F - the type of object stored in the set
Parameters:
members - Set of members of the resulting set.
Returns:
Small set consisting of the specified members.

create

public static <F> SmallSet<F> create(F member,
                                     Set<? extends F> set)
Return a small set containing the member and set of members specified in the arguments.

Type Parameters:
F - the type of object stored in the set
Parameters:
member - Member to add to result set.
set - Set of members to add to the result set.
Returns:
Small set created of the specified member and set of members.

create

public static <F> SmallSet<F> create(Set<? extends F> set1,
                                     Set<? extends F> set2)
Return a small set containing all of the members of both specified sets.

Type Parameters:
F - the type of object stored in the set
Parameters:
set1 - First set of members of result set.
set2 - Second set of members of result set.
Returns:
Samll set consisting of the specified members.