public class LinkedList<T extends LinkedListNode<T>> extends Object implements Externalizable
so that it references
the node before and after it. This way a node can be removed without having to scan the list to find it. This class
does not provide an Iterator implementation as its designed for efficiency and not genericity. There are a number of
ways to iterate the list.
Simple iterator:
for ( LinkedListNode node = list.getFirst(); node != null; node = node.remove() ) {
}
Iterator that pops the first entry:
for ( LinkedListNode node = list.removeFirst(); node != null; node = list.removeFirst() ) {
}
Modifier and Type | Class and Description |
---|---|
static class |
LinkedList.JavaUtilIterator<T extends LinkedListNode<T>> |
static class |
LinkedList.LinkedListFastIterator |
static class |
LinkedList.LinkedListIterator<T extends LinkedListNode<T>>
Returns a list iterator
|
Modifier and Type | Field and Description |
---|---|
static FastIterator |
fastIterator |
Constructor and Description |
---|
LinkedList()
Construct an empty
LinkedList |
LinkedList(T node) |
Modifier and Type | Method and Description |
---|---|
void |
add(T node)
Add a
LinkedListNode to the list. |
void |
addFirst(T node) |
void |
addLast(T node)
Add a
LinkedListNode to the end of the list. |
void |
clear()
Iterates the list removing all the nodes until there are no more nodes to remove.
|
boolean |
contains(T node) |
boolean |
equals(Object object) |
FastIterator |
fastIterator() |
T |
get(int i) |
T |
getFirst()
Return the first node in the list
|
T |
getLast()
Return the last node in the list
|
int |
hashCode() |
void |
insertAfter(T existingNode,
T newNode) |
boolean |
isEmpty() |
FastIterator |
iterator() |
Iterator<T> |
javaUtilIterator() |
void |
readExternal(ObjectInput in) |
void |
remove(T node)
Removes a
LinkedListNode from the list. |
T |
removeFirst()
Remove the first node from the list.
|
T |
removeLast()
Remove the last node from the list.
|
int |
size() |
void |
writeExternal(ObjectOutput out) |
public static final FastIterator fastIterator
public LinkedList()
LinkedList
public LinkedList(T node)
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void add(T node)
LinkedListNode
to the list. If the LinkedList
is empty then the first and
last nodes are set to the added node.node
- The LinkedListNode
to be addedpublic void addLast(T node)
LinkedListNode
to the end of the list. If the LinkedList
is empty then the first and
last nodes are set to the added node.node
- The LinkedListNode
to be addedpublic void addFirst(T node)
public void remove(T node)
LinkedListNode
from the list. This works by attach the previous reference to the child reference.
When the node to be removed is the first node it calls removeFirst()
. When the node to be removed is the last node
it calls removeLast()
.node
- The LinkedListNode
to be removed.public boolean contains(T node)
public final T getFirst()
LinkedListNode
.public final T getLast()
LinkedListNode
.public T removeFirst()
LinkedListNode
.public T removeLast()
LinkedListNode
.public T get(int i)
public final boolean isEmpty()
public void clear()
public final int size()
public FastIterator iterator()
public FastIterator fastIterator()
Copyright © 2001–2019 JBoss by Red Hat. All rights reserved.