edu.colorado.collections
Class LinkedSeq

java.lang.Object
  extended by edu.colorado.collections.LinkedSeq
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
DerivedStack

public class LinkedSeq
extends java.lang.Object
implements java.lang.Cloneable

This class is a homework assignment; A LinkedSeq is a sequence of references to Objects. The sequence can have a special "current element," which is specified and accessed through four methods that are not available in the bag classes (start, getCurrent, advance, and isCurrent).

Limitations:
Beyond Long.MAX_VALUE elements, the size method does not work. This is not a problem for current implementations of the Java Virtual Machine (JVM). But future JVMs could have heaps that allow linked lists longer than Long.MAX_VALUE.
Note:
This file contains only blank implementations ("stubs") because this is a Programming Project for my students.
Java Source Code for the stubs of this class:
http://www.cs.colorado.edu/~main/edu/colorado/collections/LinkedSeq.java


Constructor Summary
LinkedSeq()
          Initialize an empty sequence.
 
Method Summary
 void addAfter(java.lang.Object element)
          Adds a new element to this sequence, after the current element.
 void addAll(LinkedSeq addend)
          Place the contents of another sequence at the end of this sequence.
 void addBefore(java.lang.Object element)
          Adds a new element to this sequence, before the current element.
 void advance()
          Move forward, so that the current element is now the next element in the sequence.
 java.lang.Object clone()
          Generate a copy of this sequence.
static LinkedSeq concatentation(LinkedSeq s1, LinkedSeq s2)
          Create a new sequence that contains all the elements from one sequence followed by another.
 java.lang.Object getCurrent()
          Accessor method to determine the current capacity of this sequence.
 boolean isCurrent()
          Accessor method to determine whether this sequence has a specified current element that can be retrieved with the getCurrent method.
 void removeCurrent()
          Remove the current element from this sequence.
 long size()
          Accessor method to determine the number of elements in this sequence.
 void start()
          Set the current element at the front of this sequence.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinkedSeq

public LinkedSeq()
Initialize an empty sequence.

Parameters:
- - none
Postcondition:
This sequence is empty.
Method Detail

addAfter

public void addAfter(java.lang.Object element)
Adds a new element to this sequence, after the current element.

Parameters:
element - a reference to the new element that is being added
Postcondition:
A reference to the element has been added to this sequence. If there was a current element, the new element is placed after the current element. If there was no current element, the new element is placed at the end of the sequence. In all cases, the new element becomes the new current element of the sequence. Note that the newly added element may be a null reference.
Throws:
java.lang.OutOfMemoryError - Indicates insufficient memory for a new node.

addBefore

public void addBefore(java.lang.Object element)
Adds a new element to this sequence, before the current element.

Parameters:
element - a reference to the new element that is being added
Postcondition:
A reference to the element has been added to this sequence. If there was a current element, the new element is placed before the current element. If there was no current element, the new element is placed at the start of the sequence. In all cases, the new element becomes the new current element of the sequence. Note that the newly added element may be a null reference.
Throws:
java.lang.OutOfMemoryError - Indicates insufficient memory for a new node.

addAll

public void addAll(LinkedSeq addend)
Place the contents of another sequence at the end of this sequence.

Parameters:
addend - a sequence whose contents will be placed at the end of this sequence
Precondition:
The parameter, addend, is not null.
Postcondition:
The elements from addend have been placed at the end of this sequence. The current element of this sequence remains where it was, and the addend is also unchanged.
Throws:
java.lang.NullPointerException - Indicates that addend is null.
java.lang.OutOfMemoryError - Indicates insufficient memory to increase the size of this sequence.

advance

public void advance()
Move forward, so that the current element is now the next element in the sequence.

Parameters:
- - none
Precondition:
isCurrent( ) returns true.
Postcondition:
If the current element was already the end element of the sequence (with nothing after it), then there is no longer any current element. Otherwise, the new element is the element immediately after the original current element.
Throws:
java.lang.IllegalStateException - Indicates that there is no current element, so advance may not be activated.

clone

public java.lang.Object clone()
Generate a copy of this sequence.

Overrides:
clone in class java.lang.Object
Parameters:
- - none
Returns:
The return value is a copy of this sequence. Subsequent changes to the copy will not affect the original, nor vice versa. The return value must be type cast to a LinkedSeq before it is used.
Throws:
java.lang.OutOfMemoryError - Indicates insufficient memory for creating the clone.

concatentation

public static LinkedSeq concatentation(LinkedSeq s1,
                                       LinkedSeq s2)
Create a new sequence that contains all the elements from one sequence followed by another.

Parameters:
s1 - the first of two sequences
s2 - the second of two sequences
Precondition:
Neither s1 nor s2 is null.
Returns:
a new sequence that has the elements of s1 followed by s2 (with no current element)
Throws:
java.lang.NullPointerException - Indicates that one of the arguments is null.
java.lang.OutOfMemoryError - Indicates insufficient memory for the new sequence.

getCurrent

public java.lang.Object getCurrent()
Accessor method to determine the current capacity of this sequence. The addBefore and addAfter methods works efficiently (without needing more memory) until this capacity is reached.

Parameters:
- - none
Returns:
the current capacity of this sequence

isCurrent

public boolean isCurrent()
Accessor method to determine whether this sequence has a specified current element that can be retrieved with the getCurrent method.

Parameters:
- - none return true (there is a current element) or false (there is no current element at the moment)

removeCurrent

public void removeCurrent()
Remove the current element from this sequence.

Parameters:
- - none
Precondition:
isCurrent() returns true.
Postcondition:
The current element has been removed from this sequence, and the following element (if there is one) is now the new current element. If there was no following element, then there is now no current element.
Throws:
java.lang.IllegalStateException - Indicates that there is no current element, so removeCurrent may not be called.

size

public long size()
Accessor method to determine the number of elements in this sequence.

Parameters:
- - none
Returns:
the number of elements in this sequence

start

public void start()
Set the current element at the front of this sequence.

Parameters:
- - none
Postcondition:
The front element of this sequence is now the current element (but if this sequence has no elements at all, then there is no current element).