InterfaceContainer cont= new InterfaceContainer(); ListIterator it= cont.listIterator(); cont.add( someInterface); // one cannot obtain someInterface through iterator it, // instead get a new iterator it= cont.listIterator(); // it now keeps a fresh copy of cont and hence contains someInterface // Adding an interface on the iterator will cause the interface also to be added // to InterfaceContainer it.add( someOtherInterface); // someOtherInterface is now in it and cont ListIterator it2= cont.listIterator(); //someOtherInterface can also be obtained by all newly created iterators, e.g. it2.The add and remove methods of an iterator work on a particular location within a list, dependent on what the value of the iterator's cursor is. After the call the value at the appropriate position has been modified. Since the iterator received a copy of InterfaceContainer's data, InterfaceContainer may have been modified (by List methods or through other iterators). Therefore both data sets may not contain the same elements anymore. Consequently, a List method that modifies data, does not modify InterfaceContainer's data at a certain index (according to the iterators cursor). Instead, new elements are added at the end of list. When Iterator.remove is called, then the first occurrence of that element in InterfaceContainer is removed. ListIterator.set is not supported. A lot of methods resemble those of the to java.util.List interface, although this class does not implement it. However, the list iterators returned, for example by the listIterator method implement the java.util.ListIterator interface. Implementing the List interface would mean to support all none - optional methods as prescribed by the interface declaration. Among those is the subList method which returns a range of values of the list's data wrapped in a List implementation. Changes to the sub list have to cause changes in the main list. This is a problem, since this class is to be used in a multi-threaded environment. The sub list could work on a copy as the iterators do, but all the functions which work on a given index could not be properly supported. Unfortunately, the List interface documentation states that all optional methods implemented by the list have to be implemented in the sub list. That would mean to do without all those critical methods, although they might work well in the "main list" (as opposed to sub list).
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final boolean | |
| pack-priv Object[] | elementData
The array buffer into which the elements of the ArrayList are stored. |
| private int | size
The size of the ArrayList (the number of elements it contains). |
| Access | Constructor and Description |
|---|---|
| public | |
| public | InterfaceContainer(int
the initial capacity of the list. initialCapacity)Constructs an empty list with the specified initial capacity. |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized boolean | |
| public synchronized void | |
| public synchronized boolean | Returns: true if an element was inserted.the elements to be inserted into this list. 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. |
| public synchronized boolean | Returns: true if an element was inserted.index at which to insert first element
from the specified collection. index, Collection<E> elements to be inserted into this list. c)Inserts all of the elements in the specified Collection into this list, starting at the specified position. |
| public synchronized void | |
| public synchronized Object | Returns: a clone of thisList instance.Overrides java. Returns a shallow copy of this |
| public synchronized boolean | |
| public synchronized boolean | |
| public void | |
| public synchronized void | ensureCapacity(int
the desired minimum capacity. minCapacity)Increases the capacity of this |
| public synchronized Object | Returns: the element at the specified position in this list.index of element to return. index)Returns the element at the specified position in this list. |
| public synchronized int | |
| public synchronized boolean | Returns: true if this list has no elements;
false otherwise.Tests if this list has no elements. |
| public synchronized Iterator | |
| public synchronized int | Returns: the index of the last occurrence of the specified object in this list; returns -1 if the object is not found.the desired element. elem)Returns the index of the last occurrence of the specified object in this list. |
| public synchronized ListIterator | |
| public synchronized ListIterator | Returns: a new iterator.the starting offset into the list. index)The iterator keeps a copy of the list. |
| private void | |
| public synchronized Object | Returns: the element that was removed from the list.the index of the element to removed. index)Removes the element at the specified position in this list. |
| public synchronized boolean | |
| public synchronized boolean | |
| public synchronized boolean | |
| public synchronized Object | |
| public synchronized int | |
| public synchronized Object[] | Returns: an array containing all of the elements in this list in the correct order.Returns an array containing all of the elements in this list in the correct order. |
| public synchronized Object[] | Returns: an array containing the elements of the list.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. a)Returns an array containing all of the elements in this list in the correct order. |
| public synchronized void |
| DEBUG | back to summary |
|---|---|
| pack-priv static final boolean DEBUG | |
| elementData | back to summary |
|---|---|
| pack-priv Object[] elementData The array buffer into which the elements of the ArrayList are stored. The capacity of the ArrayList is the length of this array buffer. | |
| size | back to summary |
|---|---|
| private int size The size of the ArrayList (the number of elements it contains). | |
| InterfaceContainer | back to summary |
|---|---|
| public InterfaceContainer() Creates a new instance of InterfaceContainer | |
| InterfaceContainer | back to summary |
|---|---|
| public InterfaceContainer(int initialCapacity) Constructs an empty list with the specified initial capacity.
| |
| InterfaceContainer | back to summary |
|---|---|
| private InterfaceContainer(Object[] data) | |
| add | back to summary |
|---|---|
| public synchronized boolean add(Object o) Appends the specified element to the end of this list.
| |
| add | back to summary |
|---|---|
| public synchronized void add(int index, Object element) Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
| |
| addAll | back to summary |
|---|---|
| public synchronized boolean addAll(Collection<E> 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. The behavior of this operation is undefined if the specified Collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this list, and this list is nonempty.)
| |
| addAll | back to summary |
|---|---|
| public synchronized boolean addAll(int index, Collection<E> c) Inserts all of the elements in the specified Collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified Collection's iterator.
| |
| clear | back to summary |
|---|---|
| public synchronized void clear() Removes all of the elements from this list. The list will be empty after this call returns. | |
| clone | back to summary |
|---|---|
| public synchronized Object clone() Overrides java. Returns a shallow copy of this | |
| contains | back to summary |
|---|---|
| public synchronized boolean contains(Object elem) Returns
| |
| containsAll | back to summary |
|---|---|
| public synchronized boolean containsAll(Collection<E> collection) | |
| disposeAndClear | back to summary |
|---|---|
| public void disposeAndClear(com. | |
| ensureCapacity | back to summary |
|---|---|
| public synchronized void ensureCapacity(int minCapacity) Increases the capacity of this
| |
| get | back to summary |
|---|---|
| public synchronized Object get(int index) Returns the element at the specified position in this list.
| |
| indexOf | back to summary |
|---|---|
| public synchronized int indexOf(Object elem) Searches for the first occurrence of the given argument, testing
for equality using the
| |
| isEmpty | back to summary |
|---|---|
| public synchronized boolean isEmpty() Tests if this list has no elements.
| |
| iterator | back to summary |
|---|---|
| public synchronized Iterator | |
| lastIndexOf | back to summary |
|---|---|
| public synchronized int lastIndexOf(Object elem) Returns the index of the last occurrence of the specified object in this list.
| |
| listIterator | back to summary |
|---|---|
| public synchronized ListIterator | |
| listIterator | back to summary |
|---|---|
| public synchronized ListIterator The iterator keeps a copy of the list. Changes to InterfaceContainer do not affect the data of the iterator. Conversely, changes to the iterator are effect InterfaceContainer.
| |
| RangeCheck | back to summary |
|---|---|
| private void RangeCheck(int index) Check if the given index is in range. If not, throw an appropriate runtime exception. | |
| remove | back to summary |
|---|---|
| public synchronized Object remove(int index) Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).
| |
| remove | back to summary |
|---|---|
| public synchronized boolean remove(Object obj) Parameter obj may... or may not. What did the original author want to tell us here?
| |
| removeAll | back to summary |
|---|---|
| public synchronized boolean removeAll(Collection<E> collection) | |
| retainAll | back to summary |
|---|---|
| public synchronized boolean retainAll(Collection<E> collection) | |
| set | back to summary |
|---|---|
| public synchronized Object set(int index, Object element) Not supported.
| |
| size | back to summary |
|---|---|
| public synchronized int size() Returns the number of elements in this list.
| |
| toArray | back to summary |
|---|---|
| public synchronized Object[] toArray() Returns an array containing all of the elements in this list in the correct order.
| |
| toArray | back to summary |
|---|---|
| public synchronized Object[] toArray(Object[] a) Returns an array containing all of the elements in this list in the correct order. The runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.
If the list fits in 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
| |
| trimToSize | back to summary |
|---|---|
| public synchronized void trimToSize() Trims the capacity of this | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | cursor
Index of element to be returned by subsequent call to next. |
| pack-priv InterfaceContainer | |
| pack-priv int | lastRet
Index of element returned by most recent call to next or previous. |
| pack-priv Object | lastRetObj
The object that has been returned by most recent call to next or previous. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized boolean | |
| public synchronized Object | |
| public synchronized void | remove()
Overrides default java. Removes the interface from the list, that has been last returned by a call to next(). |
| cursor | back to summary |
|---|---|
| pack-priv int cursor Index of element to be returned by subsequent call to next. | |
| dataIt | back to summary |
|---|---|
| pack-priv InterfaceContainer dataIt | |
| lastRet | back to summary |
|---|---|
| pack-priv int lastRet Index of element returned by most recent call to next or previous. Reset to -1 if this element is deleted by a call to remove. | |
| lastRetObj | back to summary |
|---|---|
| pack-priv Object lastRetObj The object that has been returned by most recent call to next or previous. Reset to null if this element is deleted by a call to remove. | |
| Itr | back to summary |
|---|---|
| pack-priv Itr(InterfaceContainer _data) | |
| hasNext | back to summary |
|---|---|
| public synchronized boolean hasNext() Implements java. Doc from java. Returns | |
| next | back to summary |
|---|---|
| public synchronized Object next() Implements java. Doc from java. Returns the next element in the iteration. | |
| remove | back to summary |
|---|---|
| public synchronized void remove() Overrides default java. Removes the interface from the list, that has been last returned by a call to next(). This is done according to the specification of the interface method. The element is also removed from InterfaceContainer but independent of the location. If the element is multiple times in InterfaceContainer then it is up to the java.util.ArrayList implementation what element is removed. | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | add(Object o)
Implements java. Inserts an element to the iterators list according to the specification of this interface method. |
| public synchronized boolean | hasPrevious()
Implements java. Returns |
| public synchronized int | nextIndex()
Implements java. Returns the index of the element that would be returned by a
subsequent call to |
| public synchronized Object | previous()
Implements java. Returns the previous element in the list and moves the cursor position backwards. |
| public synchronized int | previousIndex()
Implements java. Returns the index of the element that would be returned by a
subsequent call to |
| public synchronized void | set(Object o)
Implements java. This is not possible since several iterators can modify InterfaceContainer |
| LstItr | back to summary |
|---|---|
| pack-priv LstItr(InterfaceContainer _data, int _index) | |
| add | back to summary |
|---|---|
| public synchronized void add(Object o) Implements java. Inserts an element to the iterators list according to the specification of this interface method. The element is also added to InterfaceContainer but its location within the list cannot be guaranteed. | |
| hasPrevious | back to summary |
|---|---|
| public synchronized boolean hasPrevious() Implements java. Doc from java. Returns | |
| nextIndex | back to summary |
|---|---|
| public synchronized int nextIndex() Implements java. Doc from java. Returns the index of the element that would be returned by a
subsequent call to | |
| previous | back to summary |
|---|---|
| public synchronized Object previous() Implements java. Doc from java. Returns the previous element in the list and moves the cursor
position backwards. This method may be called repeatedly to
iterate through the list backwards, or intermixed with calls to
| |
| previousIndex | back to summary |
|---|---|
| public synchronized int previousIndex() Implements java. Doc from java. Returns the index of the element that would be returned by a
subsequent call to | |
| set | back to summary |
|---|---|
| public synchronized void set(Object o) Implements java. This is not possible since several iterators can modify InterfaceContainer | |