com.sleepycat.collections
Class StoredList<E>

java.lang.Object
  extended by com.sleepycat.collections.StoredContainer
      extended by com.sleepycat.collections.StoredCollection<E>
          extended by com.sleepycat.collections.StoredList<E>
All Implemented Interfaces:
Cloneable, Iterable<E>, Collection<E>, List<E>

public class StoredList<E>
extends StoredCollection<E>
implements List<E>

Author:
Mark Hayes

Field Summary
 
Fields inherited from class com.sleepycat.collections.StoredCollection
DEFAULT_ITERATOR_BLOCK_SIZE
 
Fields inherited from class com.sleepycat.collections.StoredContainer
view
 
Constructor Summary
StoredList(Database database, EntityBinding<E> valueEntityBinding, boolean writeAllowed)
          Creates a list entity view of a Database.
StoredList(Database database, EntityBinding<E> valueEntityBinding, PrimaryKeyAssigner keyAssigner)
          Creates a list entity view of a Database with a PrimaryKeyAssigner.
StoredList(Database database, EntryBinding<E> valueBinding, boolean writeAllowed)
          Creates a list view of a Database.
StoredList(Database database, EntryBinding<E> valueBinding, PrimaryKeyAssigner keyAssigner)
          Creates a list view of a Database with a PrimaryKeyAssigner.
 
Method Summary
 boolean add(E value)
          Appends the specified element to the end of this list (optional operation).
 void add(int index, E value)
          Inserts the specified element at the specified position in this list (optional operation).
 boolean addAll(int index, Collection<? extends E> coll)
          Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
 int append(E value)
          Appends a given value returning the newly assigned index.
(package private)  void checkIterAddAllowed()
           
 boolean contains(Object value)
          Returns true if this list contains the specified element.
 boolean equals(Object other)
          Compares the specified object with this list for equality.
 E get(int index)
          Returns the element at the specified position in this list.
(package private)  int getIndexOffset()
           
 int hashCode()
           
(package private)  boolean hasValues()
           
 int indexOf(Object value)
          Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
 int lastIndexOf(Object value)
          Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
 ListIterator<E> listIterator()
          Returns a list iterator of the elements in this list (in proper sequence).
 ListIterator<E> listIterator(int index)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
(package private)  E makeIteratorData(BaseIterator iterator, DatabaseEntry keyEntry, DatabaseEntry priKeyEntry, DatabaseEntry valueEntry)
           
 E remove(int index)
          Removes the element at the specified position in this list (optional operation).
 boolean remove(Object value)
          Removes the first occurrence in this list of the specified element (optional operation).
 E set(int index, E value)
          Replaces the element at the specified position in this list with the specified element (optional operation).
(package private)  ListIterator storedOrExternalListIterator(List list)
          Returns a StoredIterator if the given collection is a StoredCollection, else returns a regular/external ListIterator.
 List<E> subList(int fromIndex, int toIndex)
          Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
 
Methods inherited from class com.sleepycat.collections.StoredCollection
add, addAll, blockIterator, containsAll, getFirstOrLast, getIteratorBlockSize, iterateDuplicates, iterator, iterator, join, makeIteratorData, removeAll, retainAll, setIteratorBlockSize, size, storedIterator, storedIterator, toArray, toArray, toList, toString
 
Methods inherited from class com.sleepycat.collections.StoredContainer
areDuplicatesAllowed, areDuplicatesOrdered, areKeyRangesAllowed, areKeysRenumbered, beginAutoCommit, clear, closeCursor, commitAutoCommit, configuredClone, containsKey, containsValue, convertException, getCursorConfig, getValue, handleException, initAfterClone, isEmpty, isOrdered, isSecondary, isTransactional, isWriteAllowed, putKeyValue, removeKey, removeValue, storedOrExternalIterator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, clear, containsAll, isEmpty, iterator, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

StoredList

public StoredList(Database database,
                  EntryBinding<E> valueBinding,
                  boolean writeAllowed)
Creates a list view of a Database.

Parameters:
database - is the Database underlying the new collection.
valueBinding - is the binding used to translate between value buffers and value objects.
writeAllowed - is true to create a read-write collection or false to create a read-only collection.
Throws:
IllegalArgumentException - if formats are not consistently defined or a parameter is invalid.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

StoredList

public StoredList(Database database,
                  EntityBinding<E> valueEntityBinding,
                  boolean writeAllowed)
Creates a list entity view of a Database.

Parameters:
database - is the Database underlying the new collection.
valueEntityBinding - is the binding used to translate between key/value buffers and entity value objects.
writeAllowed - is true to create a read-write collection or false to create a read-only collection.
Throws:
IllegalArgumentException - if formats are not consistently defined or a parameter is invalid.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

StoredList

public StoredList(Database database,
                  EntryBinding<E> valueBinding,
                  PrimaryKeyAssigner keyAssigner)
Creates a list view of a Database with a PrimaryKeyAssigner. Writing is allowed for the created list.

Parameters:
database - is the Database underlying the new collection.
valueBinding - is the binding used to translate between value buffers and value objects.
keyAssigner - is used by the add(int, E) and append(E) methods to assign primary keys.
Throws:
IllegalArgumentException - if formats are not consistently defined or a parameter is invalid.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

StoredList

public StoredList(Database database,
                  EntityBinding<E> valueEntityBinding,
                  PrimaryKeyAssigner keyAssigner)
Creates a list entity view of a Database with a PrimaryKeyAssigner. Writing is allowed for the created list.

Parameters:
database - is the Database underlying the new collection.
valueEntityBinding - is the binding used to translate between key/value buffers and entity value objects.
keyAssigner - is used by the add(int, E) and append(E) methods to assign primary keys.
Throws:
IllegalArgumentException - if formats are not consistently defined or a parameter is invalid.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).
Method Detail

add

public void add(int index,
                E value)
Inserts the specified element at the specified position in this list (optional operation). This method conforms to the List.add(int, Object) interface.

Specified by:
add in interface List<E>
Throws:
OperationFailureException - if one of the Write Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
UnsupportedOperationException - if the collection is a sublist, or if the collection is indexed, or if the collection is read-only, or if the RECNO-RENUMBER access method was not used.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

add

public boolean add(E value)
Appends the specified element to the end of this list (optional operation). This method conforms to the List.add(Object) interface.

Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>
Throws:
OperationFailureException - if one of the Write Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
UnsupportedOperationException - if the collection is a sublist, or if the collection is indexed, or if the collection is read-only, or if the RECNO-RENUMBER access method was not used.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

append

public int append(E value)
Appends a given value returning the newly assigned index. If a PrimaryKeyAssigner is associated with Store for this list, it will be used to assigned the returned index. Otherwise the Store must be a QUEUE or RECNO database and the next available record number is assigned as the index. This method does not exist in the standard List interface.

Parameters:
value - the value to be appended.
Returns:
the assigned index.
Throws:
OperationFailureException - if one of the Write Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
UnsupportedOperationException - if the collection is indexed, or if the collection is read-only, or if the Store has no PrimaryKeyAssigner and is not a QUEUE or RECNO database.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

checkIterAddAllowed

void checkIterAddAllowed()
                   throws UnsupportedOperationException
Overrides:
checkIterAddAllowed in class StoredCollection<E>
Throws:
UnsupportedOperationException

addAll

public boolean addAll(int index,
                      Collection<? extends E> coll)
Inserts all of the elements in the specified collection into this list at the specified position (optional operation). This method conforms to the List.addAll(int, Collection) interface.

Specified by:
addAll in interface List<E>
Throws:
OperationFailureException - if one of the Write Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
UnsupportedOperationException - if the collection is a sublist, or if the collection is indexed, or if the collection is read-only, or if the RECNO-RENUMBER access method was not used.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

contains

public boolean contains(Object value)
Returns true if this list contains the specified element. This method conforms to the List.contains(java.lang.Object) interface.

Specified by:
contains in interface Collection<E>
Specified by:
contains in interface List<E>
Throws:
OperationFailureException - if one of the Read Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

get

public E get(int index)
Returns the element at the specified position in this list. This method conforms to the List.get(int) interface.

