Package ptolemy.actor.gt.data
Class CombinedCollection<E>
- java.lang.Object
-
- ptolemy.actor.gt.data.CombinedCollection<E>
-
- Type Parameters:
E
- The type of elements in the collection.
- All Implemented Interfaces:
java.lang.Iterable<E>
,java.util.Collection<E>
public class CombinedCollection<E> extends java.lang.Object implements java.util.Collection<E>
A collection that is the combination of one or more collections. This is a more efficient implementation that copying all the elements of those collections into a new collection and using that collection. No copying is necessary because the component collections are maintained locally and their elements are retrieved only when they are used.- Since:
- Ptolemy II 8.0
- Version:
- $Id$
- Author:
- Thomas Huining Feng
- See Also:
ActorGraphFrame
- Pt.AcceptedRating:
- Red (tfeng)
- Pt.ProposedRating:
- Yellow (tfeng)
-
-
Constructor Summary
Constructors Constructor Description CombinedCollection()
Construct a combined collection with no collection as its component.CombinedCollection(java.util.Collection<? extends E>... collections)
Construct a combined collection with one or more collections as its components.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.List<java.util.Collection<? extends E>>
_getCollectionList()
Get the list containing all the component collections.boolean
add(E element)
Add an element to the end of this collection.boolean
addAll(java.util.Collection<? extends E> collection)
Add all elements of the provided collection to this collection.void
clear()
Clear this collection by removing all its components.boolean
contains(java.lang.Object element)
Test whether this collection contains the given element.boolean
containsAll(java.util.Collection<?> collection)
Test whether this collection contains all the elements of the given collection.boolean
isEmpty()
Test whether this collection is empty.java.util.Iterator<E>
iterator()
Return an iterator to iterate all the elements in this collection.boolean
remove(java.lang.Object element)
Throw a runtime exception because removal is not supported.boolean
removeAll(java.util.Collection<?> collection)
Throw a runtime exception because removal is not supported.boolean
retainAll(java.util.Collection<?> collection)
Throw a runtime exception because removal is not supported.int
size()
Return size of this collection.java.lang.Object[]
toArray()
Return an array that contains all the elements in this collection.<T> T[]
toArray(T[] array)
Store all the elements in this collection into the given array if its size is enough for the storage, or create a new array of the same type as the given array for the storage and return it.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
CombinedCollection
public CombinedCollection()
Construct a combined collection with no collection as its component.
-
CombinedCollection
public CombinedCollection(java.util.Collection<? extends E>... collections)
Construct a combined collection with one or more collections as its components. The order of those components coincides with the order of the elements of this combined collection.- Parameters:
collections
- The collections.
-
-
Method Detail
-
add
public boolean add(E element)
Add an element to the end of this collection. Component collections are not modified because an extra collection is added to the end that allows to add elements to.- Specified by:
add
in interfacejava.util.Collection<E>
- Parameters:
element
- The new element.- Returns:
- Always true.
-
addAll
public boolean addAll(java.util.Collection<? extends E> collection)
Add all elements of the provided collection to this collection. The given collection is added as a component of this collection and no copying is involved.- Specified by:
addAll
in interfacejava.util.Collection<E>
- Parameters:
collection
- The collection to be added.- Returns:
- Always true.
-
clear
public void clear()
Clear this collection by removing all its components.- Specified by:
clear
in interfacejava.util.Collection<E>
-
contains
public boolean contains(java.lang.Object element)
Test whether this collection contains the given element.- Specified by:
contains
in interfacejava.util.Collection<E>
- Parameters:
element
- The element.- Returns:
- true if the element is contained in this collection.
-
containsAll
public boolean containsAll(java.util.Collection<?> collection)
Test whether this collection contains all the elements of the given collection.- Specified by:
containsAll
in interfacejava.util.Collection<E>
- Parameters:
collection
- The collection.- Returns:
- true if all the elements are contained in this collection.
-
isEmpty
public boolean isEmpty()
Test whether this collection is empty.- Specified by:
isEmpty
in interfacejava.util.Collection<E>
- Returns:
- true if it is empty.
-
iterator
public java.util.Iterator<E> iterator()
Return an iterator to iterate all the elements in this collection.
-
remove
public boolean remove(java.lang.Object element)
Throw a runtime exception because removal is not supported.- Specified by:
remove
in interfacejava.util.Collection<E>
- Parameters:
element
- The element to be removed.- Returns:
- None.
-
removeAll
public boolean removeAll(java.util.Collection<?> collection)
Throw a runtime exception because removal is not supported.- Specified by:
removeAll
in interfacejava.util.Collection<E>
- Parameters:
collection
- The collection whose elements are to be removed.- Returns:
- None.
-
retainAll
public boolean retainAll(java.util.Collection<?> collection)
Throw a runtime exception because removal is not supported.- Specified by:
retainAll
in interfacejava.util.Collection<E>
- Parameters:
collection
- The collection whose elements are to be retained.- Returns:
- None.
-
size
public int size()
Return size of this collection.- Specified by:
size
in interfacejava.util.Collection<E>
- Returns:
- The size.
-
toArray
public java.lang.Object[] toArray()
Return an array that contains all the elements in this collection.- Specified by:
toArray
in interfacejava.util.Collection<E>
- Returns:
- The array.
-
toArray
public <T> T[] toArray(T[] array)
Store all the elements in this collection into the given array if its size is enough for the storage, or create a new array of the same type as the given array for the storage and return it.- Specified by:
toArray
in interfacejava.util.Collection<E>
- Type Parameters:
T
- The element type of the array.- Parameters:
array
- The array.- Returns:
- The given array, or a new array if the given array is not big enough.
-
_getCollectionList
protected java.util.List<java.util.Collection<? extends E>> _getCollectionList()
Get the list containing all the component collections. This list cannot be modified.- Returns:
- The list containing all the component collections.
-
-