org.javagroups.util
Class List
java.lang.Object
|
+--org.javagroups.util.List
- All Implemented Interfaces:
- java.lang.Cloneable, java.io.Externalizable, java.io.Serializable
- Direct Known Subclasses:
- Stack
- public class List
- extends java.lang.Object
- implements java.io.Externalizable, java.lang.Cloneable
Doubly-linked list. Elements can be added at head or tail and removed from head/tail.
This class is tuned for element access at either head or tail, random access to elements
is not very fast; in this case use Vector. Concurrent access is supported: a thread is blocked
while another thread adds/removes an object. When no objects are available, removal returns null.
- See Also:
- Serialized Form
Field Summary |
protected org.javagroups.util.List.Element |
head
|
protected java.lang.Object |
mutex
|
protected int |
size
|
protected org.javagroups.util.List.Element |
tail
|
Constructor Summary |
List()
|
Method Summary |
void |
add(java.lang.Object obj)
Adds an object at the tail of the list. |
void |
addAtHead(java.lang.Object obj)
Adds an object at the head of the list. |
protected java.lang.Object |
clone()
|
boolean |
contains(java.lang.Object obj)
|
List |
copy()
|
java.lang.String |
dump()
|
java.util.Enumeration |
elements()
|
java.util.Vector |
getContents()
|
static void |
main(java.lang.String[] args)
|
java.lang.Object |
peek()
Returns element at the tail (if present), but does not remove it from list. |
java.lang.Object |
peekAtHead()
Returns element at the head (if present), but does not remove it from list. |
void |
readExternal(java.io.ObjectInput in)
|
java.lang.Object |
remove()
Removes an object from the tail of the list. |
void |
removeAll()
|
java.lang.Object |
removeElement(java.lang.Object obj)
Removes element obj from the list, checking for equality using the equals
operator. |
java.lang.Object |
removeFromHead()
Removes an object from the head of the list. |
int |
size()
|
java.lang.String |
toString()
|
void |
writeExternal(java.io.ObjectOutput out)
|
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
head
protected org.javagroups.util.List.Element head
tail
protected org.javagroups.util.List.Element tail
size
protected int size
mutex
protected java.lang.Object mutex
List
public List()
add
public void add(java.lang.Object obj)
- Adds an object at the tail of the list.
addAtHead
public void addAtHead(java.lang.Object obj)
- Adds an object at the head of the list.
remove
public java.lang.Object remove()
- Removes an object from the tail of the list. Returns null if no elements available
removeFromHead
public java.lang.Object removeFromHead()
- Removes an object from the head of the list. Returns null if no elements available
peek
public java.lang.Object peek()
- Returns element at the tail (if present), but does not remove it from list.
peekAtHead
public java.lang.Object peekAtHead()
- Returns element at the head (if present), but does not remove it from list.
removeElement
public java.lang.Object removeElement(java.lang.Object obj)
- Removes element
obj
from the list, checking for equality using the equals
operator. Only the first duplicate object is removed. Returns the removed object.
removeAll
public void removeAll()
size
public int size()
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
dump
public java.lang.String dump()
getContents
public java.util.Vector getContents()
elements
public java.util.Enumeration elements()
contains
public boolean contains(java.lang.Object obj)
copy
public List copy()
clone
protected java.lang.Object clone()
- Overrides:
clone
in class java.lang.Object
writeExternal
public void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
- Specified by:
writeExternal
in interface java.io.Externalizable
readExternal
public void readExternal(java.io.ObjectInput in)
throws java.io.IOException,
java.lang.ClassNotFoundException
- Specified by:
readExternal
in interface java.io.Externalizable
main
public static void main(java.lang.String[] args)
Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.