diff --git a/src/java/org/apache/commons/collections/decorators/PredicatedCollection.java b/src/java/org/apache/commons/collections/decorators/PredicatedCollection.java index 2f77bce72..49f038ffa 100644 --- a/src/java/org/apache/commons/collections/decorators/PredicatedCollection.java +++ b/src/java/org/apache/commons/collections/decorators/PredicatedCollection.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/PredicatedCollection.java,v 1.2 2003/05/07 11:20:21 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/PredicatedCollection.java,v 1.3 2003/05/11 13:14:51 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -70,7 +70,7 @@ import org.apache.commons.collections.Predicate; * is thrown. * * @since Commons Collections 3.0 - * @version $Revision: 1.2 $ $Date: 2003/05/07 11:20:21 $ + * @version $Revision: 1.3 $ $Date: 2003/05/11 13:14:51 $ * * @author Stephen Colebourne * @author Paul Jack @@ -117,6 +117,21 @@ public class PredicatedCollection extends AbstractCollectionDecorator { } } + /** + * Validates the object being added to ensure it matches the predicate. + *
+ * The predicate itself should not throw an exception, but return false to + * indicate that the object cannot be added. + * + * @param object the object being added + * @throws IllegalArgumentException if the add is invalid + */ + protected void validate(Object object) { + if (predicate.evaluate(object) == false) { + throw new IllegalArgumentException("Cannot add Object '" + object + "' - Predicate rejected it"); + } + } + //----------------------------------------------------------------------- /** * Override to validate the object being added to ensure it matches @@ -147,19 +162,4 @@ public class PredicatedCollection extends AbstractCollectionDecorator { return getCollection().addAll(coll); } - /** - * Validates the object being added to ensure it matches the predicate. - *
- * The predicate itself should not throw an exception, but return false to - * indicate that the object cannot be added. - * - * @param object the object being added - * @throws IllegalArgumentException if the add is invalid - */ - protected void validate(Object object) { - if (predicate.evaluate(object) == false) { - throw new IllegalArgumentException("Cannot add Object '" + object + "' - Predicate rejected it"); - } - } - } diff --git a/src/java/org/apache/commons/collections/decorators/PredicatedList.java b/src/java/org/apache/commons/collections/decorators/PredicatedList.java index e8012c197..525cdfedc 100644 --- a/src/java/org/apache/commons/collections/decorators/PredicatedList.java +++ b/src/java/org/apache/commons/collections/decorators/PredicatedList.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/PredicatedList.java,v 1.2 2003/05/07 11:20:21 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/decorators/Attic/PredicatedList.java,v 1.3 2003/05/11 13:14:51 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -72,7 +72,7 @@ import org.apache.commons.collections.Predicate; * is thrown. * * @since Commons Collections 3.0 - * @version $Revision: 1.2 $ $Date: 2003/05/07 11:20:21 $ + * @version $Revision: 1.3 $ $Date: 2003/05/11 13:14:51 $ * * @author Stephen Colebourne * @author Paul Jack @@ -119,18 +119,6 @@ public class PredicatedList extends PredicatedCollection implements List { } //----------------------------------------------------------------------- - public void add(int index, Object object) { - validate(object); - getList().add(index, object); - } - - public boolean addAll(int index, Collection coll) { - for (Iterator it = coll.iterator(); it.hasNext(); ) { - validate(it.next()); - } - return getList().addAll(index, coll); - } - public Object get(int index) { return getList().get(index); } @@ -143,26 +131,29 @@ public class PredicatedList extends PredicatedCollection implements List { return getList().lastIndexOf(object); } + public Object remove(int index) { + return getList().remove(index); + } + + //----------------------------------------------------------------------- + public void add(int index, Object object) { + validate(object); + getList().add(index, object); + } + + public boolean addAll(int index, Collection coll) { + for (Iterator it = coll.iterator(); it.hasNext(); ) { + validate(it.next()); + } + return getList().addAll(index, coll); + } + public ListIterator listIterator() { return listIterator(0); } public ListIterator listIterator(int i) { - return new AbstractListIteratorDecorator(getList().listIterator(i)) { - public void add(Object object) { - validate(object); - getIterator().add(object); - } - - public void set(Object object) { - validate(object); - getIterator().set(object); - } - }; - } - - public Object remove(int index) { - return getList().remove(index); + return new PredicatedListIterator(getList().listIterator(i)); } public Object set(int index, Object object) { @@ -175,4 +166,24 @@ public class PredicatedList extends PredicatedCollection implements List { return new PredicatedList(sub, predicate); } + /** + * Inner class Iterator for the PredicatedList + */ + protected class PredicatedListIterator extends AbstractListIteratorDecorator { + + protected PredicatedListIterator(ListIterator iterator) { + super(iterator); + } + + public void add(Object object) { + validate(object); + getIterator().add(object); + } + + public void set(Object object) { + validate(object); + getIterator().set(object); + } + } + }