Specified by:
get in interface List<E>
Throws:
OperationFailureException - if one of the Read Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

indexOf

public int indexOf(Object value)
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. This method conforms to the List.indexOf(java.lang.Object) interface.

Specified by:
indexOf in interface List<E>
Throws:
OperationFailureException - if one of the Read Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

lastIndexOf

public int lastIndexOf(Object value)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element. This method conforms to the List.lastIndexOf(java.lang.Object) interface.

Specified by:
lastIndexOf in interface List<E>
Throws:
OperationFailureException - if one of the Read Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

getIndexOffset

int getIndexOffset()
Overrides:
getIndexOffset in class StoredCollection<E>

listIterator

public ListIterator<E> listIterator()
Returns a list iterator of the elements in this list (in proper sequence). The iterator will be read-only if the collection is read-only. This method conforms to the List.listIterator() interface.

For information on cursor stability and iterator block size, see StoredCollection.iterator().

Specified by:
listIterator in interface List<E>
Returns:
a ListIterator for this collection.
Throws:
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).
See Also:
StoredContainer.isWriteAllowed()

listIterator

public ListIterator<E> listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list. The iterator will be read-only if the collection is read-only. This method conforms to the List.listIterator(int) interface.

For information on cursor stability and iterator block size, see StoredCollection.iterator().

Specified by:
listIterator in interface List<E>
Returns:
a ListIterator for this collection.
Throws:
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).
See Also:
StoredContainer.isWriteAllowed()

remove

public E remove(int index)
Removes the element at the specified position in this list (optional operation). This method conforms to the List.remove(int) interface.

Specified by:
remove in interface List<E>
Throws:
OperationFailureException - if one of the Write Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
UnsupportedOperationException - if the collection is a sublist, or if the collection is read-only.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

remove

public boolean remove(Object value)
Removes the first occurrence in this list of the specified element (optional operation). This method conforms to the List.remove(Object) interface.

Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>
Throws:
OperationFailureException - if one of the Write Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
UnsupportedOperationException - if the collection is a sublist, or if the collection is read-only.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

set

public E set(int index,
             E value)
Replaces the element at the specified position in this list with the specified element (optional operation). This method conforms to the List.set(int, E) interface.

Specified by:
set in interface List<E>
Throws:
OperationFailureException - if one of the Write Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
UnsupportedOperationException - if the collection is indexed, or if the collection is read-only.
IllegalArgumentException - if an entity value binding is used and the primary key of the value given is different than the existing stored primary key.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

subList

public List<E> subList(int fromIndex,
                       int toIndex)
Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. Note that add() and remove() may not be called for the returned sublist. This method conforms to the List.subList(int, int) interface.

Specified by:
subList in interface List<E>
Throws:
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

equals

public boolean equals(Object other)
Compares the specified object with this list for equality. A value comparison is performed by this method and the stored values are compared rather than calling the equals() method of each element. This method conforms to the List.equals(java.lang.Object) interface.

Specified by:
equals in interface Collection<E>
Specified by:
equals in interface List<E>
Overrides:
equals in class StoredCollection<E>
Throws:
OperationFailureException - if one of the Read Operation Failures occurs.
EnvironmentFailureException - if an unexpected, internal or environment-wide failure occurs.
RuntimeExceptionWrapper - if a checked exception is thrown, including a DatabaseException on BDB (C Edition).

storedOrExternalListIterator

final ListIterator storedOrExternalListIterator(List list)
Returns a StoredIterator if the given collection is a StoredCollection, else returns a regular/external ListIterator. The iterator returned should be closed with the static method StoredIterator.close(Iterator).


hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<E>
Specified by:
hashCode in interface List<E>
Overrides:
hashCode in class StoredCollection<E>

makeIteratorData

E makeIteratorData(BaseIterator iterator,
                   DatabaseEntry keyEntry,
                   DatabaseEntry priKeyEntry,
                   DatabaseEntry valueEntry)
Specified by:
makeIteratorData in class StoredCollection<E>

hasValues

boolean hasValues()
Specified by:
hasValues in class StoredCollection<E>


Copyright (c) 2004-2010 Oracle. All rights reserved.