gausssoft.collections
Class AltFilterCollection
java.lang.Object
|
+--java.util.AbstractCollection
|
+--gausssoft.collections.AltFilterCollection
- All Implemented Interfaces:
- Collection, Serializable
- public class AltFilterCollection
- extends AbstractCollection
- implements Serializable
The AltFilterCollection wraps around another Collection
object providing the same functionality as AbstractCollection.
This class exists as an alternative to FilterCollection class, in
the way that certain methods are inherited from the AbstractCollection class,
while other methods call the backing Collection. The main use of this is to
cut down the work that some classes would have to perform if they had used
the FilterCollection class.
For example, you may have a collection object which contains objects of several
different class types. However, you may want to wrap a FilterCollection round it so that a
certain object only sees the objects in the backing Collection which are
String objects. This would mean preventing addition of non-String objects
by modifying the add method, preventing removal of non-String objects by
modifying the remove method and so on. However, you would have to
modify the addAll method, otherwise that would be passed to
the backing collection. Modifications would also be needed to the removeAll
method, as well as equals, hashCode, toArray and
so on.
This ends up duplicating a lot of work to create the FilterCollection subclass. So
this class is provided to allow object filtering to occur whilst minimizing the effort
to program it. All operations which call the backing collection are required
operations, operations which do not override the behaviour of the AbstractCollection
class implementation are batch operations, which use the required methods
in their implementation.
This object is only serializable if the backing collection is serializable. It should be
noted that when an iterator is returned at this level, it is returning a AltFilterIterator, which uses a backing iterator from the backing collection for the
remove method of this object, rather than that of the backing iterator.
If you intend a different behaviour of the iterator to that of the iterators produced
by the backing collection, you should override the iterator method.
All methods which override the subclass implementations simply call the method of the
same name in the backing collection.
- Author:
- Allan Crooks
- See Also:
Collection,
AbstractCollection,
FilterCollection,
AltFilterList,
AltFilterSet,
AltFilterIterator, Serialized Form
root
protected Collection root
- The backing collection.
AltFilterCollection
public AltFilterCollection(Collection root)
- Creates a new AltFilterCollection.
- Parameters:
root - The backing collection to use.- Throws:
NullPointerException - If root is null.
iterator
public Iterator iterator()
- Returns a
AltFilterIterator object, using this object as the filtering
object and using an iterator from the backing collection as the backing iterator.
- Overrides:
iterator in class AbstractCollection
- Returns:
- An iterator for this collection.
size
public int size()
- Overrides:
size in class AbstractCollection
add
public boolean add(Object o)
- Overrides:
add in class AbstractCollection
contains
public boolean contains(Object o)
- Overrides:
contains in class AbstractCollection
remove
public boolean remove(Object o)
- Overrides:
remove in class AbstractCollection