|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbyucc.jhdl.base.list.LinkedList
It is assumed that this class will always be subclassed and that insert and some get function will be defined based on insert() and getElt(). All of the other functions for deletion, iteration, etc., are available for use by anyone accessing the subclass. The intention is to keep the user from putting things in the list that don't belong there and to avoid corruption of the list. I don't try and keep the the user from doing weird things with stuff they get out of the list. In-order traversal is as simple as for(list.init(); !list.atEnd(); list.next()) { ... list.getElt(); ... }. This implements a doubly-linked list, with root pointing backward to tail, last element pointing forward to null, allowing easy append() and atEnd(). Also, LinkedListElt has package-visible fields for faster access. LinkedLists are ideal for large lists, lists built primarily by appends, and lists with frequent deletes using in-order traversal. In-order traversal, insert, append, and deleteCurrent are all O(1), inList, delete, intersect, and appendList are O(n).
Constructor Summary | |
LinkedList()
|
Method Summary | |
protected void |
append(java.lang.Object elt)
Append just puts the new element at the end of the list. |
protected void |
appendList(LinkedList lst)
Modifies calling list by appending contents of argument onto tail end, maintaing the order of elements from the argument. |
boolean |
atBegin()
Returns true if the current pointer is at the beginning of the list during reverse traversal. |
boolean |
atEnd()
Returns true if the current pointer is at the end of the list |
boolean |
delete(java.lang.Object elt)
Deletes all references to elt in the list, and reinitializes list. |
void |
deleteAll()
Deletes all elements of the list |
void |
deleteCurrent()
During iteration this just deletes whatever current is pointing to. |
int |
elementCount()
Count the number of elements in a list. |
boolean |
empty()
Returns true if the list is empty |
protected LinkedList |
filter(Predicate pred)
Filters a list in place, preserving only the elements for which Predicate.accept() returns true. |
LinkedListElt |
getCurrent()
Returns the LinkedListElt that current is pointing to. |
protected java.lang.Object |
getElt()
Returns the current element, or null if beyond list end |
void |
init()
Initializes the list for traversal, so that the current pointer is at the front of the list |
void |
initReverse()
Initialize the list for traversal, so that the current pointer is at the back of the list |
boolean |
inList(java.lang.Object o)
Returns true if the object is currently in the list at least once. |
protected void |
insert(java.lang.Object elt)
Insert just puts the new element at the top of the list, moving everyone else down. |
protected void |
insertAfterCurrent(java.lang.Object elt)
Inserts element after the current one, appending if at the end of the list. |
protected void |
insertBeforeCurrent(java.lang.Object elt)
Inserts element before the current one, appending if at the end of the list. |
protected void |
insertList(LinkedList lst)
Modifies calling list by inserting contents of argument in reverse order at head. |
protected LinkedList |
intersect(LinkedList ret_list,
LinkedList lst)
Returns the intersection of two lists, the argument and this. |
protected void |
merge(LinkedList other_list)
Merges other_list onto the end of this. |
void |
next()
Advances the current pointer to the next element; if already at the end does nothing |
void |
prev()
Reverses the current pointer to the prior element; if already at the front does nothing |
java.lang.String |
toString()
Provides a String representation for use in debug. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public LinkedList()
Method Detail |
public final void init()
init
in interface List
public final void initReverse()
public final boolean empty()
public final void next()
next
in interface List
public final void prev()
prev
in interface List
protected java.lang.Object getElt()
public final boolean atEnd()
atEnd
in interface List
public final boolean atBegin()
public final boolean inList(java.lang.Object o)
inList
in interface List
public final void deleteCurrent()
protected final void insert(java.lang.Object elt)
elt
- the object to insertprotected final void append(java.lang.Object elt)
elt
- the object to appendprotected final void insertAfterCurrent(java.lang.Object elt)
elt
- the object to insertprotected final void insertBeforeCurrent(java.lang.Object elt)
elt
- the object to insertprotected LinkedList intersect(LinkedList ret_list, LinkedList lst)
ret_list
- The empty list that will be returned with the result (must be passed a list, because reflection cannot always generate the correct list type)lst
- The list to check along with bound list (this).
protected void appendList(LinkedList lst)
lst
- The list to grab elements from, unmodified.
protected void insertList(LinkedList lst)
for (lst.init(); !lst.atEnd(); lst.next())
this.insert(lst.getElt());
.
lst
- The list to insert, unmodified, but read in reverse order.
public void deleteAll()
public boolean delete(java.lang.Object elt)
elt
- the element to delete
public int elementCount()
elementCount
in interface List
public LinkedListElt getCurrent()
protected void merge(LinkedList other_list)
other_list
- list to mergepublic java.lang.String toString()
protected LinkedList filter(Predicate pred)
pred
- the predicate for determining list membership
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |