|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.util.ListEntry
public class ListEntry
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.
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 |
---|
public ListEntry()
public ListEntry(ListEntry prevEntry, ListEntry nextEntry) throws IllegalArgumentException
prevEntry
- a reference to the previous entry, must not yet have
a next element; or null
if this is the first entry in a listnextEntry
- a reference to the next entry, must not yet have
a next element; or null
if this is the final entry in a list
IllegalArgumentException
- if prevEntry
already has
a next element (hasNext()
== true
) or if
nextEntry
already has a previous element
(hasPrevious()
== true
)Method Detail |
---|
public boolean hasNext()
true
if there is a next element. (In other words,
returns true
if next()
would return an element
rather than null
.)
true
iff the list has more elementspublic boolean hasPrevious()
true
if there is a previous element. (In other
words, returns true
if previous()
would return an
element rather than null
.)
true
iff the list has more elementspublic void insertAfter(ListEntry newEntry) throws IllegalArgumentException, NullPointerException
hasPrevious()
must return false
).
The next()
element of either this entry or the new
entry must be null
.
Inserting null
elements is not allowed.
newEntry
- the new list entry to insert
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
public void insertBefore(ListEntry newEntry) throws IllegalArgumentException, NullPointerException
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.
newEntry
- the new list entry to insert
IllegalArgumentException
- if the conditions stated above are
violated
NullPointerException
- if newEntry
is
null
public ListEntry next()
null
if there is
no next elementpublic ListEntry previous()
null
if there
is no previous elementpublic void remove()
hasPrevious()
and hasNext()
will
return false
.
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |