org.ozoneDB.collections
Class FullLinkedListImpl

java.lang.Object
  extended byorg.ozoneDB.OzoneObject
      extended byorg.ozoneDB.collections.AbstractOzoneCollection
          extended byorg.ozoneDB.collections.BaseListImpl
              extended byorg.ozoneDB.collections.FullLinkedListImpl
All Implemented Interfaces:
BaseList, java.util.Collection, FullLinkedList, java.util.List, OzoneCollection, org.ozoneDB.OzoneCompatible, org.ozoneDB.OzoneCompatibleOrProxy, OzoneList, org.ozoneDB.OzoneRemote, java.io.Serializable

public class FullLinkedListImpl
extends BaseListImpl
implements FullLinkedList

Linked list implementation of the List interface. In addition to the methods of the List interface, this class provides access to the first and last list elements in O(1) time for easy stack, queue, or double-ended queue (deque) creation. The list is doubly-linked, with traversal to a given index starting from the end closest to the element.

LinkedList is not synchronized, so if you need multi-threaded access, consider using:
List l = Collections.synchronizedList(new LinkedList(...));

The iterators are fail-fast, meaning that any structural modification, except for remove() called on the iterator itself, cause the iterator to throw a ConcurrentModificationException rather than exhibit non-deterministic behavior.

Since:
1.2
Author:
Original author unknown, Bryce McKinlay, Eric Blake
See Also:
List, ArrayList, Vector, Collections.synchronizedList(java.util.List), Serialized Form

Field Summary
 
Fields inherited from class org.ozoneDB.collections.BaseListImpl
modCount
 
Constructor Summary
FullLinkedListImpl()
          Create an empty linked list.
FullLinkedListImpl(java.util.Collection c)
          Create a linked list containing the elements, in order, of a given collection.
 
Method Summary
 java.util.List _org_ozoneDB_emptyClientCollection()
          Needed for sub lists so that they can return the same type of list as the sub lists backing list would when getClientXxx() is called.
 int _org_ozoneDB_getModCount()
           
 java.util.Iterator _org_ozoneDB_internalIterator()
           
 void add(int index, java.lang.Object o)
          Inserts an element in the given position in the list.
 boolean add(java.lang.Object o)
          Adds an element to the end of the list.
 boolean addAll(java.util.Collection c)
          Append the elements of the collection in iteration order to the end of this list.
 boolean addAll(int index, java.util.Collection c)
          Insert the elements of the collection in iteration order at the given index of this list.
 void addFirst(java.lang.Object o)
          Insert an element at the first of the list.
 void addLast(java.lang.Object o)
          Insert an element at the last of the list.
 void clear()
          Remove all elements from this list.
 java.lang.Object clone()
          Create a shallow copy of this LinkedList (the elements are not cloned).
 boolean contains(java.lang.Object o)
          Returns true if the list contains the given object.
 java.lang.Object get(int index)
          Return the element at index.
 java.lang.Object getFirst()
          Returns the first element in the list.
 java.lang.Object getLast()
          Returns the last element in the list.
 int indexOf(java.lang.Object o)
          Returns the first index where the element is located in the list, or -1.
 int lastIndexOf(java.lang.Object o)
          Returns the last index where the element is located in the list, or -1.
 java.util.ListIterator listIterator(int index)
          Obtain a ListIterator over this list, starting at a given index.
 java.lang.Object remove(int index)
          Removes the element at the given position from the list.
 boolean remove(java.lang.Object o)
          Removes the entry at the lowest index in the list that matches the given object, comparing by o == null ?
 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.
 java.lang.Object set(int index, java.lang.Object o)
          Replace the element at the given location in the list.
 int size()
          Returns the size of the list.
 java.lang.Object[] toArray()
          Returns an array which contains the elements of the list in order.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Returns an Array whose component type is the runtime component type of the passed-in Array.
 
Methods inherited from class org.ozoneDB.collections.BaseListImpl
_org_ozoneDB_removeRange, equals, getClientList, hashCode, internalIterator, iterator, listIterator, subList
 
Methods inherited from class org.ozoneDB.collections.AbstractOzoneCollection
containsAll, getClientCollection, isEmpty, removeAll, retainAll, toString
 
