public class InterfaceContainer
extends java.lang.Object
implements java.lang.Cloneable
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 an 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).
Constructor and Description |
---|
InterfaceContainer()
Creates a new instance of InterfaceContainer
|
InterfaceContainer(int initialCapacity)
Constructs an empty list with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
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 ArrayList instance.
|
boolean |
contains(java.lang.Object elem)
Returns true if this list contains the specified element.
|
boolean |
containsAll(java.util.Collection collection) |
void |
disposeAndClear(EventObject evt) |
void |
ensureCapacity(int minCapacity)
Increases the capacity of this ArrayList 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 at the specified position in this list.
|
int |
indexOf(java.lang.Object elem)
Searches for the first occurrence of the given argument, testing
for equality using the equals method.
|
boolean |
isEmpty()
Tests if this list has no elements.
|
java.util.Iterator |
iterator() |
int |
lastIndexOf(java.lang.Object elem)
Returns the index of the last occurrence of the specified object in
this list.
|
java.util.ListIterator |
listIterator() |
java.util.ListIterator |
listIterator(int index)
The iterator keeps a copy of the list.
|
java.lang.Object |
remove(int index)
Removes the element at the specified position in this list.
|
boolean |
remove(java.lang.Object obj)
Parameter obj may
|
boolean |
removeAll(java.util.Collection collection) |
boolean |
retainAll(java.util.Collection collection) |
java.lang.Object |
set(int index,
java.lang.Object element)
Not supported.
|
int |
size()
Returns the number of elements in this list.
|
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 ArrayList instance to be the
list's current size.
|
public InterfaceContainer()
public InterfaceContainer(int initialCapacity)
initialCapacity
- the initial capacity of the list.java.lang.IllegalArgumentException
- if the specified initial capacity
is negativepublic void trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacity.public boolean add(java.lang.Object o)
o
- element to be appended to this list.public void add(int index, java.lang.Object element)
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 addAll(java.util.Collection c)
c
- the elements to be inserted into this list.java.lang.IndexOutOfBoundsException
- if index out of range (index
< 0 || index > size()).public boolean addAll(int index, java.util.Collection c)
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()
public boolean contains(java.lang.Object elem)
elem
- element whose presence in this List is to be tested.public boolean containsAll(java.util.Collection collection)
public java.lang.Object get(int index)
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)
elem
- an object.Object.equals(Object)
public boolean isEmpty()
public java.util.Iterator iterator()
public int lastIndexOf(java.lang.Object elem)
elem
- the desired element.public java.lang.Object clone()
clone
in class java.lang.Object
public java.util.ListIterator listIterator()
public java.util.ListIterator listIterator(int index)
index
- public java.lang.Object remove(int index)
index
- the index of the element to removed.java.lang.IndexOutOfBoundsException
- if index out of range (index
< 0 || index >= size()).public boolean remove(java.lang.Object obj)
public boolean removeAll(java.util.Collection collection)
public boolean retainAll(java.util.Collection collection)
public java.lang.Object set(int index, java.lang.Object element)
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 int size()
public java.lang.Object[] toArray()
public java.lang.Object[] toArray(java.lang.Object[] a)
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 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.
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 disposeAndClear(EventObject evt)