All Packages Class Hierarchy This Package Previous Next Index
Class com.roguewave.tools.v2-0.Dlist
java.lang.Object
|
+----com.roguewave.tools.v2-0.CollectionBase
|
+----com.roguewave.tools.v2-0.Dlist
- public class Dlist
- extends CollectionBase
- implements Cloneable, Serializable, Sequence
Class Dlist implements a doubly-linked list of elements ordered
externally by the client of the class. Duplicate entries are allowed.
Items can efficiently be inserted at either the beginning, end, or
middle of the list, and likewise for removal.
There are several ways to retrieve elements from within the collection.
One is by numeric index. Another is by searching for an element which
is equal to a given item, as determined by the equals() method
inherited or overridden from class Object. Finally, one can search
for an element which is identical to a given item, that is,
equal in the sense of the == operator.
The primary difference between classes Dlist and Slist is that
a Dlist provides an enumerator that allows for movement both
forwards and backwards within the collection. The cost is that
each node in the Dlist contains one extra pointer over those in an
Slist.
The storage and maintenance of this extra pointer means that
Slists are a tad more efficient in space and time.
- See Also:
- Slist
-
head_
- Sentinel link pointing to first node
-
last_
- reference to last node for convenience
-
tail_
- Sentinel link positioned past last node
-
Dlist()
- Creates an empty doubly-linked list
-
append(Object)
- Adds an element to the end of the list
-
at(int)
- Returns the ith element of the list where
i is between 0 and
one less than the number of entries.
-
atPut(int, Object)
- Replaces the element at the given position
with the given item.
-
bidirectionalElements()
- Returns a bidirectional enumeration of the elements in the list.
-
clear()
- Removes all elements from the list.
-
clone()
- Returns a clone of this Dlist.
-
contains(Object)
- Returns true if the list contains an element equal to (equals())
the given item.
-
containsReference(Object)
- Returns true if the list contains an element that
is identical to (==) the given item.
-
elements()
- Returns an enumeration of the elements in the list.
-
find(Object)
- Returns the first element in the list equal to (equals())
the given item, or null if no such element is found.
-
first()
- Returns the first element of the list.
-
index(Object)
- Returns the position (from 0) of the first element in the list
equal to (equals()) the given item, or -1 if not found.
-
indexReference(Object)
- Returns the position (from 0) of the first element in the list
that is identical to (==) the given item, or -1 if not found.
-
init()
- Initializes member data as appropriate for an empty list.
-
insert(Object)
- Adds the given item to the end of the list.
-
insertAt(int, Object)
- Adds the given item to the list in front of the element at
the given position.
-
last()
- Returns the last element of the list.
-
occurrencesOf(Object)
- Returns the number of items in the list
equal to (equals()) the given item.
-
occurrencesOfReference(Object)
- Returns the number of items in the list
identical to (==) the given item.
-
prepend(Object)
- Adds the given item to the beginning of the list.
-
remove(Object)
- Removes the first element in the list equal to (equals())
the given item.
-
removeAll(Object)
- Removes all elements in the list equal to (equals())
the given item.
-
removeAllReference(Object)
- Removes all elements in the list identical to (==)
the given item.
-
removeAt(int)
- Removes the ith element of the list where
i is between 0 and
one less than the number of entries.
-
removeFirst()
- Removes the first element of the list.
-
removeLast()
- Removes the last element of the list
-
removeReference(Object)
- Removes the first element in the list identical to (==)
the given item.
-
removeRight(Dlink)
- Removes the Dlink to the right of the given link.
-
toString()
- Converts the Dlist to a string.
-
transform(UnaryFunction)
- Replaces each member of the list with the result of
applying the unary function to that memeber.
head_
protected Dlink head_
- Sentinel link pointing to first node
tail_
protected Dlink tail_
- Sentinel link positioned past last node
last_
protected Dlink last_
- reference to last node for convenience
Dlist
public Dlist()
- Creates an empty doubly-linked list
append
public synchronized Object append(Object item)
- Adds an element to the end of the list
- Returns:
- The new element
at
public synchronized Object at(int i)
- Returns the ith element of the list where
i is between 0 and
one less than the number of entries.
- Throws: DlistIndexOutOfBoundsException
- If i is not between 0 and
one less than the number of elements in the list
atPut
public synchronized Object atPut(int i,
Object item)
- Replaces the element at the given position
with the given item.
tt>i must be
between 0 and one less than the number of entries.
- Returns:
- The previous element at position i
- Throws: DlistIndexOutOfBoundsException
- If i is not between 0 and
one less than the number of elements in the list
bidirectionalElements
public synchronized BidirectionalEnumeration bidirectionalElements()
- Returns a bidirectional enumeration of the elements in the list.
Use the returned BidirectionalEnumeration
object to visit each of the
elements in turn, with the ability to move both forwards and
backwards through the list.
This method is identical to elements() except that
the return value does not have to be downcast from Enumeration
to BidirectionalEnumeration.
- See Also:
- elements
clear
public synchronized void clear()
- Removes all elements from the list.
- Overrides:
- clear in class CollectionBase
clone
public synchronized Object clone()
- Returns a clone of this Dlist. Note that the elements
themselves are not cloned.
- Overrides:
- clone in class Object
contains
public boolean contains(Object item)
- Returns true if the list contains an element equal to (equals())
the given item.
- Overrides:
- contains in class CollectionBase
containsReference
public boolean containsReference(Object item)
- Returns true if the list contains an element that
is identical to (==) the given item.
elements
public synchronized Enumeration elements()
- Returns an enumeration of the elements in the list. Use the returned
Enumeration object to visit each of the elements in turn.
This method is identical to bidirectionalElements() except
that the return value is of type Enumeration,
which must be downcast
to BidirectionalEnumeration in order to move both forwards and
backwards within the list.
- Returns:
- an enumerator that implements BidirectionalEnumeration
- Overrides:
- elements in class CollectionBase
- See Also:
- bidirectionalElements
find
public synchronized Object find(Object item)
- Returns the first element in the list equal to (equals())
the given item, or null if no such element is found.
- Overrides:
- find in class CollectionBase
first
public synchronized Object first()
- Returns the first element of the list.
- Throws: NoSuchElementException
- if the list is empty
index
public synchronized int index(Object item)
- Returns the position (from 0) of the first element in the list
equal to (equals()) the given item, or -1 if not found.
indexReference
public synchronized int indexReference(Object item)
- Returns the position (from 0) of the first element in the list
that is identical to (==) the given item, or -1 if not found.
insert
public synchronized Object insert(Object item)
- Adds the given item to the end of the list.
- Returns:
- The new element
- Overrides:
- insert in class CollectionBase
- See Also:
- append
insertAt
public synchronized Object insertAt(int i,
Object item)
- Adds the given item to the list in front of the element at
the given position. If i is equal to the
number of elements in the list,
then item will be added to the end of the list.
- Returns:
- The new element
- Throws: DlistIndexOutOfBoundsException
- If i is not between 0 and
the number of elements in the list
last
public synchronized Object last()
- Returns the last element of the list.
- Throws: NoSuchElementException
- if the list is empty
occurrencesOf
public synchronized int occurrencesOf(Object item)
- Returns the number of items in the list
equal to (equals()) the given item.
- Overrides:
- occurrencesOf in class CollectionBase
occurrencesOfReference
public synchronized int occurrencesOfReference(Object item)
- Returns the number of items in the list
identical to (==) the given item.
prepend
public synchronized Object prepend(Object item)
- Adds the given item to the beginning of the list.
- Returns:
- The new element
remove
public synchronized Object remove(Object item)
- Removes the first element in the list equal to (equals())
the given item.
- Returns:
- the element removed, or null if no such element
- Overrides:
- remove in class CollectionBase
removeReference
public synchronized Object removeReference(Object item)
- Removes the first element in the list identical to (==)
the given item.
- Returns:
- the element removed, or null if no such element
removeAll
public synchronized int removeAll(Object item)
- Removes all elements in the list equal to (equals())
the given item.
- Returns:
- The number of elements removed
- Overrides:
- removeAll in class CollectionBase
removeAllReference
public synchronized int removeAllReference(Object item)
- Removes all elements in the list identical to (==)
the given item.
- Returns:
- The number of elements removed
removeAt
public synchronized Object removeAt(int i)
- Removes the ith element of the list where
i is between 0 and
one less than the number of entries.
- Returns:
- The removed element
- Throws: DlistIndexOutOfBoundsException
- If i is not between 0 and
one less than the number of elements in the list
removeFirst
public synchronized Object removeFirst()
- Removes the first element of the list.
- Returns:
- The removed element
- Throws: NoSuchElementException
- if the list is empty
removeLast
public synchronized Object removeLast()
- Removes the last element of the list
- Returns:
- The removed element
- Throws: NoSuchElementException
- if the list is empty
toString
public synchronized String toString()
- Converts the Dlist to a string. The string will have the form
"[elem1, elem2, elem3, ..., elemN]"
An empty list returns the string "[]".
- Overrides:
- toString in class Object
transform
public synchronized void transform(UnaryFunction fun)
- Replaces each member of the list with the result of
applying the unary function to that memeber.
init
protected void init()
- Initializes member data as appropriate for an empty list.
removeRight
protected Dlink removeRight(Dlink link)
- Removes the Dlink to the right of the given link. It is an
error if link is the last link.
All Packages Class Hierarchy This Package Previous Next Index