All Packages Class Hierarchy This Package Previous Next Index
Class com.roguewave.tools.v2-0.Slist
java.lang.Object
|
+----com.roguewave.tools.v2-0.CollectionBase
|
+----com.roguewave.tools.v2-0.Slist
- public class Slist
- extends CollectionBase
- implements Sequence, Cloneable, Serializable
Class Slist implements a singly-linked list of elements ordered
externally by the client of the class. Duplicate entries are allowed.
Items can be inserted efficiently at 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 mean 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 efficient access to the end of the list
-
tail_
- Sentinel link positioned just past the last node
-
Slist()
- Creates an empty singly-linked list.
-
append(Object)
- Adds an item 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.
-
clear()
- Removes all elements from the list.
-
clone()
- Returns a clone of this Slist.
-
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 an 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()) item.
-
occurrencesOfReference(Object)
- Returns the number of items in the list
identical to (==) the given item.
-
prepend(Object)
- Adds an 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(Slink)
-
-
toString()
- Converts this Slist to a string.
-
transform(UnaryFunction)
- Replaces each member of the collection with the result of
applying the unary function to that memeber.
head_
protected Slink head_
- Sentinel link pointing to first node
tail_
protected Slink tail_
- Sentinel link positioned just past the last node
last_
protected Slink last_
- reference to last node for efficient access to the end of the list
Slist
public Slist()
- Creates an empty singly-linked list.
append
public synchronized Object append(Object item)
- Adds an item 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: SlistIndexOutOfBoundsException
- 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.
i must be
between 0 and one less than the number of entries.
- Returns:
- The previous element at position i
- Throws: SlistIndexOutOfBoundsException
- If i is not between 0 and
one less than the number of elements in the list
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 Slist. 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.
- Overrides:
- elements in class CollectionBase
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 an 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 the new object will be added to the end of the list.
- Returns:
- The new element
- Throws: SlistIndexOutOfBoundsException
- 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()) 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 an 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: SlistIndexOutOfBoundsException
- 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 this Slist 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 collection 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 Slink removeRight(Slink link)
All Packages Class Hierarchy This Package Previous Next Index