Methods inherited from class org.ozoneDB.OzoneObject
container, database, deleteRecursive, getHandle, getObjectID, handle, onActivate, onCreate, onDelete, onPassivate, requireWriteLocking, self, setContainer, toXML
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ozoneDB.collections.BaseList
_org_ozoneDB_removeRange
 
Methods inherited from interface org.ozoneDB.collections.OzoneList
getClientList
 
Methods inherited from interface org.ozoneDB.collections.OzoneCollection
getClientCollection, removeAll, retainAll
 
Methods inherited from interface java.util.Collection
containsAll, equals, hashCode, isEmpty, iterator
 
Methods inherited from interface org.ozoneDB.OzoneCompatibleOrProxy
getObjectID
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

FullLinkedListImpl

public FullLinkedListImpl()
Create an empty linked list.


FullLinkedListImpl

public FullLinkedListImpl(java.util.Collection c)
Create a linked list containing the elements, in order, of a given collection.

Parameters:
c - the collection to populate this list from
Throws:
java.lang.NullPointerException - if c is null
Method Detail

getFirst

public java.lang.Object getFirst()
Returns the first element in the list.

Returns:
the first list element
Throws:
java.util.NoSuchElementException - if the list is empty

getLast

public java.lang.Object getLast()
Returns the last element in the list.

Returns:
the last list element
Throws:
java.util.NoSuchElementException - if the list is empty

removeFirst

public java.lang.Object removeFirst()
Remove and return the first element in the list.

Returns:
the former first element in the list
Throws:
java.util.NoSuchElementException - if the list is empty

removeLast

public java.lang.Object removeLast()
Remove and return the last element in the list.

Returns:
the former last element in the list
Throws:
java.util.NoSuchElementException - if the list is empty

addFirst

public void addFirst(java.lang.Object o)
Insert an element at the first of the list.

Parameters:
o - the element to insert

addLast

public void addLast(java.lang.Object o)
Insert an element at the last of the list.

Parameters:
o - the element to insert

contains

public boolean contains(java.lang.Object o)
Returns true if the list contains the given object. Comparison is done by o == null ? e = null : o.equals(e).

Specified by:
contains in interface java.util.Collection
Overrides:
contains in class AbstractOzoneCollection
Parameters:
o - the element to look for
Returns:
true if it is found

size

public int size()
Returns the size of the list.

Specified by:
size in interface java.util.Collection
Specified by:
size in class AbstractOzoneCollection
Returns:
the list size

add

public boolean add(java.lang.Object o)
Adds an element to the end of the list.

Specified by:
add in interface OzoneCollection
Overrides:
add in class BaseListImpl
Parameters:
o - the entry to add
Returns:
true, as it always succeeds
See Also:
BaseListImpl.add(int, Object)

remove

public boolean remove(java.lang.Object o)
Removes the entry at the lowest index in the list that matches the given object, comparing by o == null ? e = null : o.equals(e).

Specified by:
remove in interface OzoneCollection
Overrides:
remove in class AbstractOzoneCollection
Parameters:
o - the object to remove
Returns:
true if an instance of the object was removed
See Also:
Iterator.remove()

addAll

public boolean addAll(java.util.Collection c)
Append the elements of the collection in iteration order to the end of this list. If this list is modified externally (for example, if this list is the collection), behavior is unspecified.

Specified by:
addAll in interface OzoneCollection
Overrides:
addAll in class AbstractOzoneCollection
Parameters:
c - the collection to append
Returns:
true if the list was modified
Throws:
java.lang.NullPointerException - if c is null
See Also:
AbstractOzoneCollection.add(Object)

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Insert the elements of the collection in iteration order at the given index of this list. If this list is modified externally (for example, if this list is the collection), behavior is unspecified.

Specified by:
addAll in interface OzoneList
Overrides:
addAll in class BaseListImpl
Parameters:
c - the collection to append
Returns:
true if the list was modified
Throws:
java.lang.NullPointerException - if c is null
java.lang.IndexOutOfBoundsException - if index < 0 || index > size()

clear

public void clear()
Remove all elements from this list.

Specified by:
clear in interface OzoneCollection
Overrides:
clear in class BaseListImpl
See Also:
BaseListImpl.remove(int), BaseListImpl._org_ozoneDB_removeRange(int, int)

