de.fu_berlin.ties.util
Class ListEntry

java.lang.Object
  extended by de.fu_berlin.ties.util.ListEntry
Direct Known Subclasses:
XMLConstituent

public class ListEntry
extends Object

An entry in a doubly linked list. Useful when you cannot use the List implementations, e.g. because you need direct references to list entries. This class only stores a reference to the previous and next entry for list management -- you must extend it so store any useful data.

Version:
$Revision: 1.3 $, $Date: 2004/08/24 18:00:38 $, $Author: siefkes $
Author:
Christian Siefkes

Constructor Summary
ListEntry()
          Creates a new instance, without setting references to surrounding entries.
ListEntry(ListEntry prevEntry, ListEntry nextEntry)
          Creates a new instance.
 
Method Summary
 boolean hasNext()
          Returns true if there is a next element.
 boolean hasPrevious()
          Returns true if there is a previous element.
 void insertAfter(ListEntry newEntry)
          Inserts a new element after the current one, adjusting the list structure accordingly.
 void insertBefore(ListEntry newEntry)
          Inserts a new element before the current one, adjusting the list structure accordingly.
 ListEntry next()
          Returns the next element in the list, if any.
 ListEntry previous()
          Returns the previous element in the list, if any.
 void remove()
          Removes this entry from this list.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ListEntry

public ListEntry()
Creates a new instance, without setting references to surrounding entries.


ListEntry

public ListEntry(ListEntry prevEntry,
                 ListEntry nextEntry)
          throws IllegalArgumentException
Creates a new instance.

Parameters:
prevEntry - a reference to the previous entry, must not yet have a next element; or null if this is the first entry in a list
nextEntry - a reference to the next entry, must not yet have a next element; or null if this is the final entry in a list
Throws:
IllegalArgumentException - if prevEntry already has a next element (hasNext() == true) or if nextEntry already has a previous element (hasPrevious() == true)
Method Detail

hasNext

public boolean hasNext()
Returns true if there is a next element. (In other words, returns true if next() would return an element rather than null.)

Returns:
true iff the list has more elements

hasPrevious

public boolean hasPrevious()
Returns true if there is a previous element. (In other words, returns true if previous() would return an element rather than null.)

Returns:
true iff the list has more elements

insertAfter

public void insertAfter(ListEntry newEntry)
                 throws IllegalArgumentException,
                        NullPointerException
Inserts a new element after the current one, adjusting the list structure accordingly. The new entry must not yet have a previous element (i.e., calling hasPrevious() must return false). The next() element of either this entry or the new entry must be null. Inserting null elements is not allowed.

Parameters:
newEntry - the new list entry to insert
Throws:
IllegalArgumentException - if newEntry already has a previous element (hasPrevious() == true) or both this entry and newEntry have a next() element
NullPointerException - if newEntry is null

insertBefore

public void insertBefore(ListEntry newEntry)
                  throws IllegalArgumentException,
                         NullPointerException
Inserts a new element before the current one, adjusting the list structure accordingly. If this entry has a previous() element, the next() element of either the new entry or the previous() element must be null; otherwise the next() element of either this entry or the new entry must be null. Inserting null elements is not allowed.

Parameters:
newEntry - the new list entry to insert
Throws:
IllegalArgumentException - if the conditions stated above are violated
NullPointerException - if newEntry is null

next

public ListEntry next()
Returns the next element in the list, if any.

Returns:
the next element in the list, or null if there is no next element

previous

public ListEntry previous()
Returns the previous element in the list, if any.

Returns:
the previous element in the list, or null if there is no previous element

remove

public void remove()
Removes this entry from this list. The list structure is adjusted accordingly. Afterwards this entry won't be part of a list, i.e. both hasPrevious() and hasNext() will return false.


toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a textual representation


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.