commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/decorators PredicatedList.java PredicatedCollection.java
Date Sun, 11 May 2003 13:14:51 GMT
scolebourne    2003/05/11 06:14:51

  Modified:    collections/src/java/org/apache/commons/collections/decorators
                        PredicatedList.java PredicatedCollection.java
  Log:
  Reformat file layout
  
  Revision  Changes    Path
  1.3       +40 -29    jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/PredicatedList.java
  
  Index: PredicatedList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/PredicatedList.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PredicatedList.java	7 May 2003 11:20:21 -0000	1.2
  +++ PredicatedList.java	11 May 2003 13:14:51 -0000	1.3
  @@ -119,18 +119,6 @@
       }
   
       //-----------------------------------------------------------------------
  -    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 @@
           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) {
  @@ -173,6 +164,26 @@
       public List subList(int fromIndex, int toIndex) {
           List sub = getList().subList(fromIndex, toIndex);
           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);
  +        }
       }
   
   }
  
  
  
  1.3       +17 -17    jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/PredicatedCollection.java
  
  Index: PredicatedCollection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/PredicatedCollection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PredicatedCollection.java	7 May 2003 11:20:21 -0000	1.2
  +++ PredicatedCollection.java	11 May 2003 13:14:51 -0000	1.3
  @@ -117,6 +117,21 @@
           }
       }
   
  +    /**
  +     * Validates the object being added to ensure it matches the predicate.
  +     * <p>
  +     * 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
  @@ -145,21 +160,6 @@
               validate(it.next());
           }
           return getCollection().addAll(coll);
  -    }
  -
  -    /**
  -     * Validates the object being added to ensure it matches the predicate.
  -     * <p>
  -     * 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");
  -        }
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message