csc241.samples.stringList
Class stringLinkedListItr

java.lang.Object
  |
  +--csc241.samples.stringList.stringLinkedListItr
Direct Known Subclasses:
stringLinkedListSortedItr

public class stringLinkedListItr
extends java.lang.Object

stringLinkedListItr class maintains "current position" on a List


Field Summary
protected  ListNode current_
          Current position.
protected  stringLinkedList myList_
          The List.
 
Constructor Summary
stringLinkedListItr(stringLinkedList anyList)
          Construct the list.
 
Method Summary
 void advance()
          Advance the current_ position to the next node in the list.
 java.lang.String dump()
          return a string representing the list content
 boolean find(java.lang.String x)
          Set the current position to the first node containing an item.
 void first()
          Set the current_ position to the first node in the list.
 void insert(java.lang.String x)
          Insert after the current position.
 void insertAtBeginning(java.lang.String x)
          Insert at the beginning of the list.
 void remove(java.lang.String x)
          Remove the first occurrence of an item.
 java.lang.String retrieve()
          Return the item stored in the current_ position.
 boolean validCurrent()
          Test if the current position references a valid list item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myList_

protected stringLinkedList myList_
The List.

current_

protected ListNode current_
Current position.
Constructor Detail

stringLinkedListItr

public stringLinkedListItr(stringLinkedList anyList)
Construct the list. As a result of the construction, the current_ position is the first item, unless the list is empty, in which case the current_ is null.
Parameters:
anyList - a LinkedList object to which this iterator is permanently bound.
Method Detail

insert

public void insert(java.lang.String x)
            throws java.lang.Exception
Insert after the current position. current is set to the inserted node on success.
Parameters:
x - the item to insert.
Throws:
java.lang.Exception - if the current position is null.

insertAtBeginning

public void insertAtBeginning(java.lang.String x)
Insert at the beginning of the list. current is set to the inserted node.
Parameters:
x - the item to insert.

find

public boolean find(java.lang.String x)
Set the current position to the first node containing an item. current is unchanged if x is not found.
Parameters:
x - the item to search for.
Returns:
true if the item is found, false otherwise.

remove

public void remove(java.lang.String x)
            throws java.lang.Exception
Remove the first occurrence of an item. current is set to the node at the beginning of the list on success; remains unchanged otherwise.
Parameters:
x - the item to remove.
Throws:
java.lang.Exception - if the item is not found.

validCurrent

public boolean validCurrent()
Test if the current position references a valid list item.
Returns:
true if the current position is not null

retrieve

public java.lang.String retrieve()
Return the item stored in the current_ position.
Returns:
the stored item or null if the current_ position is not in the list.

first

public void first()
Set the current_ position to the first node in the list. This operation is valid for empty lists.

advance

public void advance()
Advance the current_ position to the next node in the list. If the current_ position is null, then do nothing. No exceptions are thrown by this routine because in the most common use (inside a for loop), this would require the programmer to add an unnecessary try/catch block.

dump

public java.lang.String dump()
return a string representing the list content