Algorithm
Development Kit 1.0

algs.model.list
Class List<E>

java.lang.Object
  extended by algs.model.list.List<E>
Type Parameters:
E - the underlying Node parameterization
All Implemented Interfaces:
java.lang.Iterable<E>

public class List<E>
extends java.lang.Object
implements java.lang.Iterable<E>

List of objects.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
List()
          Construct an empty list.
 
Method Summary
 void append(E e)
          Append element to the end of the list.
 void concat(List<E> list)
          Concatenate a list to the end of our list.
 E contains(E e)
          Determine membership by returning element if found.
 Node<E> head()
          Return head of the list.
 boolean isEmpty()
          Return whether the list is empty.
 java.util.Iterator<E> iterator()
          Return iterator over the list.
 E remove()
          Remove element from the front of the list and return it.
 int size()
          Return size of the list.
 java.lang.String toString()
          Useful string for debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

List

public List()
Construct an empty list.

Method Detail

isEmpty

public boolean isEmpty()
Return whether the list is empty.


size

public int size()
Return size of the list.


head

public Node<E> head()
Return head of the list.


append

public void append(E e)
Append element to the end of the list.

Parameters:
e - element to be appended.

contains

public E contains(E e)
Determine membership by returning element if found.

We return the object in the list, rather than boolean, since complex objects that meet 'equals' may, in fact, contain additional information and the external code might want to have the actual object in the list.

Parameters:
e - sought for object.

remove

public E remove()
Remove element from the front of the list and return it.

Throws:
java.util.NoSuchElementException - if list is empty.

concat

public void concat(List<E> list)
Concatenate a list to the end of our list.

If list is null, then no operation (or error) occurs. Note that concatenating list A to B does not affect the passed in list parameter. Thus you may end up with some interesting intermingled objects if you are not careful.

Parameters:
list - List to be concatenated to the end of the list.

toString

public java.lang.String toString()
Useful string for debugging.

Overrides:
toString in class java.lang.Object

iterator

public java.util.Iterator<E> iterator()
Return iterator over the list.

Specified by:
iterator in interface java.lang.Iterable<E>

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.