public class TLinkedList
extends java.util.AbstractSequentialList
implements java.io.Serializable
Using this implementation allows you to get java.util.LinkedList behavior (a doubly linked list, with Iterators that support insert and delete operations) without incurring the overhead of creating Node wrapper objects for every element in your list.
The requirement to achieve this time/space gain is that the Objects stored in the List implement the TLinkable interface.
The limitations are that you cannot put the same object into more than one list or more than once in the same list. You must also ensure that you only remove objects that are actually in the list. That is, if you have an object A and lists l1 and l2, you must ensure that you invoke List.remove(A) on the correct list. It is also forbidden to invoke List.remove() with an unaffiliated TLinkable (one that belongs to no list): this will destroy the list you invoke it on.
Created: Sat Nov 10 15:25:10 2001
TLinkable,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
protected class |
TLinkedList.IteratorImpl
A ListIterator that supports additions and deletions.
|
| Modifier and Type | Field and Description |
|---|---|
protected TLinkable |
_head
the head of the list
|
protected int |
_size
the number of elements in the list
|
protected TLinkable |
_tail
the tail of the list
|
| Constructor and Description |
|---|
TLinkedList()
Creates a new
TLinkedList instance. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
java.lang.Object linkable)
Inserts linkable at index index in the list.
|
boolean |
add(java.lang.Object linkable)
Appends linkable to the end of the list.
|
void |
addBefore(TLinkable current,
TLinkable newElement)
Inserts newElement into the list immediately before current.
|
void |
addFirst(java.lang.Object linkable)
Inserts linkable at the head of the list.
|
void |
addLast(java.lang.Object linkable)
Adds linkable to the end of the list.
|
void |
clear()
Empties the list.
|
boolean |
contains(java.lang.Object o)
A linear search for o in the list.
|
java.lang.Object |
getFirst()
Returns the head of the list
|
java.lang.Object |
getLast()
Returns the tail of the list.
|
protected void |
insert(int index,
java.lang.Object linkable)
Implementation of index-based list insertions.
|
java.util.ListIterator |
listIterator(int index)
Returns an iterator positioned at index.
|
boolean |
remove(java.lang.Object o)
Removes the specified element from the list.
|
java.lang.Object |
removeFirst()
Remove and return the first element in the list.
|
java.lang.Object |
removeLast()
Remove and return the last element in the list.
|
int |
size()
Returns the number of elements in the list.
|
java.lang.Object[] |
toArray()
Copies the list's contents into a native array.
|
java.lang.Object[] |
toUnlinkedArray()
Copies the list to a native array, destroying the next/previous
links as the copy is made.
|
equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subListaddAll, containsAll, isEmpty, removeAll, retainAll, toArray, toStringprotected TLinkable _head
protected TLinkable _tail
protected int _size
public java.util.ListIterator listIterator(int index)
listIterator in interface java.util.ListlistIterator in class java.util.AbstractSequentialListindex - an int valueListIterator valuepublic int size()
size in interface java.util.Collectionsize in interface java.util.Listsize in class java.util.AbstractCollectionint valuepublic void add(int index,
java.lang.Object linkable)
add in interface java.util.Listadd in class java.util.AbstractSequentialListindex - an int valuelinkable - an object of type TLinkablepublic boolean add(java.lang.Object linkable)
add in interface java.util.Collectionadd in interface java.util.Listadd in class java.util.AbstractListlinkable - an object of type TLinkablepublic void addFirst(java.lang.Object linkable)
linkable - an object of type TLinkablepublic void addLast(java.lang.Object linkable)
linkable - an object of type TLinkablepublic void clear()
clear in interface java.util.Collectionclear in interface java.util.Listclear in class java.util.AbstractListpublic java.lang.Object[] toArray()
toArray in interface java.util.CollectiontoArray in interface java.util.ListtoArray in class java.util.AbstractCollectionObject[] valuepublic java.lang.Object[] toUnlinkedArray()
Object[] valuepublic boolean contains(java.lang.Object o)
contains in interface java.util.Collectioncontains in interface java.util.Listcontains in class java.util.AbstractCollectiono - an Object valueboolean valuepublic java.lang.Object getFirst()
Object valuepublic java.lang.Object getLast()
Object valuepublic java.lang.Object removeFirst()
Object valuepublic java.lang.Object removeLast()
Object valueprotected void insert(int index,
java.lang.Object linkable)
index - an int valuelinkable - an object of type TLinkablepublic boolean remove(java.lang.Object o)
remove in interface java.util.Collectionremove in interface java.util.Listremove in class java.util.AbstractCollectiono - a TLinkable element already inserted in this list.public void addBefore(TLinkable current, TLinkable newElement)
current - a TLinkable value currently in the list.newElement - a TLinkable value to be added to
the list.