net.sf.molae.pipe.filter
Class FilteredCollection

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--net.sf.molae.pipe.filter.FilteredCollection
All Implemented Interfaces:
Collection

public final class FilteredCollection
extends AbstractCollection

Implements a collection that contains all elements of a base collection that match a filter condition.


Constructor Summary
FilteredCollection(Collection base, Predicate filter)
          Constructs a filtered collection from the specified collection and filter.
 
Method Summary
 boolean add(Object o)
          Ensures that this collection contains the specified element if the element matches the filter.
protected  void assertRange(Object o)
          Checks if the specified object fulfils the filter predicate of this class.
 boolean contains(Object o)
          Returns true if the base collection contains the specified element and the element matches the underlying filter.
protected  Collection getBase()
          Returns the underlying collection.
protected  Predicate getFilter()
          Returns the underlying filter.
 Iterator iterator()
           
 boolean remove(Object o)
          Removes a single instance of the specified element from the base collection, if it is present and matches the underlying filter.
 int size()
           
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

FilteredCollection

public FilteredCollection(Collection base,
                          Predicate filter)
Constructs a filtered collection from the specified collection and filter.
Parameters:
base - the underlying collection
filter - predicate that determines which objects belong to the collection
Throws:
NullPointerException - if the specified objects are null.
Method Detail

getBase

protected Collection getBase()
Returns the underlying collection.
Returns:
the underlying collection.

getFilter

protected Predicate getFilter()
Returns the underlying filter.
Returns:
the underlying filter

assertRange

protected void assertRange(Object o)
Checks if the specified object fulfils the filter predicate of this class.
Parameters:
o - object to evaluate.
Throws:
IllegalArgumentException - if the specified object does not fulfil the filter predicate of this class.

size

public int size()
Overrides:
size in class AbstractCollection

contains

public boolean contains(Object o)
Returns true if the base collection contains the specified element and the element matches the underlying filter.
Overrides:
contains in class AbstractCollection
Parameters:
o - element whose presence in this collection is to be tested.
Returns:
true if the base collection contains the specified element and the element matches the underlying filter

iterator

public Iterator iterator()
Overrides:
iterator in class AbstractCollection

add

public boolean add(Object o)
Ensures that this collection contains the specified element if the element matches the filter.
Overrides:
add in class AbstractCollection
Throws:
UnsupportedOperationException - depending on the base collection
ClassCastException - depending on the base collection
IllegalArgumentException - if the specified object does not fulfil the filter predicate of this class or the base collection does not accept the element.

remove

public boolean remove(Object o)
Removes a single instance of the specified element from the base collection, if it is present and matches the underlying filter.
Overrides:
remove in class AbstractCollection
Throws:
UnsupportedOperationException - depending on the base collection