|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.garret.consus.Persistent org.garret.consus.POCollection org.garret.consus.POList
Resizable-array implementation of the List interface. Implements all optional list operations and permits all elements, including null. In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list. (This class is roughly equivalent to Vector, except that it is unsynchronized.)
The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that of the LinkedList implementation.
Each POList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to a POList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.
An application can increase the capacity of an POList instance, before adding a large number of elements, by using the ensureCapacity operation. This may reduce the amount of incremental reallocation.
Field Summary |
---|
Fields inherited from class org.garret.consus.Persistent |
---|
db, oid, PO_DELETED, PO_LOADED, PO_NEW, PO_STUB, state, type |
Constructor Summary | |
---|---|
POList()
Constructs an empty list. |
|
POList(java.util.Collection c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. |
|
POList(int initialCapacity)
Constructs an empty list with the specified initial capacity. |
Method Summary | |
---|---|
void |
add(int index,
java.lang.Object element)
Inserts the specified element at the specified position in this list. |
boolean |
add(java.lang.Object o)
Appends the specified element to the end of this list. |
boolean |
addAll(java.util.Collection c)
Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator. |
boolean |
addAll(int index,
java.util.Collection c)
Inserts all of the elements in the specified Collection into this list, starting at the specified position. |
void |
clear()
Removes all of the elements from this list. |
java.lang.Object |
clone()
Returns a shallow copy of this POList instance. |
boolean |
contains(java.lang.Object elem)
Returns true if this list contains the specified element. |
void |
ensureCapacity(int minCapacity)
Increases the capacity of this POList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. |
java.lang.Object |
get(int index)
Returns the element from the specified position in this list. |
int |
indexOf(java.lang.Object elem)
Searches for the first occurence of the given argument, testing for equality using the equals method. |
boolean |
isEmpty()
Tests if this list has no elements. |
java.util.Iterator |
iterator()
Returns an iterator of the elements in this list in the proper sequence. |
int |
lastIndexOf(java.lang.Object elem)
Returns the index of the last occurrence of the specified object in this list. |
java.util.ListIterator |
listIterator()
Returns an iterator of the elements in this list (in proper sequence). |
java.util.ListIterator |
listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in the list. |
boolean |
loadClosure()
POList doesn't imlicitly loads its components. |
java.lang.Object |
remove(int index)
Removes the element at the specified position in this list. |
void |
removeRange(int fromIndex,
int toIndex)
Removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive. |
java.lang.Object |
set(int index,
java.lang.Object element)
Replaces the element at the specified position in this list with the specified element. |
int |
size()
Returns the number of elements in this list. |
java.util.List |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this list between fromIndex, inclusive, and toIndex, exclusive. |
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this list in the correct order. |
java.lang.Object[] |
toArray(java.lang.Object[] a)
Returns an array containing all of the elements in this list in the correct order. |
void |
trimToSize()
Trims the capacity of this POList instance to be the list's current size. |
Methods inherited from class org.garret.consus.POCollection |
---|
containsAll, equals, hashCode, remove, removeAll, retainAll, toString |
Methods inherited from class org.garret.consus.Persistent |
---|
assignOID, become, beginUpdate, endUpdate, get, get, getOid, getOid, getRef, getRef, isDeleted, isLoaded, isNew, load, loadComponents, lock, remove, save, store, store, unget |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
containsAll, equals, hashCode, remove, removeAll, retainAll |
Constructor Detail |
---|
public POList()
public POList(java.util.Collection c)
public POList(int initialCapacity)
initialCapacity
- the initial capacity of the list.Method Detail |
---|
public void add(int index, java.lang.Object element)
add
in interface java.util.List
index
- index at which the specified element is to be inserted.element
- element to be inserted.
java.lang.IndexOutOfBoundsException
- if index is out of range
(index < 0 || index > size()).public boolean add(java.lang.Object o)
add
in interface java.util.List
add
in class POCollection
o
- element to be appended to this list.
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.List
addAll
in class POCollection
c
- elements to be inserted into this list.
java.lang.IndexOutOfBoundsException
- if index out of range (index
< 0 || index > size()).POCollection.add(Object)
public boolean addAll(int index, java.util.Collection c)
addAll
in interface java.util.List
index
- index at which to insert first element
from the specified collection.c
- elements to be inserted into this list.
java.lang.IndexOutOfBoundsException
- if index out of range (index
< 0 || index > size()).public void clear()
clear
in interface java.util.List
clear
in class POCollection
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean contains(java.lang.Object elem)
contains
in interface java.util.List
contains
in class POCollection
elem
- element whose presence in this List is to be tested.
public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacity.public java.lang.Object get(int index)
get
in interface java.util.List
index
- index of element to return.
java.lang.IndexOutOfBoundsException
- if index is out of range (index
< 0 || index >= size()).public int indexOf(java.lang.Object elem)
indexOf
in interface java.util.List
elem
- an object.
Object.equals(Object)
public final boolean isEmpty()
isEmpty
in interface java.util.List
isEmpty
in class POCollection
public java.util.Iterator iterator()
This implementation returns a straightforward implementation of the iterator interface, relying on the backing list's size(), get(int), and remove(int) methods.
Note that the iterator returned by this method will throw an UnsupportedOperationException in response to its remove method, unless the list's remove(int) method is overridden.
This implementation can be made to throw runtime exceptions in the face of concurrent modification, as described in the specification for the (protected) modCount field.
iterator
in interface java.util.List
iterator
in class POCollection
public int lastIndexOf(java.lang.Object elem)
lastIndexOf
in interface java.util.List
elem
- the desired element.
public java.util.ListIterator listIterator()
listIterator
in interface java.util.List
listIterator(int)
public java.util.ListIterator listIterator(int index)
This implementation returns a straightforward implementation of the ListIterator interface, that extends the implementation of the Iterator interface returned by the iterator() method. The ListIterator implementation relies on the backing list's get(int), set(int, Object), add(int, Object) and remove(int) methods.
Note that the list iterator returned by this implementation will throw an UnsupportedOperationException in response to its remove, set and add methods, unless the list's remove(int), set(int, Object), and add(int, Object) methods are overridden.
This implementation can be made to throw runtime exceptions in the face of concurrent modification, as described in the specification for the (protected) modCount field.
listIterator
in interface java.util.List
index
- index of the first element to be returned from the list
iterator (by a call to the next method).
java.lang.IndexOutOfBoundsException
- if the specified index is out of
range (index < 0 || index > size()).public boolean loadClosure()
loadClosure
in class Persistent
true
to load all graph with referenced objects or
false
for loading stubs instead of referenced object.public java.lang.Object remove(int index)
remove
in interface java.util.List
index
- the index of the element to removed.
java.lang.IndexOutOfBoundsException
- if index out of range (index
< 0 || index >= size()).public void removeRange(int fromIndex, int toIndex)
fromIndex
- index of first element to be removed.toIndex
- index after last element to be removed.public java.lang.Object set(int index, java.lang.Object element)
set
in interface java.util.List
index
- index of element to replace.element
- element to be stored at the specified position.
java.lang.IndexOutOfBoundsException
- if index out of range
(index < 0 || index >= size()).public final int size()
size
in interface java.util.List
size
in class POCollection
public java.util.List subList(int fromIndex, int toIndex)
This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by operating on a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:
* list.subList(from, to).clear();n Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.
The semantics of the list returned by this method become undefined if the backing list (i.e. this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of the list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
This implementation returns a list that subclasses AbstractList. The subclass stores, in private fields, the offset of the subList within the backing list, the size of the subList (which can change over its lifetime), and the expected modCount value of the backing list.
The subclass's set(int, Object), get(int), add(int, Object), remove(int), addAll(int, Collection) and removeRange(int, int) methods all delegate to the corresponding methods on the backing abstract list, after bounds-checking the index and adjusting for the offset. The addAll(Collection c) method merely returns addAll(size, c).
The listIterator(int) method returns a "wrapper object" over a list iterator on the backing list, which is created with the corresponding method on the backing list. The iterator method merely returns listIterator(), and the size method merely returns the subclass's size field.
All methods first check to see if the actual modCount of the backing list is equal to its expected value, and throw a ConcurrentModificationException if it is not.
subList
in interface java.util.List
fromIndex
- low endpoint (inclusive) of the subList.toIndex
- high endpoint (exclusive) of the subList.
java.lang.IndexOutOfBoundsException
- endpoint index value out of range
(fromIndex < 0 || toIndex > size)
java.lang.IllegalArgumentException
- endpoint indices out of order
(fromIndex > toIndex)public java.lang.Object[] toArray()
toArray
in interface java.util.List
toArray
in class POCollection
public java.lang.Object[] toArray(java.lang.Object[] a)
If the list fits into the specified array with room to spare (i.e. the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.
toArray
in interface java.util.List
toArray
in class POCollection
a
- the array into which the elements of the list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.
java.lang.ArrayStoreException
- if the runtime type of a is not a supertype
of the runtime type of every element in this list.public void trimToSize()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |