Overriding methods in Collection<T>
<p>I am working on a class assignment where I have a collection and it will be filtered out. For example, the filter class, which is an interface is one method (matches) which takes in T element.  </p>

<p>In my FilterCollection class:</p>

<pre><code>public class FilteredCollection&lt;T&gt; extends AbstractCollectionDecorator&lt;T&gt; {

Collection&lt;T&gt; filterCollection;
Filter&lt;T&gt; currentFilter;


private FilteredCollection(Collection&lt;T&gt; coll, Filter&lt;T&gt; filter) {
    super(coll);
    this.filterCollection = coll;
    this.currentFilter = filter;
}


public static &lt;T&gt; FilteredCollection&lt;T&gt; decorate(Collection&lt;T&gt; coll, Filter&lt;T&gt; filter) {
    return new FilteredCollection&lt;T&gt;(coll, filter);
}
</code></pre>

<p>From there I have to override methods, such as add, addall, contains, remove, etc.</p>

<p>With the add() method</p>

<pre><code>@Override
public boolean add(T object)
{
    return filterCollection.add(object);
}
</code></pre>

<p>However, I need to see if the object matches whats in the filter and if it does, dont add it, if it doesnt, add it. What is the proper way to go about this?</p>