Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Util.Collections
Class LinearSet  view LinearSet download LinearSet.java

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended byUtil.Collections.LinearSet
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.lang.Iterable, java.io.Serializable, java.util.Set

public class LinearSet
extends java.util.AbstractSet
implements java.lang.Cloneable, java.io.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.1 2003/03/05 08:26:27 joewhaley Exp $

Field Summary
private  ListFactory lf
           
private  java.util.List list
           
 
Constructor Summary
LinearSet()
          Creates a LinearSet.
LinearSet(int capacity)
          Creates a LinearSet with given capacity.
LinearSet(ListFactory lf)
          Creates an empty LinearSet, using a List generated by lf as the backing store.
LinearSet(ListFactory lf, int capacity)
          Creates an empty LinearSet with a given capacity, using a List generated by lf as the backing store.
LinearSet(ListFactory lf, java.util.Set set)
          Creates an empty LinearSet, using a List generated by lf as the backing store, and fills it with the elements of set.
LinearSet(java.util.Set set)
          Creates a LinearSet, filling it with the elements of set.
 
Method Summary
 boolean add(java.lang.Object o)
          Adds the specified element to the set if it is not already present (optional operation).
 boolean addAll(java.util.Collection c)
          Adds all of the elements of the given collection to this set (optional operation).
 void clear()
          Removes all elements from this set (optional operation).
 java.lang.Object clone()
          This method may be called to create a new copy of the Object.
 java.lang.Object get(java.lang.Object o)
           
 java.util.Iterator iterator()
          Returns an iterator over the set.
 boolean remove(java.lang.Object o)
          Removes the specified element from this set (optional operation).
 int size()
          Returns the number of elements in the set.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
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
contains, containsAll, isEmpty, retainAll, toArray, toArray
 

Field Detail

list

private java.util.List list

lf

private ListFactory lf
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(java.util.Set set)
Creates a LinearSet, filling it with the elements of set. Uses an ArrayList as the backing store.


LinearSet

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


LinearSet

public LinearSet(ListFactory 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 lf,
                 java.util.Set 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 java.util.Iterator iterator()
Description copied from interface: java.util.Set
Returns an iterator over the set. The iterator has no specific order, unless further specified.

Specified by:
iterator in interface java.util.Set

size

public int size()
Description copied from interface: java.util.Set
Returns the number of elements in the set. If there are more than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. This is the cardinality of the set.

Specified by:
size in interface java.util.Set

add

public boolean add(java.lang.Object o)
Description copied from interface: java.util.Set
Adds the specified element to the set if it is not already present (optional operation). In particular, the comparison algorithm is o == null ? e == null : o.equals(e). Sets need not permit all values, and may document what exceptions will be thrown if a value is not permitted.

Specified by:
add in interface java.util.Set

addAll

public boolean addAll(java.util.Collection c)
Description copied from interface: java.util.Set
Adds all of the elements of the given collection to this set (optional operation). If the argument is also a Set, this returns the mathematical union of the two. The behavior is unspecified if the set is modified while this is taking place.

Specified by:
addAll in interface java.util.Set

remove

public boolean remove(java.lang.Object o)
Description copied from interface: java.util.Set
Removes the specified element from this set (optional operation). If an element e exists, o == null ? e == null : o.equals(e), it is removed from the set.

Specified by:
remove in interface java.util.Set

clear

public void clear()
Description copied from interface: java.util.Set
Removes all elements from this set (optional operation). This set will be empty afterwords, unless an exception occurs.

Specified by:
clear in interface java.util.Set

get

public java.lang.Object get(java.lang.Object o)

clone

public java.lang.Object clone()
Description copied from class: java.lang.Object
This method may be called to create a new copy of the Object. The typical behavior is as follows:
  • o == o.clone() is false
  • o.getClass() == o.clone().getClass() is true
  • o.equals(o) is true

However, these are not strict requirements, and may be violated if necessary. Of the three requirements, the last is the most commonly violated, particularly if the subclass does not override Object.equals(Object)>Object.equals(Object) 55 .

If the Object you call clone() on does not implement java.lang.Cloneable (which is a placeholder interface), then a CloneNotSupportedException is thrown. Notice that Object does not implement Cloneable; this method exists as a convenience for subclasses that do.

Object's implementation of clone allocates space for the new Object using the correct class, without calling any constructors, and then fills in all of the new field values with the old field values. Thus, it is a shallow copy. However, subclasses are permitted to make a deep copy.

All array types implement Cloneable, and override this method as follows (it should never fail):

 public Object clone()
 {
   try
     {
       super.clone();
     }
   catch (CloneNotSupportedException e)
     {
       throw new InternalError(e.getMessage());
     }
 }