get

public java.lang.Object get(int index)
Return the element at index.

Specified by:
get in interface java.util.List
Parameters:
index - the place to look
Returns:
the element at index
Throws:
java.lang.IndexOutOfBoundsException - if index < 0 || index >= size()

set

public java.lang.Object set(int index,
                            java.lang.Object o)
Replace the element at the given location in the list.

Specified by:
set in interface OzoneList
Overrides:
set in class BaseListImpl
Parameters:
index - which index to change
o - the new element
Returns:
the prior element
Throws:
java.lang.IndexOutOfBoundsException - if index < 0 || index >= size()

add

public void add(int index,
                java.lang.Object o)
Inserts an element in the given position in the list.

Specified by:
add in interface OzoneList
Overrides:
add in class BaseListImpl
Parameters:
index - where to insert the element
o - the element to insert
Throws:
java.lang.IndexOutOfBoundsException - if index < 0 || index > size()

remove

public java.lang.Object remove(int index)
Removes the element at the given position from the list.

Specified by:
remove in interface OzoneList
Overrides:
remove in class BaseListImpl
Parameters:
index - the location of the element to remove
Returns:
the removed element
Throws:
java.lang.IndexOutOfBoundsException - if index < 0 || index > size()
See Also:
BaseListImpl.modCount

indexOf

public int indexOf(java.lang.Object o)
Returns the first index where the element is located in the list, or -1.

Specified by:
indexOf in interface java.util.List
Overrides:
indexOf in class BaseListImpl
Parameters:
o - the element to look for
Returns:
its position, or -1 if not found

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Returns the last index where the element is located in the list, or -1.

Specified by:
lastIndexOf in interface java.util.List
Overrides:
lastIndexOf in class BaseListImpl
Parameters:
o - the element to look for
Returns:
its position, or -1 if not found

_org_ozoneDB_internalIterator

public java.util.Iterator _org_ozoneDB_internalIterator()
Specified by:
_org_ozoneDB_internalIterator in interface OzoneCollection

listIterator

public java.util.ListIterator listIterator(int index)
Obtain a ListIterator over this list, starting at a given index. The ListIterator returned by this method supports the add, remove and set methods.

Specified by:
listIterator in interface java.util.List
Overrides:
listIterator in class BaseListImpl
Parameters:
index - the index of the element to be returned by the first call to next(), or size() to be initially positioned at the end of the list
Returns:
a ListIterator over the elements of this list, in order, starting at index
Throws:
java.lang.IndexOutOfBoundsException - if index < 0 || index > size()
See Also:
BaseListImpl.modCount

clone

public java.lang.Object clone()
Create a shallow copy of this LinkedList (the elements are not cloned).

Returns:
an object of the same class as this object, containing the same elements in the same order

toArray

public java.lang.Object[] toArray()
Returns an array which contains the elements of the list in order.

Specified by:
toArray in interface java.util.Collection
Overrides:
toArray in class AbstractOzoneCollection
Returns:
an array containing the list elements

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Returns an Array whose component type is the runtime component type of the passed-in Array. The returned Array is populated with all of the elements in this LinkedList. If the passed-in Array is not large enough to store all of the elements in this List, a new Array will be created and returned; if the passed-in Array is larger than the size of this List, then size() index will be set to null.

Specified by:
toArray in interface java.util.Collection
Overrides:
toArray in class AbstractOzoneCollection
Parameters:
a - the passed-in Array
Returns:
an array representation of this list
Throws:
java.lang.ArrayStoreException - if the runtime type of a does not allow an element in this list
java.lang.NullPointerException - if a is null

_org_ozoneDB_getModCount

public int _org_ozoneDB_getModCount()
Specified by:
_org_ozoneDB_getModCount in interface BaseList

_org_ozoneDB_emptyClientCollection

public java.util.List _org_ozoneDB_emptyClientCollection()
Description copied from interface: BaseList
Needed for sub lists so that they can return the same type of list as the sub lists backing list would when getClientXxx() is called.

Specified by:
_org_ozoneDB_emptyClientCollection in interface BaseList
Returns:
empty list, to be filled and returned to client via getClientXxx()


Copyright © 2004 The Ozone Database Project - www.ozone-db.org. All Rights Reserved.