|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.tensegrity.generic.util.CombinedCollection
Class CombinedCollection merges two collections into a new
collection view consisting of the contents of both. Because the underlying
collections are not physically combined, the cost of creating the combined
List is linear.
An instance does not allow modification to any of its contents, but changes
to the underlying collections are immediately reflected. The sole exception
is during an iteration. In other words, it is possible to iterate over a
CombinedCollection and change the underlying lists without
having a ConcurrentModificationException being thrown.
It is not possible to alter the combined collection instance or their contents directly, however.
Unsupported operations will cause a RuntimeException to be
thrown, which indicates that the user is trying something defined by the
Collection interface yet which contradicts the semantics of
the read-only view that a CombinedCollection provides.
The cost of creating a new CombinedCollection instance is very
low and allows quick pseudo-concatenation of two existing Collection
instances. The resulting object can be traversed with an Iterator
and its size can also be determined. Additionally, the instance can be passed
to constructors of other standard Collection objects, since its
toObject method has been appropriately overridden. The number of
operations that are supported by this class are limited, however, and restricted
to read-only operations.
Combined collections can be recursively nested. Suppose you have three rather
large collections, for example ArrayLists, and you wish to combine them into a
single Collection object. The code would look like this:
public Collection combineArrayLists (ArrayList a, ArrayList b, ArrayList c)
{
return new CombinedCollection ( a, new CombinedCollection (b, c));
}
| Field Summary | |
protected java.util.Collection |
a
Reference to the first of the two combined collections. |
protected java.util.Collection |
b
Reference to the second of the two combined collections. |
| Constructor Summary | |
CombinedCollection(java.util.Collection a,
java.util.Collection b)
Constructs a new CombinedCollection instance that consists of the two specified |
|
| Method Summary | |
void |
add(int index,
java.lang.Object element)
|
boolean |
add(java.lang.Object o)
|
boolean |
addAll(java.util.Collection c)
|
boolean |
addAll(int index,
java.util.Collection c)
|
void |
clear()
|
boolean |
contains(java.lang.Object o)
|
boolean |
containsAll(java.util.Collection c)
|
java.lang.Object |
get(int index)
|
int |
indexOf(java.lang.Object o)
|
boolean |
isEmpty()
|
java.util.Iterator |
iterator()
|
int |
lastIndexOf(java.lang.Object o)
|
java.util.ListIterator |
listIterator()
|
java.util.ListIterator |
listIterator(int index)
|
java.lang.Object |
remove(int index)
|
boolean |
remove(java.lang.Object o)
|
boolean |
removeAll(java.util.Collection c)
|
boolean |
retainAll(java.util.Collection c)
|
java.lang.Object |
set(int index,
java.lang.Object element)
|
int |
size()
|
java.util.List |
subList(int fromIndex,
int toIndex)
|
java.lang.Object[] |
toArray()
|
java.lang.Object[] |
toArray(java.lang.Object[] array)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.List |
equals, hashCode |
| Field Detail |
protected java.util.Collection a
protected java.util.Collection b
| Constructor Detail |
public CombinedCollection(java.util.Collection a,
java.util.Collection b)
a - the first collection to combine.b - the second collection to combine.| Method Detail |
public int size()
size in interface java.util.ListCollection.size()public boolean isEmpty()
isEmpty in interface java.util.ListCollection.isEmpty()public boolean contains(java.lang.Object o)
contains in interface java.util.ListCollection.contains(java.lang.Object)public java.util.Iterator iterator()
iterator in interface java.util.ListCollection.iterator()public java.lang.Object[] toArray()
toArray in interface java.util.ListCollection.toArray()public java.lang.Object[] toArray(java.lang.Object[] array)
toArray in interface java.util.ListCollection.toArray(java.lang.Object[])public boolean add(java.lang.Object o)
add in interface java.util.ListCollection.add(java.lang.Object)public boolean remove(java.lang.Object o)
remove in interface java.util.ListCollection.remove(java.lang.Object)public boolean containsAll(java.util.Collection c)
containsAll in interface java.util.ListCollection.containsAll(java.util.Collection)public boolean addAll(java.util.Collection c)
addAll in interface java.util.ListCollection.addAll(java.util.Collection)
public boolean addAll(int index,
java.util.Collection c)
addAll in interface java.util.ListList.addAll(int, java.util.Collection)public boolean removeAll(java.util.Collection c)
removeAll in interface java.util.ListCollection.removeAll(java.util.Collection)public boolean retainAll(java.util.Collection c)
retainAll in interface java.util.ListCollection.retainAll(java.util.Collection)public void clear()
clear in interface java.util.ListCollection.clear()public java.lang.Object get(int index)
get in interface java.util.ListList.get(int)
public java.lang.Object set(int index,
java.lang.Object element)
set in interface java.util.ListList.set(int, java.lang.Object)
public void add(int index,
java.lang.Object element)
add in interface java.util.ListList.add(int, java.lang.Object)public java.lang.Object remove(int index)
remove in interface java.util.ListList.remove(int)public int indexOf(java.lang.Object o)
indexOf in interface java.util.ListList.indexOf(java.lang.Object)public int lastIndexOf(java.lang.Object o)
lastIndexOf in interface java.util.ListList.lastIndexOf(java.lang.Object)public java.util.ListIterator listIterator()
listIterator in interface java.util.ListList.listIterator()public java.util.ListIterator listIterator(int index)
listIterator in interface java.util.ListList.listIterator(int)
public java.util.List subList(int fromIndex,
int toIndex)
subList in interface java.util.ListList.subList(int, int)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||