JUtil

net.cscott.jutil
Class LinearSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by net.cscott.jutil.LinearSet<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>

public class LinearSet<E>
extends AbstractSet<E>
implements Cloneable, Serializable

LinearSet is a simplistic light-weight Set designed for use when the number of entries is small. It is backed by a List.

Version:
$Id: LinearSet.java,v 1.6 2006-10-30 19:58:06 cananian Exp $
Author:
Felix S. Klock II
See Also:
Serialized Form

Constructor Summary
LinearSet()
          Creates a LinearSet.
LinearSet(Collection<? extends E> c)
          Creates a LinearSet, filling it with the elements of the given collection.
LinearSet(int capacity)
          Creates a LinearSet with given capacity.
LinearSet(ListFactory<E> lf)
          Creates an empty LinearSet, using a List generated by lf as the backing store.
LinearSet(ListFactory<E> lf, int capacity)
          Creates an empty LinearSet with a given capacity, using a List generated by lf as the backing store.
LinearSet(ListFactory<E> lf, Set<? extends E> set)
          Creates an empty LinearSet, using a List generated by lf as the backing store, and fills it with the elements of set.
LinearSet(Set<? extends E> set)
          Creates a LinearSet, filling it with the elements of set.
 
Method Summary
 boolean add(E o)
           
 boolean addAll(Collection<? extends E> c)
           
 LinearSet<E> clone()
           
 Iterator<E> iterator()
           
 boolean remove(Object o)
           
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
clear, contains, containsAll, isEmpty, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
clear, contains, containsAll, isEmpty, retainAll, toArray, toArray
 

Constructor Detail

LinearSet

public LinearSet()
Creates a LinearSet. Uses an ArrayList as the backing store.


LinearSet

public LinearSet(int capacity)
Creates a LinearSet with given capacity. Uses an ArrayList as the backing store.


LinearSet

public LinearSet(Set<? extends E> set)
Creates a LinearSet, filling it with the elements of set. Uses an ArrayList as the backing store.


LinearSet

public LinearSet(Collection<? extends E> c)
Creates a LinearSet, filling it with the elements of the given collection. Uses an ArrayList as the backing store. Uses time quadratic in the size of the given collection.


LinearSet

public LinearSet(ListFactory<E> lf)
Creates an empty LinearSet, using a List generated by lf as the backing store.


LinearSet

public LinearSet(ListFactory<E> lf,
                 int capacity)
Creates an empty LinearSet with a given capacity, using a List generated by lf as the backing store.


LinearSet

public LinearSet(ListFactory<E> lf,
                 Set<? extends E> set)
Creates an empty LinearSet, using a List generated by lf as the backing store, and fills it with the elements of set.

Method Detail

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Set<E>
Specified by:
iterator in class AbstractCollection<E>

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface Set<E>
Specified by:
size in class AbstractCollection<E>

add

public boolean add(E o)
Specified by:
add in interface Collection<E>
Specified by:
add in interface Set<E>
Overrides:
add in class AbstractCollection<E>

addAll

public boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface Set<E>
Overrides:
addAll in class AbstractCollection<E>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface Set<E>
Overrides:
remove in class AbstractCollection<E>

clone

public LinearSet<E> clone()
Overrides:
clone in class Object

JUtil

Copyright (c) 2006 C. Scott Ananian