commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pj...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestBoundedCollection.java TestBufferUtils.java TestListUtils.java TestMapUtils.java TestPredicatedCollection.java TestSetUtils.java TestAll.java TestCollectionUtils.java TestList.java
Date Tue, 13 Aug 2002 00:26:52 GMT
pjack       2002/08/12 17:26:52

  Modified:    collections/src/java/org/apache/commons/collections
                        BufferUtils.java CollectionUtils.java
                        ListUtils.java MapUtils.java PredicateUtils.java
                        src/java/org/apache/commons/collections/BufferUtils.java
                        src/java/org/apache/commons/collections/CollectionUtils.java
                        src/java/org/apache/commons/collections/ListUtils.java
                        src/java/org/apache/commons/collections/MapUtils.java
                        src/java/org/apache/commons/collections/PredicateUtils.java
                        src/test/org/apache/commons/collections/TestAll.java
                        src/test/org/apache/commons/collections/TestCollectionUtils.java
                        src/test/org/apache/commons/collections/TestList.java
               collections/src/test/org/apache/commons/collections
                        TestAll.java TestCollectionUtils.java TestList.java
                        src/java/org/apache/commons/collections/BufferUtils.java
                        src/java/org/apache/commons/collections/CollectionUtils.java
                        src/java/org/apache/commons/collections/ListUtils.java
                        src/java/org/apache/commons/collections/MapUtils.java
                        src/java/org/apache/commons/collections/PredicateUtils.java
                        src/test/org/apache/commons/collections/TestAll.java
                        src/test/org/apache/commons/collections/TestCollectionUtils.java
                        src/test/org/apache/commons/collections/TestList.java
  Added:       collections/src/java/org/apache/commons/collections
                        BagUtils.java SetUtils.java
                        src/java/org/apache/commons/collections/BagUtils.java
                        src/java/org/apache/commons/collections/SetUtils.java
                        src/test/org/apache/commons/collections/TestBoundedCollection.java
                        src/test/org/apache/commons/collections/TestBufferUtils.java
                        src/test/org/apache/commons/collections/TestListUtils.java
                        src/test/org/apache/commons/collections/TestMapUtils.java
                        src/test/org/apache/commons/collections/TestPredicatedCollection.java
                        src/test/org/apache/commons/collections/TestSetUtils.java
               collections/src/test/org/apache/commons/collections
                        TestBoundedCollection.java TestBufferUtils.java
                        TestListUtils.java TestMapUtils.java
                        TestPredicatedCollection.java TestSetUtils.java
                        src/java/org/apache/commons/collections/BagUtils.java
                        src/java/org/apache/commons/collections/SetUtils.java
                        src/test/org/apache/commons/collections/TestBoundedCollection.java
                        src/test/org/apache/commons/collections/TestBufferUtils.java
                        src/test/org/apache/commons/collections/TestListUtils.java
                        src/test/org/apache/commons/collections/TestMapUtils.java
                        src/test/org/apache/commons/collections/TestPredicatedCollection.java
                        src/test/org/apache/commons/collections/TestSetUtils.java
  Removed:     collections/src/java/org/apache/commons/collections
                        LazyCollections.java
                        src/java/org/apache/commons/collections/LazyCollections.java
               collections/src/test/org/apache/commons/collections
                        src/java/org/apache/commons/collections/LazyCollections.java
  Log:
  Added new decorators, and modified existing decorators to fit the
  conventions outlined in the developer's guide.
  
  Decorators are package-protected inner classes, not part of the public
  API.  Existing lazy and predicated decorators were moved to
  CollectionUtils, ListUtils etc.  New classes SetUtils, BagUtils were
  added for decorators of those types.
  
  New bounded and fixed size decorators were added for appropriate types.
  Unmodifiable and synchronized decorators were added for Buffers and
  Bags.
  
  Unit tests were added where possible.  No unit tests for synchronized
  collection wrappers; not sure how to implement a valid test for proper
  synchronization.
  
  Also, no unit tests for Bag decorators, because the decorator unit tests
  require the TestCollection framework, which won't work with Bag since it
  violates the Collection contract.
  
  Revision  Changes    Path
  1.4       +59 -197   jakarta-commons/collections/src/java/org/apache/commons/collections/BufferUtils.java
  
  Index: BufferUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/BufferUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BufferUtils.java	3 Jul 2002 02:16:48 -0000	1.3
  +++ BufferUtils.java	13 Aug 2002 00:26:51 -0000	1.4
  @@ -74,6 +74,10 @@
   public class BufferUtils {
   
   
  +    private BufferUtils() {
  +    }
  +
  +
       /**
        *  Returns a synchronized buffer backed by the given buffer.
        *  Much like the synchronized collections returned by 
  @@ -113,127 +117,42 @@
           return new SynchronizedBuffer(buf) {
   
               public synchronized boolean add(Object o) {
  -                boolean r = b.add(o);
  +                boolean r = collection.add(o);
                   notify();
                   return r;
               }
   
               public synchronized boolean addAll(Collection c) {
  -                boolean r = b.addAll(c);
  +                boolean r = collection.addAll(c);
                   notifyAll();
                   return r;
               }
   
               public synchronized Object get() {
  -                while (b.isEmpty()) {
  +                while (collection.isEmpty()) {
                       try {
                           wait();
                       } catch (InterruptedException e) {
                           throw new BufferUnderflowException();
                       }
                   }
  -                return b.get();
  +                return ((Buffer)collection).get();
               }
   
               public synchronized Object remove() {
  -                while (b.isEmpty()) {
  +                while (collection.isEmpty()) {
                       try {
                           wait();
                       } catch (InterruptedException e) {
                           throw new BufferUnderflowException();
                       }
                   }
  -                return b.remove();
  +                return ((Buffer)collection).remove();
               }
           };
       }
   
   
  -    private static class SynchronizedBuffer implements Buffer {
  -
  -            Buffer b;
  -
  -
  -            public SynchronizedBuffer(Buffer b) {
  -                 this.b = b;
  -            }
  -
  -            public synchronized int size() {
  -                return b.size();
  -            }
  -
  -            public synchronized boolean isEmpty() {
  -                return b.isEmpty();
  -            }
  -
  -            public synchronized boolean contains(Object o) {
  -                return b.contains(o);
  -            }
  -
  -            public Iterator iterator() {
  -                return b.iterator();
  -            }
  -
  -            public synchronized Object[] toArray() {
  -                return b.toArray();
  -            }
  -
  -            public synchronized Object[] toArray(Object[] o) {
  -                return b.toArray(o);
  -            }
  -
  -            public synchronized boolean add(Object o) {
  -                return b.add(o);
  -            }
  -
  -            public synchronized boolean remove(Object o) {
  -                return b.remove(o);
  -            }
  -
  -            public synchronized boolean containsAll(Collection c) {
  -                return b.containsAll(c);
  -            }
  -
  -            public synchronized boolean addAll(Collection c) {
  -                return b.addAll(c);
  -            }
  -
  -            public synchronized boolean removeAll(Collection c) {
  -                return b.removeAll(c);
  -            }
  -
  -            public synchronized boolean retainAll(Collection c) {
  -                return b.retainAll(c);
  -            }
  -
  -            public synchronized void clear() {
  -                b.clear();
  -            }
  -
  -            public synchronized boolean equals(Object o) {
  -                return b.equals(o);
  -            }
  -
  -            public synchronized int hashCode() {
  -                return b.hashCode();
  -            }
  -
  -            public synchronized String toString() {
  -                return b.toString();
  -            }
  -
  -            public synchronized Object get() {
  -                return b.get();
  -            }
  -
  -            public synchronized Object remove() {
  -                return b.remove();
  -            }          
  -
  -        
  -    }
  -
  -
       /**
        *  Returns an unmodifiable buffer backed by the given buffer.
        *
  @@ -241,35 +160,7 @@
        *  @return  an unmodifiable buffer backed by that buffer
        */
       public static Buffer unmodifiableBuffer(Buffer b) {
  -        return new BufferDecorator(b) {
  -            public boolean addAll(Collection c) {
  -                throw new UnsupportedOperationException();
  -            } 
  -
  -            public boolean removeAll(Collection c) {
  -                throw new UnsupportedOperationException();
  -            } 
  -
  -            public boolean retainAll(Collection c) {
  -                throw new UnsupportedOperationException();
  -            } 
  -
  -            public boolean add(Object o) {
  -                throw new UnsupportedOperationException();
  -            } 
  -
  -            public boolean remove(Object o) {
  -                throw new UnsupportedOperationException();
  -            } 
  -
  -            public void clear() {
  -                throw new UnsupportedOperationException();
  -            }
  -
  -            public Object remove() {
  -                throw new UnsupportedOperationException();
  -            }
  -        };
  +        return new UnmodifiableBuffer(b);
       }
   
   
  @@ -285,116 +176,87 @@
        *  @return  a predicated buffer
        */
       public static Buffer predicatedBuffer(Buffer buf, final Predicate p) {
  -        if (buf == null) {
  -            throw new IllegalArgumentException("Buffer must not be null.");
  -        }
  -        if (p == null) {
  -            throw new IllegalArgumentException("Predicate must not be null.");
  -        }
  -        return new BufferDecorator(buf) {
  -
  -            public boolean add(Object o) {
  -                test(o);
  -                return b.add(o);
  -            }
  +        return new PredicatedBuffer(buf, p);
  +    }
   
  -            public boolean addAll(Collection c) {
  -                Iterator iterator = c.iterator();
  -                while (iterator.hasNext()) {
  -                    test(iterator.next());
  -                }
  -                return b.addAll(c);
  -            }
   
  -            private void test(Object o) {
  -                if (!p.evaluate(o)) {
  -                    throw new IllegalArgumentException("Invalid: " + o);
  -                }
  -            }
  -        };
  +    public static Buffer boundedBuffer(Buffer buf, int maxSize) {
  +        return new BoundedBuffer(buf, maxSize);
       }
   
   
  -    private static class BufferDecorator implements Buffer {
  -
  -        Buffer b;
  +    private static class SynchronizedBuffer 
  +    extends CollectionUtils.SynchronizedCollection
  +    implements Buffer {
   
  -        BufferDecorator(Buffer b) {
  -            this.b = b;
  +        public SynchronizedBuffer(Buffer b) {
  +            super(b);
           }
   
  -        public int size() {
  -            return b.size();
  +        public synchronized Object get() {
  +            return ((Buffer)collection).get();
           }
   
  -        public boolean isEmpty() {
  -            return b.isEmpty();
  -        }
  +        public synchronized Object remove() {
  +            return ((Buffer)collection).remove();
  +        }        
  +    }
   
  -        public boolean contains(Object o) {
  -            return b.contains(o);
  -        }
   
  -        public Iterator iterator() {
  -            return b.iterator();
  -        }
  +    private static class UnmodifiableBuffer 
  +    extends CollectionUtils.UnmodifiableCollection
  +    implements Buffer {
   
  -        public Object[] toArray() {
  -            return b.toArray();
  +        public UnmodifiableBuffer(Buffer b) {
  +            super(b);
           }
   
  -        public Object[] toArray(Object[] o) {
  -            return b.toArray(o);
  +        public Object get() {
  +            return ((Buffer)collection).get();
           }
   
  -        public boolean add(Object o) {
  -            return b.add(o);
  +        public Object remove() {
  +            throw new UnsupportedOperationException();
           }
   
  -        public boolean remove(Object o) {
  -            return b.remove(o);
  -        }
  +    }
   
  -        public boolean containsAll(Collection c) {
  -            return b.containsAll(c);
  -        }
   
  -        public boolean addAll(Collection c) {
  -            return b.addAll(c);
  -        }
  +    private static class PredicatedBuffer 
  +    extends CollectionUtils.PredicatedCollection
  +    implements Buffer {
   
  -        public boolean removeAll(Collection c) {
  -            return b.removeAll(c);
  +        public PredicatedBuffer(Buffer b, Predicate p) {
  +            super(b, p);
           }
   
  -        public boolean retainAll(Collection c) {
  -            return b.retainAll(c);
  +        public Object get() {
  +            return ((Buffer)collection).get();
           }
   
  -        public void clear() {
  -            b.clear();
  +        public Object remove() {
  +            return ((Buffer)collection).remove();
           }
   
  -        public boolean equals(Object o) {
  -            return b.equals(o);
  -        }
  +    }
   
  -        public int hashCode() {
  -            return b.hashCode();
  -        }
   
  -        public String toString() {
  -            return b.toString();
  +    private static class BoundedBuffer
  +    extends CollectionUtils.BoundedCollection
  +    implements Buffer {
  +
  +        public BoundedBuffer(Buffer b, int maxSize) {
  +            super(b, maxSize);
           }
   
           public Object get() {
  -            return b.get();
  +            return ((Buffer)collection).get();
           }
   
           public Object remove() {
  -            return b.remove();
  +            return ((Buffer)collection).remove();
           }
  -    }
   
  +    }
   
   }
  
  
  
  1.10      +336 -4    jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java
  
  Index: CollectionUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CollectionUtils.java	10 Aug 2002 00:36:34 -0000	1.9
  +++ CollectionUtils.java	13 Aug 2002 00:26:51 -0000	1.10
  @@ -555,4 +555,336 @@
           }
           return 0;
       }
  +
  +
  +    /**
  +     *  Base class for collection decorators.  I decided to do it this way
  +     *  because it seemed to result in the most reuse.  
  +     *
  +     *  Inner class tree looks like:
  +     *       CollectionWrapper
  +     *          PredicatedCollection
  +     *             PredicatedSet
  +     *             PredicatedList
  +     *             PredicatedBag
  +     *          BoundedCollection
  +     *             BoundedSet
  +     *             BoundedList
  +     *             BoundedBag
  +     *          LazyCollection
  +     *             LazyList
  +     *             LazyBag
  +     *       SynchronizedCollection
  +     *          SynchronizedBuffer
  +     *          SynchronizedBag
  +     */
  +    static class CollectionWrapper implements Collection {
  +
  +        final protected Collection collection;
  +
  +        public CollectionWrapper(Collection collection) {
  +            if (collection == null) {
  +                throw new IllegalArgumentException("Collection must not be null.");
  +            }
  +            this.collection = collection;
  +        }
  +
  +        public int size() {
  +            return collection.size();
  +        }
  +
  +        public boolean isEmpty() {
  +            return collection.isEmpty();
  +        }
  +
  +        public boolean contains(Object o) {
  +            return collection.contains(o);
  +        }
  +
  +        public Iterator iterator() {
  +            return collection.iterator();
  +        }
  +
  +        public Object[] toArray() {
  +            return collection.toArray();
  +        }
  +
  +        public Object[] toArray(Object[] o) {
  +            return collection.toArray(o);
  +        }
  +
  +        public boolean add(Object o) {
  +            return collection.add(o);
  +        }
  +
  +        public boolean remove(Object o) {
  +            return collection.remove(o);
  +        }
  +
  +        public boolean containsAll(Collection c2) {
  +            return collection.containsAll(c2);
  +        }
  +
  +        public boolean addAll(Collection c2) {
  +            return collection.addAll(c2);
  +        }
  +
  +        public boolean removeAll(Collection c2) {
  +            return collection.removeAll(c2);
  +        }
  +
  +        public boolean retainAll(Collection c2) {
  +            return collection.retainAll(c2);
  +        }
  +
  +        public void clear() {
  +            collection.clear();
  +        }
  +
  +        public boolean equals(Object o) {
  +            if (o == this) return true;
  +            return collection.equals(o);
  +        }
  +
  +        public int hashCode() {
  +            return collection.hashCode();
  +        }
  +
  +        public String toString() {
  +            return collection.toString();
  +        }
  +
  +    }
  +
  +
  +    static class PredicatedCollection extends CollectionWrapper {
  +
  +        final protected Predicate predicate;
  +
  +        public PredicatedCollection(Collection c, Predicate p) {
  +            super(c);
  +            if (p == null) {
  +                throw new IllegalArgumentException("Predicate must not be null.");
  +            }
  +            this.predicate = p;
  +            for (Iterator iter = c.iterator(); iter.hasNext(); ) {
  +                validate(iter.next());
  +            }
  +        }
  +
  +        public boolean add(Object o) {
  +            validate(o);
  +            return collection.add(o);
  +        }
  +
  +
  +        public boolean addAll(Collection c2) {
  +            for (Iterator iter = c2.iterator(); iter.hasNext(); ) {
  +                validate(iter.next());
  +            }
  +            return collection.addAll(c2);
  +        }
  +
  +
  +        protected void validate(Object o) {
  +            if (!predicate.evaluate(o)) {
  +                throw new IllegalArgumentException("Object failed predicate.");
  +            }
  +        }
  +
  +    }
  +
  +
  +    static class UnmodifiableCollection extends CollectionWrapper {
  +
  +
  +        public UnmodifiableCollection(Collection c) {
  +            super(c);
  +        }
  +
  +        public boolean add(Object o) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public boolean addAll(Collection c) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public boolean remove(Object o) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public boolean removeAll(Collection c) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public boolean retainAll(Collection c) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public void clear() {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public Iterator iterator() {
  +            return new UnmodifiableIterator(collection.iterator());
  +        }
  +
  +    }
  +
  +
  +    static class BoundedCollection extends CollectionWrapper {
  +
  +        final protected int maxSize;
  +
  +
  +        public BoundedCollection(Collection c, int maxSize) {
  +            super(c);
  +            this.maxSize = maxSize;
  +        }
  +
  +        public boolean add(Object o) {
  +            if (!collection.contains(o)) {
  +                validate(1);
  +            }
  +            return collection.add(o);
  +        }
  +
  +        public boolean addAll(Collection c) {
  +            int delta = 0;
  +            for (Iterator iter = c.iterator(); iter.hasNext(); ) {
  +                if (!collection.contains(iter.next())) delta++;
  +            }
  +            validate(delta);
  +            return collection.addAll(c);
  +        }
  +
  +
  +        protected void validate(int delta) {
  +            if (delta + size() > maxSize) {
  +                throw new IllegalStateException("Maximum size reached.");
  +            }
  +        }
  +
  +    }
  +
  +
  +
  +
  +    static class SynchronizedCollection {
  +
  +        final protected Collection collection;
  +
  +        public SynchronizedCollection(Collection collection) {
  +            if (collection == null) {
  +                throw new IllegalArgumentException("Collection must not be null.");
  +            }
  +            this.collection = collection;
  +        }
  +
  +        public synchronized int size() {
  +            return collection.size();
  +        }
  +
  +        public synchronized boolean isEmpty() {
  +            return collection.isEmpty();
  +        }
  +
  +        public synchronized boolean contains(Object o) {
  +            return collection.contains(o);
  +        }
  +
  +        public Iterator iterator() {
  +            return collection.iterator();
  +        }
  +
  +        public synchronized Object[] toArray() {
  +            return collection.toArray();
  +        }
  +
  +        public synchronized Object[] toArray(Object[] o) {
  +            return collection.toArray(o);
  +        }
  +
  +        public synchronized boolean add(Object o) {
  +            return collection.add(o);
  +        }
  +
  +        public synchronized boolean remove(Object o) {
  +            return collection.remove(o);
  +        }
  +
  +        public synchronized boolean containsAll(Collection c2) {
  +            return collection.containsAll(c2);
  +        }
  +
  +        public synchronized boolean addAll(Collection c2) {
  +            return collection.addAll(c2);
  +        }
  +
  +        public synchronized boolean removeAll(Collection c2) {
  +            return collection.removeAll(c2);
  +        }
  +
  +        public synchronized boolean retainAll(Collection c2) {
  +            return collection.retainAll(c2);
  +        }
  +
  +        public synchronized void clear() {
  +            collection.clear();
  +        }
  +
  +        public synchronized boolean equals(Object o) {
  +            return collection.equals(o);
  +        }
  +
  +        public synchronized int hashCode() {
  +            return collection.hashCode();
  +        }
  +
  +        public synchronized String toString() {
  +            return collection.toString();
  +        }
  +
  +    }
  +
  +
  +    static class UnmodifiableIterator implements Iterator {
  +
  +        final protected Iterator iterator;
  +
  +        public UnmodifiableIterator(Iterator iterator) {
  +            this.iterator = iterator;
  +        }
  +
  +        public boolean hasNext() {
  +            return iterator.hasNext();
  +        }
  +
  +        public Object next() {
  +            return iterator.next();
  +        }
  +
  +        public void remove() {
  +            throw new UnsupportedOperationException();
  +        }
  +    }
  +
  +
  +    /**
  +     *  Returns a predicated collection backed by the given collection.
  +     *  Only objects that pass the test in the given predicate can be 
  +     *  added to the collection.
  +     *  It is important not to use the original collection after invoking this 
  +     *  method, as it is a backdoor for adding unvalidated objects.
  +     *
  +     *  @param b  the collection to predicate
  +     *  @param p  the predicate for the collection
  +     *  @return  a predicated collection backed by the given collection
  +     */
  +    public static Collection predicatedCollection(Collection c, Predicate p) {
  +        return new PredicatedCollection(c, p);
  +    }
  +
  +
   }
  
  
  
  1.5       +442 -5    jakarta-commons/collections/src/java/org/apache/commons/collections/ListUtils.java
  
  Index: ListUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/ListUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ListUtils.java	12 Jun 2002 03:59:15 -0000	1.4
  +++ ListUtils.java	13 Aug 2002 00:26:51 -0000	1.5
  @@ -61,16 +61,19 @@
   package org.apache.commons.collections;
   
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.ListIterator;
   
   /**
  - * Miscelaneous utilities to manipulate Lists.
  + * Contains static utility methods and decorators for {@link List} 
  + * instances.
    *
    * @since 1.0
    * @author  <a href="mailto:fede@apache.org">Federico Barbieri</a>
    * @author  <a href="mailto:donaldp@apache.org">Peter Donald</a>
  - * @deprecated See {@link org.apache.commons.collections.CollectionUtils}.
  + * @author Paul Jack
    */
   public class ListUtils
   {
  @@ -117,4 +120,438 @@
           result.addAll( list2 );
           return result;
       }
  +
  +
  +    static class ListIteratorWrapper implements ListIterator {
  +
  +        final protected ListIterator iterator;
  +
  +        public ListIteratorWrapper(ListIterator iterator) {
  +            this.iterator = iterator;
  +        }
  +
  +        public boolean hasNext() {
  +            return iterator.hasNext();
  +        }
  +
  +        public Object next() {
  +            return iterator.next();
  +        }
  +
  +        public boolean hasPrevious() {
  +            return iterator.hasPrevious();
  +        }
  +
  +        public Object previous() {
  +            return iterator.previous();
  +        }
  +
  +        public int nextIndex() {
  +            return iterator.nextIndex();
  +        }
  +
  +        public int previousIndex() {
  +            return iterator.previousIndex();
  +        }
  +
  +        public void remove() {
  +            iterator.remove();
  +        }
  +
  +        public void set(Object o) {
  +            iterator.set(o);
  +        }
  +
  +        public void add(Object o) {
  +            iterator.add(o);
  +        }
  +
  +    }
  +
  +
  +    static class PredicatedList extends CollectionUtils.PredicatedCollection
  +    implements List {
  +
  +        public PredicatedList(List list, Predicate p) {
  +            super(list, p);
  +        }
  +
  +        public boolean addAll(int i, Collection c) {
  +            for (Iterator iter = c.iterator(); iter.hasNext(); ) {
  +                validate(iter.next());
  +            }
  +            return getList().addAll(i, c);
  +        }
  +
  +        public Object get(int i) {
  +            return getList().get(i);
  +        }
  +
  +        public Object set(int i, Object o) {
  +            validate(o);
  +            return getList().set(i, o);
  +        }
  +
  +        public void add(int i, Object o) {
  +            validate(o);
  +            getList().add(i, o);
  +        }
  +
  +        public Object remove(int i) {
  +            return getList().remove(i);
  +        }
  +
  +        public int indexOf(Object o) {
  +            return getList().indexOf(o);
  +        }
  +
  +        public int lastIndexOf(Object o) {
  +            return getList().lastIndexOf(o);
  +        }
  +
  +        public ListIterator listIterator() {
  +            return listIterator(0);
  +        }
  +
  +        public ListIterator listIterator(int i) {
  +            return new ListIteratorWrapper(getList().listIterator(i)) {
  +                public void add(Object o) {
  +                    validate(o);
  +                    iterator.add(o);
  +                }
  +
  +                public void set(Object o) {
  +                    validate(o);
  +                    iterator.set(o);
  +                }
  +            };
  +        }
  +
  +        public List subList(int i1, int i2) {
  +            List sub = getList().subList(i1, i2);
  +            return new PredicatedList(sub, predicate);
  +        }
  +
  +        private List getList() {
  +            return (List)collection;
  +        }
  +
  +    }
  +
  +
  +    static class FixedSizeList extends CollectionUtils.UnmodifiableCollection
  +    implements List {
  +
  +        public FixedSizeList(List list) {
  +            super(list);
  +        }
  +
  +        public boolean addAll(int i, Collection c) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public Object get(int i) {
  +            return getList().get(i);
  +        }
  +
  +        public Object set(int i, Object o) {
  +            return getList().set(i, o);
  +        }
  +
  +        public void add(int i, Object o) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public Object remove(int i) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public int indexOf(Object o) {
  +            return getList().indexOf(o);
  +        }
  +
  +        public int lastIndexOf(Object o) {
  +            return getList().lastIndexOf(o);
  +        }
  +
  +        public ListIterator listIterator() {
  +            return listIterator(0);
  +        }
  +
  +        public ListIterator listIterator(int i) {
  +            return new ListIteratorWrapper(getList().listIterator(i)) {
  +                public void remove() {
  +                    throw new UnsupportedOperationException();
  +                }
  +
  +                public void add(Object o) {
  +                    throw new UnsupportedOperationException();
  +                }
  +
  +                public void remove(Object o) {
  +                    throw new UnsupportedOperationException();
  +                }
  +            };
  +        }
  +
  +        public List subList(int i1, int i2) {
  +            List sub = getList().subList(i1, i2);
  +            return new FixedSizeList(sub);
  +        }
  +
  +        private List getList() {
  +            return (List)collection;
  +        }
  +
  +    }
  +
  +
  +    static class BoundedList extends CollectionUtils.CollectionWrapper 
  +    implements List {
  +
  +        final protected int maxSize;
  +
  +        public BoundedList(List list, int maxSize) {
  +            super(list);
  +            this.maxSize = maxSize;
  +        }
  +
  +        public boolean addAll(Collection c) {
  +            validate(c.size());
  +            return collection.addAll(c);
  +        }
  +
  +        public boolean add(Object o) {
  +            validate(1);
  +            return collection.add(o);
  +        }
  +
  +        public boolean addAll(int i, Collection c) {
  +            validate(c.size());
  +            return getList().addAll(i, c);
  +        }
  +
  +        public void add(int i, Object o) {
  +            validate(1);
  +            getList().add(i, o);
  +        }
  +
  +        public Object get(int i) {
  +            return getList().get(i);
  +        }
  +
  +        public Object set(int i, Object o) {
  +            return getList().set(i, o);
  +        }
  +
  +        public Object remove(int i) {
  +            return getList().remove(i);
  +        }
  +
  +        public int indexOf(Object o) {
  +            return getList().indexOf(o);
  +        }
  +
  +        public int lastIndexOf(Object o) {
  +            return getList().lastIndexOf(o);
  +        }
  +
  +        public ListIterator listIterator() {
  +            return listIterator(0);
  +        }
  +
  +        public ListIterator listIterator(int i) {
  +            return new ListIteratorWrapper(getList().listIterator(i)) {
  +                public void add(Object o) {
  +                    validate(1);
  +                    iterator.add(o);
  +                }
  +            };
  +        }
  +
  +        public List subList(int i1, int i2) {
  +            return getList().subList(i1, i2);
  +        }
  +
  +        private List getList() {
  +            return (List)collection;
  +        }
  +
  +        private void validate(int delta) {
  +            if (delta + size() > maxSize) {
  +                throw new IllegalStateException("Maximum size reached.");
  +            }
  +        }
  +
  +    }
  +
  +
  +    static class LazyList extends CollectionUtils.CollectionWrapper 
  +    implements List {
  +
  +        final protected SimpleObjectFactory factory;
  +
  +        public LazyList(List list, SimpleObjectFactory factory) {
  +            super(list);
  +            this.factory = factory;
  +        }
  +
  +        
  +        /* Proxy method to the impl's get method. With the exception that if it's out
  +         * of bounds, then the collection will grow, leaving place-holders in its
  +         * wake, so that an item can be set at any given index. Later the
  +         * place-holders are removed to return to a pure collection.
  +         *
  +         * If there's a place-holder at the index, then it's replaced with a proper
  +         * object to be used.
  +         */
  +        public Object get(int index) {
  +            Object obj;
  +            if (index < (getList().size())) {
  +            /* within bounds, get the object */
  +                obj = getList().get(index);
  +                if (obj == null) {
  +                    /* item is a place holder, create new one, set and return */
  +                    obj = this.factory.createObject();
  +                    this.getList().set(index, obj);
  +                    return obj;
  +                } else {
  +                    /* good and ready to go */
  +                    return obj;
  +                }
  +            } else {
  +                /* we have to grow the list */
  +                for (int i = getList().size(); i < index; i++) {
  +                    getList().add(null);
  +                }
  +                /* create our last object, set and return */
  +                obj = this.factory.createObject();
  +                getList().add(obj);
  +                return obj;
  +            }
  +        }
  +
  +
  +        /* proxy the call to the provided list implementation. */
  +        public List subList(int fromIndex, int toIndex) {
  +            /* wrap the returned sublist so it can continue the functionality */
  +            return new LazyList(getList().subList(fromIndex, toIndex), factory);
  +        }
  +
  +        public boolean addAll(int i, Collection c) {
  +            return getList().addAll(i, c);
  +        }
  +
  +        public Object set(int i, Object o) {
  +            return getList().set(i, o);
  +        }
  +
  +        public void add(int i, Object o) {
  +            getList().add(i, o);
  +        }
  +
  +        public Object remove(int i) {
  +            return getList().remove(i);
  +        }
  +
  +        public int indexOf(Object o) {
  +            return getList().indexOf(o);
  +        }
  +
  +        public int lastIndexOf(Object o) {
  +            return getList().lastIndexOf(o);
  +        }
  +
  +        public ListIterator listIterator() {
  +            return getList().listIterator();
  +        }
  +
  +        public ListIterator listIterator(int i) {
  +            return getList().listIterator(i);
  +        }
  +
  +        private List getList() {
  +            return (List)collection;
  +        }
  +
  +    }
  +
  +
  +    /**
  +     *  Returns a predicated list backed by the given list.  Only objects
  +     *  that pass the test in the given predicate can be added to the list.
  +     *  It is important not to use the original list after invoking this 
  +     *  method, as it is a backdoor for adding unvalidated objects.
  +     *
  +     *  @param list  the list to predicate
  +     *  @param p  the predicate for the list
  +     *  @return  a predicated list backed by the given list
  +     */
  +    public static List predicatedList(List list, Predicate p) {
  +        return new PredicatedList(list, p);
  +    }
  +
  +
  +    /**
  +     *  Returns a "lazy" list whose elements will be created on demand.<P>
  +     *  <P>
  +     *  When the index passed to the returned list's {@link List#get(int) get}
  +     *  method is greater than the list's size, then the factory will be used
  +     *  to create a new object and that object will be inserted at that index.
  +     *  <P>
  +     *  For instance:
  +     *
  +     *  <Pre>
  +     *  SimpleObjectFactory factory = new SimpleObjectFactory() {
  +     *      public Object createObject() {
  +     *          return new Date();
  +     *      }
  +     *  }
  +     *  List lazy = ListUtils.lazyList(new ArrayList(), factory);
  +     *  Object obj = lazy.get(3);
  +     *  </Pre>
  +     *
  +     *  After the above code is executed, <Code>obj</Code> will contain
  +     *  a new <Code>Date</Code> instance.  Furthermore, that <Code>Date</Code>
  +     *  instance is the fourth element in the list.  The first, second, 
  +     *  and third element are all set to <Code>null</Code>.<P>
  +     *
  +     *  @param list  the list to make lazy
  +     *  @param factory  the factory for creating new objects
  +     *  @return a lazy list backed by the given list
  +     */
  +    public static List lazyList(List list, SimpleObjectFactory factory) {
  +        return new LazyList(list, factory);
  +    }
  +
  +
  +    /**
  +     *  Returns a fixed-sized list backed by the given list.
  +     *  Elements may not be added or removed from the returned list, but 
  +     *  existing elements can be changed (for instance, via the 
  +     *  {@link List#set(int,Object)} method).
  +     *
  +     *  @param list  the list whose size to fix
  +     *  @return  a fixed-size list backed by that list
  +     */
  +    public static List fixedSizeList(List list) {
  +        return new FixedSizeList(list);
  +    }
  +
  +
  +    /**
  +     *  Returns a bounded list backed by the given list.
  +     *  New elements may only be added to the returned list if its 
  +     *  size is less than the specified maximum; otherwise, an
  +     *  {@link IllegalStateException} will be thrown.
  +     *
  +     *  @param list  the list whose size to bind
  +     *  @param maxSize  the maximum size of the returned list
  +     *  @return  a bounded list 
  +     */
  +    public static List boundedList(List list, int maxSize) {
  +        return new BoundedList(list, maxSize);
  +    }
  +
  +
   }
  
  
  
  1.6       +473 -4    jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java
  
  Index: MapUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MapUtils.java	12 Jun 2002 03:59:15 -0000	1.5
  +++ MapUtils.java	13 Aug 2002 00:26:51 -0000	1.6
  @@ -73,6 +73,7 @@
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
     * @author <a href="mailto:nissim@nksystems.com">Nissim Karpenstein</a>
     * @author <a href="mailto:knielsen@apache.org">Kasper Nielsen</a>
  +  * @author Paul Jack
     */
   public class MapUtils {
   
  @@ -397,7 +398,7 @@
       }
       
       protected static void logInfo(Exception e) {
  -        // XXXX: should probably use log4j here instead...
  +        // mapX: should probably use log4j here instead...
           System.out.println( "INFO: Exception: " + e );
       }
   
  @@ -425,4 +426,472 @@
       }
   
   
  +    static class PredicatedMap extends ProxyMap {
  +
  +        final protected Predicate keyPredicate;
  +        final protected Predicate valuePredicate;
  +
  +
  +        public PredicatedMap(Map map, Predicate keyPred, Predicate valuePred) {
  +            super(map);
  +            this.keyPredicate = keyPred;
  +            this.valuePredicate = valuePred;
  +            Iterator iter = map.entrySet().iterator();
  +            while (iter.hasNext()) {
  +                Map.Entry entry = (Map.Entry)iter.next();
  +                Object key = entry.getKey();
  +                Object value = entry.getValue();
  +                validate(key, value);
  +            }
  +        }
  +
  +        public Object put(Object key, Object value) {
  +            validate(key, value);
  +            return map.put(key, value);
  +        }
  +
  +        public void putAll(Map m) {
  +            Iterator iter = m.entrySet().iterator();
  +            while (iter.hasNext()) {
  +                Map.Entry entry = (Map.Entry)iter.next();
  +                Object key = entry.getKey();
  +                Object value = entry.getValue();
  +                validate(key, value);
  +            }
  +            map.putAll(m);
  +        }
  +
  +        public Set entrySet() {
  +            return new PredicatedMapEntrySet(map.entrySet(), valuePredicate);
  +        }
  +
  +
  +        private void validate(Object key, Object value) {
  +            if (!keyPredicate.evaluate(key)) {
  +                throw new IllegalArgumentException("Invalid key.");
  +            }
  +            if (!valuePredicate.evaluate(value)) {
  +                throw new IllegalArgumentException("Invalid value.");
  +            }
  +        }
  +    }
  +
  +
  +    static class PredicatedMapEntrySet 
  +    extends CollectionUtils.CollectionWrapper
  +    implements Set {
  +
  +        final private Predicate predicate;
  +
  +        public PredicatedMapEntrySet(Set set, Predicate p) {
  +            super(set);
  +            this.predicate = p;
  +        }
  +
  +        public Iterator iterator() {
  +            final Iterator iterator = collection.iterator();
  +            return new Iterator() {
  +                public boolean hasNext() {
  +                    return iterator.hasNext();
  +                }
  +
  +                public Object next() {
  +                    Map.Entry entry = (Map.Entry)iterator.next();
  +                    return new PredicatedMapEntry(entry, predicate);
  +                }
  +
  +                public void remove() {
  +                    iterator.remove();
  +                }
  +            };
  +        }
  +    }
  +
  +
  +    static class PredicatedMapEntry implements Map.Entry {
  +
  +        final private Map.Entry entry;
  +        final private Predicate predicate;
  +
  +
  +        public PredicatedMapEntry(Map.Entry entry, Predicate p) {
  +            this.entry = entry;
  +            this.predicate = p;
  +        }
  +
  +        public boolean equals(Object o) {
  +            return entry.equals(o);
  +        }
  +
  +        public int hashCode() {
  +            return entry.hashCode();
  +        }
  +
  +        public String toString() {
  +            return entry.toString();
  +        }
  +
  +        public Object getKey() {
  +            return entry.getKey();
  +        }
  +
  +        public Object getValue() {
  +            return entry.getValue();
  +        }
  +
  +        public Object setValue(Object o) {
  +            if (!predicate.evaluate(o)) {
  +                throw new IllegalArgumentException("Invalid value.");
  +            }
  +            return entry.setValue(o);
  +        }
  +    }
  +
  +
  +    static class BoundedMap extends ProxyMap {
  +
  +        final protected int maxSize;
  +
  +        public BoundedMap(Map map, int maxSize) {
  +            super(map);
  +            this.maxSize = maxSize;
  +        }
  +
  +        public Object put(Object key, Object value) {
  +            if (!containsKey(key)) validate(1);
  +            return map.put(key, value);
  +        }
  +
  +        public void putAll(Map m) {
  +            int delta = 0;
  +            for (Iterator iter = m.keySet().iterator(); iter.hasNext(); ) {
  +                 if (!map.containsKey(iter.next())) delta++;
  +            }
  +            validate(delta);
  +            map.putAll(m);
  +        }
  +
  +
  +        protected void validate(int delta) {
  +            if (map.size() + delta > maxSize) {
  +                throw new IllegalStateException("Maximum size reached.");
  +            }
  +        }
  +    }
  +
  +
  +    static class FixedSizeMap extends ProxyMap {
  +
  +        public FixedSizeMap(Map map) {
  +            super(map);
  +        }
  +
  +
  +        public Object put(Object key, Object value) {
  +            if (!map.containsKey(key)) {
  +                throw new IllegalArgumentException("Can't add new keys.");
  +            }
  +            return map.put(key, value);
  +        }
  +
  +
  +        public void putAll(Map m) {
  +            for (Iterator iter = m.keySet().iterator(); iter.hasNext(); ) {
  +                if (!map.containsKey(iter.next())) {
  +                    throw new IllegalArgumentException("Can't add new keys.");
  +                }
  +            }
  +            map.putAll(m);
  +        }
  +
  +    }
  +
  +
  +    static class LazyMap extends ProxyMap {
  +
  +        final protected SimpleObjectFactory factory;
  +
  +
  +        public LazyMap(Map map, SimpleObjectFactory factory) {
  +            super(map);
  +            this.factory = factory;
  +        }
  +
  +
  +        public Object get(Object key) {
  +            if (!map.containsKey(key)) {
  +                Object value = factory.createObject();
  +                map.put(key, value);
  +                return value;
  +            }
  +            return map.get(key);
  +        }
  +
  +    }
  +
  +
  +
  +    static class PredicatedSortedMap extends PredicatedMap 
  +    implements SortedMap {
  +
  +        public PredicatedSortedMap(SortedMap map, Predicate k, Predicate v) {
  +            super(map, k, v);
  +        }
  +
  +        public Object firstKey() {
  +            return getSortedMap().firstKey();
  +        }
  +
  +
  +        public Object lastKey() {
  +            return getSortedMap().lastKey();
  +        }
  +
  +
  +        public Comparator comparator() {
  +            return getSortedMap().comparator();
  +        }
  +
  +
  +        public SortedMap subMap(Object o1, Object o2) {
  +            SortedMap sub = getSortedMap().subMap(o1, o2);
  +            return new PredicatedSortedMap(sub, keyPredicate, valuePredicate);
  +        }
  +
  +        public SortedMap headMap(Object o1) {
  +            SortedMap sub = getSortedMap().headMap(o1);
  +            return new PredicatedSortedMap(sub, keyPredicate, valuePredicate);
  +        }
  +
  +        public SortedMap tailMap(Object o1) {
  +            SortedMap sub = getSortedMap().tailMap(o1);
  +            return new PredicatedSortedMap(sub, keyPredicate, valuePredicate);
  +        }
  +
  +        private SortedMap getSortedMap() {
  +            return (SortedMap)map;
  +        }
  +
  +    }
  +
  +
  +    static class FixedSizeSortedMap extends FixedSizeMap implements SortedMap {
  +
  +        public FixedSizeSortedMap(SortedMap m) {
  +            super(m);
  +        }
  +
  +        public Object firstKey() {
  +            return getSortedMap().firstKey();
  +        }
  +
  +
  +        public Object lastKey() {
  +            return getSortedMap().lastKey();
  +        }
  +
  +
  +        public Comparator comparator() {
  +            return getSortedMap().comparator();
  +        }
  +
  +
  +        public SortedMap subMap(Object o1, Object o2) {
  +            return new FixedSizeSortedMap(getSortedMap().subMap(o1, o2));
  +        }
  +
  +        public SortedMap headMap(Object o1) {
  +            return new FixedSizeSortedMap(getSortedMap().headMap(o1));
  +        }
  +
  +        public SortedMap tailMap(Object o1) {
  +            return new FixedSizeSortedMap(getSortedMap().tailMap(o1));
  +        }
  +
  +        private SortedMap getSortedMap() {
  +            return (SortedMap)map;
  +        }
  +
  +    }
  +
  +
  +    static class LazySortedMap extends LazyMap implements SortedMap {
  +
  +        public LazySortedMap(SortedMap m, SimpleObjectFactory factory) {
  +            super(m, factory);
  +        }
  +
  +        public Object firstKey() {
  +            return getSortedMap().firstKey();
  +        }
  +
  +
  +        public Object lastKey() {
  +            return getSortedMap().lastKey();
  +        }
  +
  +
  +        public Comparator comparator() {
  +            return getSortedMap().comparator();
  +        }
  +
  +
  +        public SortedMap subMap(Object o1, Object o2) {
  +            return new LazySortedMap(getSortedMap().subMap(o1, o2), factory);
  +        }
  +
  +        public SortedMap headMap(Object o1) {
  +            return new LazySortedMap(getSortedMap().headMap(o1), factory);
  +        }
  +
  +        public SortedMap tailMap(Object o1) {
  +            return new LazySortedMap(getSortedMap().tailMap(o1), factory);
  +        }
  +
  +        private SortedMap getSortedMap() {
  +            return (SortedMap)map;
  +        }
  +
  +    }
  +
  +
  +    /**
  +     *  Returns a predicated map backed by the given map.  Only keys and
  +     *  values that pass the given predicates can be added to the map.
  +     *  It is important not to use the original map after invoking this 
  +     *  method, as it is a backdoor for adding unvalidated objects.
  +     *
  +     *  @param map  the map to predicate
  +     *  @param keyPred  the predicate for keys
  +     *  @param valuePred  the predicate for values
  +     *  @return  a predicated map backed by the given map
  +     */
  +    public static Map predicatedMap(Map map, Predicate keyPred, Predicate valuePred) {
  +        return new PredicatedMap(map, keyPred, valuePred);
  +    }
  +
  +
  +    /**
  +     *  Returns a bounded map backed by the given map.
  +     *  New pairs may only be added to the returned map if its 
  +     *  size is less than the specified maximum; otherwise, an
  +     *  {@link IllegalStateException} will be thrown.
  +     *
  +     *  @param b  the map whose size to bind
  +     *  @param maxSize  the maximum size of the returned map
  +     *  @return  a bounded map 
  +     */
  +    public static Map boundedMap(Map map, int maxSize) {
  +        return new BoundedMap(map, maxSize);
  +    }
  +
  +
  +    /**
  +     *  Returns a fixed-sized map backed by the given map.
  +     *  Elements may not be added or removed from the returned map, but 
  +     *  existing elements can be changed (for instance, via the 
  +     *  {@link Map#put(Object,Object)} method).
  +     *
  +     *  @param map  the map whose size to fix
  +     *  @return  a fixed-size map backed by that map
  +     */
  +    public static Map fixedSizeMap(Map map) {
  +        return new FixedSizeMap(map);
  +    }
  +
  +
  +    /**
  +     *  Returns a "lazy" map whose values will be created on demand.<P>
  +     *  <P>
  +     *  When the key passed to the returned map's {@link Map#get(Object)}
  +     *  method is not present in the map, then the factory will be used
  +     *  to create a new object and that object will become the value
  +     *  associated with that key.
  +     *  <P>
  +     *  For instance:
  +     *
  +     *  <Pre>
  +     *  SimpleObjectFactory factory = new SimpleObjectFactory() {
  +     *      public Object createObject() {
  +     *          return new Date();
  +     *      }
  +     *  }
  +     *  Map lazy = MapUtils.lazyMap(new HashMap(), factory);
  +     *  Object obj = lazy.get("test");
  +     *  </Pre>
  +     *
  +     *  After the above code is executed, <Code>obj</Code> will contain
  +     *  a new <Code>Date</Code> instance.  Furthermore, that <Code>Date</Code>
  +     *  instance is the value for the <Code>test</Code> key.<P>
  +     *
  +     *  @param map  the map to make lazy
  +     *  @param factory  the factory for creating new objects
  +     *  @return a lazy map backed by the given map
  +     */
  +    public static Map lazyMap(Map map, SimpleObjectFactory factory) {
  +        return new LazyMap(map, factory);
  +    }
  +
  +
  +    /**
  +     *  Returns a predicated sorted map backed by the given map.  Only keys and
  +     *  values that pass the given predicates can be added to the map.
  +     *  It is important not to use the original map after invoking this 
  +     *  method, as it is a backdoor for adding unvalidated objects.
  +     *
  +     *  @param map  the map to predicate
  +     *  @param keyPred  the predicate for keys
  +     *  @param valuePred  the predicate for values
  +     *  @return  a predicated map backed by the given map
  +     */
  +    public static SortedMap predicatedSortedMap(SortedMap map, Predicate keyPred, Predicate valuePred) {
  +        return new PredicatedSortedMap(map, keyPred, valuePred);
  +    }
  +
  +
  +    /**
  +     *  Returns a fixed-sized sorted map backed by the given sorted map.
  +     *  Elements may not be added or removed from the returned map, but 
  +     *  existing elements can be changed (for instance, via the 
  +     *  {@link Map#put(Object,Object)} method).
  +     *
  +     *  @param map  the map whose size to fix
  +     *  @return  a fixed-size map backed by that map
  +     */
  +    public static SortedMap fixedSizeSortedMap(SortedMap map) {
  +        return new FixedSizeSortedMap(map);
  +    }
  +
  +
  +    /**
  +     *  Returns a "lazy" sorted map whose values will be created on demand.
  +     *  <P>
  +     *  When the key passed to the returned map's {@link Map#get(Object)}
  +     *  method is not present in the map, then the factory will be used
  +     *  to create a new object and that object will become the value
  +     *  associated with that key.
  +     *  <P>
  +     *  For instance:
  +     *
  +     *  <Pre>
  +     *  SimpleObjectFactory factory = new SimpleObjectFactory() {
  +     *      public Object createObject() {
  +     *          return new Date();
  +     *      }
  +     *  }
  +     *  SortedMap lazy = MapUtils.lazySortedMap(new TreeMap(), factory);
  +     *  Object obj = lazy.get("test");
  +     *  </Pre>
  +     *
  +     *  After the above code is executed, <Code>obj</Code> will contain
  +     *  a new <Code>Date</Code> instance.  Furthermore, that <Code>Date</Code>
  +     *  instance is the value for the <Code>test</Code> key.<P>
  +     *
  +     *  @param map  the map to make lazy
  +     *  @param factory  the factory for creating new objects
  +     *  @return a lazy map backed by the given map
  +     */
  +    public static SortedMap lazySortedMap(SortedMap map, SimpleObjectFactory factory) {
  +        return new LazySortedMap(map, factory);
  +    }
   }
  
  
  
  1.3       +3 -988    jakarta-commons/collections/src/java/org/apache/commons/collections/PredicateUtils.java
  
  Index: PredicateUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/PredicateUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PredicateUtils.java	16 Jun 2002 03:39:40 -0000	1.2
  +++ PredicateUtils.java	13 Aug 2002 00:26:51 -0000	1.3
  @@ -106,112 +106,6 @@
   	}
   
   	/**
  -	 * Create a new Collection that wraps another Collection and validates
  -	 * entries. Only objects that pass the test in the predicate can be
  -	 * added to the list.
  -	 * It is important that the original collection is not used again after
  -	 * this call, as it is a backdoor to add non-validated objects.
  -	 * @param coll  the collection to wrap and restrict
  -	 * @param predicate  the predicate to control what to allow into the collection
  -	 */
  -	public static Collection predicateCollection(Collection coll, Predicate predicate) {
  -         return new PredicateCollection(coll, predicate);
  -    }
  -
  -	/**
  -	 * Create a new List that wraps another List and validates
  -	 * entries. Only objects that pass the test in the predicate can be
  -	 * added to the list.
  -	 * It is important that the original list is not used again after
  -	 * this call, as it is a backdoor to add non-validated objects.
  -	 * @param list  the list to wrap and restrict
  -	 * @param predicate  the predicate to control what to allow into the list
  -	 */
  -	public static List predicateList(List list, Predicate predicate) {
  -         return new PredicateList(list, predicate);
  -    }
  -
  -	/**
  -	 * Create a new Set that wraps another Set and validates
  -	 * entries. Only objects that pass the test in the predicate can be
  -	 * added to the list.
  -	 * It is important that the original set is not used again after
  -	 * this call, as it is a backdoor to add non-validated objects.
  -	 * @param set  the set to wrap and restrict
  -	 * @param predicate  the predicate to control what to allow into the set
  -	 */
  -	public static Set predicateSet(Set set, Predicate predicate) {
  -         return new PredicateSet(set, predicate);
  -    }
  -
  -	/**
  -	 * Create a new SortedSet that wraps another SortedSet and validates
  -	 * entries. Only objects that pass the test in the predicate can be
  -	 * added to the list.
  -	 * It is important that the original set is not used again after
  -	 * this call, as it is a backdoor to add non-validated objects.
  -	 * @param set  the set to wrap and restrict
  -	 * @param predicate  the predicate to control what to allow into the set
  -	 */
  -	public static SortedSet predicateSortedSet(SortedSet set, Predicate predicate) {
  -         return new PredicateSortedSet(set, predicate);
  -    }
  -
  -	/**
  -	 * Create a new Bag that wraps another Bag and validates
  -	 * entries. Only objects that pass the test in the predicate can be
  -	 * added to the list.
  -	 * It is important that the original bag is not used again after
  -	 * this call, as it is a backdoor to add non-validated objects.
  -	 * @param bag  the bag to wrap and restrict
  -	 * @param predicate  the predicate to control what to allow into the bag
  -	 */
  -	public static Bag predicateBag(Bag bag, Predicate predicate) {
  -         return new PredicateBag(bag, predicate);
  -    }
  -
  -	/**
  -	 * Create a new SortedBag that wraps another SortedBag and validates
  -	 * entries. Only objects that pass the test in the predicate can be
  -	 * added to the list.
  -	 * It is important that the original bag is not used again after
  -	 * this call, as it is a backdoor to add non-validated objects.
  -	 * @param bag  the bag to wrap and restrict
  -	 * @param predicate  the predicate to control what to allow into the bag
  -	 */
  -	public static SortedBag predicateSortedBag(SortedBag bag, Predicate predicate) {
  -         return new PredicateSortedBag(bag, predicate);
  -    }
  -
  -	/**
  -	 * Create a new Map that wraps another Map and validates
  -	 * entries. Only objects that pass the test in the predicate can be
  -	 * added to the list.
  -	 * It is important that the original map is not used again after
  -	 * this call, as it is a backdoor to add non-validated objects.
  -	 * @param map  the map to wrap and restrict
  -	 * @param keyPredicate  the predicate to control what to allow into the bag
  -	 * @param valuePredicate  the predicate to control what to allow into the bag
  -	 */
  -	public static Map predicateMap(Map map, Predicate keyPredicate, Predicate valuePredicate) {
  -         return new PredicateMap(map, keyPredicate, valuePredicate);
  -    }
  -
  -	/**
  -	 * Create a new SortedMap that wraps another SortedMap and validates
  -	 * entries. Only objects that pass the test in the predicate can be
  -	 * added to the list.
  -	 * It is important that the original map is not used again after
  -	 * this call, as it is a backdoor to add non-validated objects.
  -	 * @param map  the map to wrap and restrict
  -	 * @param keyPredicate  the predicate to control what to allow into the bag
  -	 * @param valuePredicate  the predicate to control what to allow into the bag
  -	 */
  -	public static SortedMap predicateSortedMap(SortedMap map, Predicate keyPredicate, Predicate valuePredicate) {
  -         return new PredicateSortedMap(map, keyPredicate, valuePredicate);
  -    }
  -
  -	/**
   	 * Create a new predicate that returns true only if both of the passed
   	 * in predicates are true.
   	 * @param predicate1  the first predicate
  @@ -260,885 +154,6 @@
   	    }
   	}
   
  -	/**
  -	 * PredicateCollection validates a Collection
  -	 */
  -	private static class PredicateCollection 
  -			implements Collection, Serializable {
  -			    
  -        /** The predicate to control entry into the collection */
  -        protected final Predicate iPredicate;
  -        /** The collection being wrapped */
  -        protected final Collection iCollection;
  -			    
  -    	/**
  -    	 * Create a new PredicateCollection that wraps another collection.
  -    	 * It is important that the original collection is not used again
  -    	 * after this call, as it is a backdoor to add non-validated objects.
  -    	 * @param coll  the collection to wrap and restrict
  -    	 * @param predicate  the predicate used to validate entry into the list
  -    	 */
  -    	public PredicateCollection(Collection coll, Predicate predicate) {
  -    	    super();
  -    	    if (coll == null) {
  -    	        throw new IllegalArgumentException("Collection to be wrapped must not be null");
  -    	    }
  -    	    if (predicate == null) {
  -    	        throw new IllegalArgumentException("Predicate must not be null");
  -    	    }
  -    	    iPredicate = predicate;
  -    	    iCollection = coll;
  -            Iterator it = iCollection.iterator();
  -            while (it.hasNext()) {
  -                validate(iPredicate, it.next());
  -            }
  -    	}
  -    
  -        /**
  -         * Add an item to the end of the list. If the item is not an instance
  -         * of the list's validation type an exception is thrown. The state of
  -         * the list will be unaltered if an exception is thrown.
  -         * @see Collection#add(Object)
  -         * @param item  the item to add
  -         * @throws IllegalArgumentException if the object is not of a valid type
  -         */
  -        public boolean add(Object item) {
  -            validate(iPredicate, item);
  -            return iCollection.add(item);
  -        }
  -    
  -        /**
  -         * Add a collection to the end of the list. If any of the items in the
  -         * collection is not an instance of the list's validation type an
  -         * exception is thrown. The state of the list will be unaltered if an
  -         * exception is thrown.
  -         * @see Collection#addAll(Collection)
  -         * @param coll  the collection to add
  -         * @throws IllegalArgumentException if the object is not of a valid type
  -         */
  -        public boolean addAll(Collection coll) {
  -            Iterator it = coll.iterator();
  -            while (it.hasNext()) {
  -    	        validate(iPredicate, it.next());
  -            }
  -            return iCollection.addAll(coll);
  -        }
  -    
  -        /**
  -         * @see Collection#iterator()
  -         */
  -        public Iterator iterator() {
  -            return iCollection.iterator();
  -        }
  -
  -        /**
  -         * @see Collection#size()
  -         */
  -        public int size() {
  -            return iCollection.size();
  -        }
  -
  -        /**
  -         * @see Collection#clear()
  -         */
  -        public void clear() {
  -            iCollection.clear();
  -        }
  -
  -        /**
  -         * @see Collection#isEmpty()
  -         */
  -        public boolean isEmpty() {
  -            return iCollection.isEmpty();
  -        }
  -
  -        /**
  -         * @see Collection#contains(Object)
  -         */
  -        public boolean contains(Object item) {
  -            return iCollection.contains(item);
  -        }
  -
  -        /**
  -         * @see Collection#containsAll(Collection)
  -         */
  -        public boolean containsAll(Collection coll) {
  -            return iCollection.containsAll(coll);
  -        }
  -
  -        /**
  -         * @see Collection#remove(Object)
  -         */
  -        public boolean remove(Object item) {
  -            return iCollection.remove(item);
  -        }
  -
  -        /**
  -         * @see Collection#removeAll(Collection)
  -         */
  -        public boolean removeAll(Collection coll) {
  -            return iCollection.remove(coll);
  -        }
  -
  -        /**
  -         * @see Collection#retainAll(Collection)
  -         */
  -        public boolean retainAll(Collection coll) {
  -            return iCollection.retainAll(coll);
  -        }
  -
  -        /**
  -         * @see Collection#toArray()
  -         */
  -        public Object[] toArray() {
  -            return iCollection.toArray();
  -        }
  -
  -        /**
  -         * @see Collection#toArray(Object[])
  -         */
  -        public Object[] toArray(Object[] array) {
  -            return iCollection.toArray(array);
  -        }
  -
  -        /**
  -         * @see Object#equals(Object)
  -         */
  -        public boolean equals(Object obj) {
  -            return iCollection.equals(obj);
  -        }
  -    
  -        /**
  -         * @see Object#hashCode()
  -         */
  -        public int hashCode() {
  -            return iCollection.hashCode();
  -        }
  -    
  -        /**
  -         * @see Object#toString()
  -         */
  -        public String toString() {
  -            return iCollection.toString();
  -        }
  -	}
  -	
  -	/**
  -	 * PredicateList validates a List
  -	 */
  -	private static class PredicateList
  -			extends PredicateCollection
  -			implements List {
  -	
  -    	/**
  -    	 * Create a new PredicateList that wraps another list.
  -    	 * It is important that the original list is not used again after
  -    	 * this call, as it is a backdoor to add non-validated objects.
  -    	 * @param list  the list to wrap and restrict
  -    	 * @param predicate  the predicate used to validate entry into the list
  -    	 */
  -    	public PredicateList(List list, Predicate predicate) {
  -    	    super(list, predicate);
  -    	}
  -    	
  -        /**
  -         * Add an item to the list at the specified index. If the item is
  -         * not an instance of the list's validation type an exception is
  -         * thrown. The state of the list will be unaltered if an exception 
  -         * is thrown.
  -         * @see List#add(int, Object)
  -         * @param index  the index at which to add the item
  -         * @param item  the item to add
  -         * @throws IllegalArgumentException if the object is not of a valid type
  -         */
  -        public void add(int index, Object item) {
  -            validate(iPredicate, item);
  -            ((List) iCollection).add(index, item);
  -        }
  -    
  -        /**
  -         * Add a collection at the specified index. If any of the items in the
  -         * collection is not an instance of the list's validation type an
  -         * exception is thrown. The state of the list will be unaltered if an
  -         * exception is thrown.
  -         * @see List#addAll(int, Collection)
  -         * @param index  the index at which to add the collection
  -         * @param coll  the collection to add
  -         * @throws IllegalArgumentException if the object is not of a valid type
  -         */
  -        public boolean addAll(int index, Collection coll) {
  -            Iterator it = coll.iterator();
  -            while (it.hasNext()) {
  -    	        validate(iPredicate, it.next());
  -            }
  -            return ((List) iCollection).addAll(index, coll);
  -        }
  -    
  -        /**
  -         * Set the value at the specified index. If the item is not an instance
  -         * of the list's validation type an exception is thrown. The state of
  -         * the list will be unaltered if an exception is thrown.
  -         * @see List#set(int, Object)
  -         * @param index  the index to change
  -         * @param item  the item to change to
  -         * @throws IllegalArgumentException if the object is not of a valid type
  -         */
  -        public Object set(int index, Object item) {
  -            validate(iPredicate, item);
  -            return ((List) iCollection).set(index, item);
  -        }
  -        
  -        /**
  -         * @see List#listIterator()
  -         */
  -        public ListIterator listIterator() {
  -            return new PredicateListIterator(((List) iCollection).listIterator(), iPredicate);
  -        }
  -    
  -        /**
  -         * @see List#listIterator(int)
  -         */
  -        public ListIterator listIterator(int index) {
  -            return new PredicateListIterator(((List) iCollection).listIterator(index), iPredicate);
  -        }
  -    
  -        /**
  -         * @see List#subList(int, int)
  -         */
  -        public List subList(int fromIndex, int toIndex) {
  -            return new PredicateList(((List) iCollection).subList(fromIndex, toIndex), iPredicate);
  -        }
  -
  -        /**
  -         * @see List#get(int)
  -         */
  -        public Object get(int index) {
  -            return ((List) iCollection).get(index);
  -        }
  -    
  -        /**
  -         * @see List#indexOf(Object)
  -         */
  -        public int indexOf(Object item) {
  -            return ((List) iCollection).indexOf(item);
  -        }
  -    
  -        /**
  -         * @see List#lastIndexOf(Object)
  -         */
  -        public int lastIndexOf(Object item) {
  -            return ((List) iCollection).lastIndexOf(item);
  -        }
  -    
  -        /**
  -         * @see List#remove(int)
  -         */
  -        public Object remove(int index) {
  -            return ((List) iCollection).remove(index);
  -        }
  -	}
  -
  -	/**
  -	 * PredicateListIterator handles the list iterator for PredicateList
  -	 */
  -	private static class PredicateListIterator implements ListIterator {
  -	    
  -	    private final ListIterator iIterator;
  -	    private final Predicate iPredicate;
  -	    
  -	    /**
  -	     * Constructor
  -	     */
  -	    private PredicateListIterator(ListIterator iterator, Predicate predicate) {
  -	        super();
  -	        iIterator = iterator;
  -	        iPredicate = predicate;
  -		}
  -		
  -        /**
  -         * @see Iterator#hasNext()
  -         */
  -        public boolean hasNext() {
  -            return iIterator.hasNext();
  -        }
  -
  -        /**
  -         * @see ListIterator#hasPrevious()
  -         */
  -        public boolean hasPrevious() {
  -            return iIterator.hasPrevious();
  -        }
  -
  -        /**
  -         * @see Iterator#next()
  -         */
  -        public Object next() {
  -            return iIterator.next();
  -        }
  -
  -        /**
  -         * @see ListIterator#nextIndex()
  -         */
  -        public int nextIndex() {
  -            return iIterator.nextIndex();
  -        }
  -
  -        /**
  -         * @see ListIterator#previous()
  -         */
  -        public Object previous() {
  -            return iIterator.previous();
  -        }
  -
  -        /**
  -         * @see ListIterator#previousIndex()
  -         */
  -        public int previousIndex() {
  -            return iIterator.previousIndex();
  -        }
  -
  -        /**
  -         * @see Iterator#remove()
  -         */
  -        public void remove() {
  -            iIterator.remove();
  -        }
  -
  -        /**
  -         * @see ListIterator#add(Object)
  -         */
  -        public void add(Object item) {
  -	        validate(iPredicate, item);
  -            iIterator.add(item);
  -        }
  -
  -        /**
  -         * @see ListIterator#set(Object)
  -         */
  -        public void set(Object item) {
  -	        validate(iPredicate, item);
  -            iIterator.set(item);
  -        }
  -	}
  -	
  -	/**
  -	 * PredicateSet validates a Set
  -	 */
  -	private static class PredicateSet
  -			extends PredicateCollection
  -			implements Set {
  -	
  -    	/**
  -    	 * Create a new PredicateSet that wraps another Set.
  -    	 * It is important that the original set is not used again after
  -    	 * this call, as it is a backdoor to add non-validated objects.
  -    	 * @param set  the set to wrap and restrict
  -    	 * @param predicate  the predicate used to validate entry into the set
  -    	 */
  -    	public PredicateSet(Set set, Predicate predicate) {
  -    	    super(set, predicate);
  -    	}
  -	}
  -	
  -	/**
  -	 * PredicateSet validates a SortedSet
  -	 */
  -	private static class PredicateSortedSet
  -			extends PredicateSet
  -			implements SortedSet {
  -	
  -    	/**
  -    	 * Create a new PredicateSortedSet that wraps another SortedSet.
  -    	 * It is important that the original SortedSet is not used again after
  -    	 * this call, as it is a backdoor to add non-validated objects.
  -    	 * @param set  the set to wrap and restrict
  -    	 * @param predicate  the predicate used to validate entry into the SortedSet
  -    	 */
  -    	public PredicateSortedSet(SortedSet set, Predicate predicate) {
  -    	    super(set, predicate);
  -    	}
  -    	
  -        /**
  -         * @see SortedSet#headSet(Object)
  -         */
  -        public SortedSet headSet(Object toElement) {
  -            return new PredicateSortedSet(((SortedSet) iCollection).headSet(toElement), iPredicate);
  -        }
  -    
  -        /**
  -         * @see SortedSet#subSet(Object, Object)
  -         */
  -        public SortedSet subSet(Object fromElement, Object toElement) {
  -            return new PredicateSortedSet(((SortedSet) iCollection).subSet(fromElement, toElement), iPredicate);
  -        }
  -    
  -        /**
  -         * @see SortedSet#tailSet(Object)
  -         */
  -        public SortedSet tailSet(Object fromElement) {
  -            return new PredicateSortedSet(((SortedSet) iCollection).tailSet(fromElement), iPredicate);
  -        }
  -    
  -        /**
  -         * @see SortedSet#first()
  -         */
  -        public Object first() {
  -            return ((SortedSet) iCollection).first();
  -        }
  -    
  -        /**
  -         * @see SortedSet#last()
  -         */
  -        public Object last() {
  -            return ((SortedSet) iCollection).last();
  -        }
  -        
  -        /**
  -         * @see SortedSet#comparator()
  -         */
  -        public Comparator comparator() {
  -            return ((SortedSet) iCollection).comparator();
  -        }
  -	}
  -	
  -	/**
  -	 * PredicateBag validates a Bag
  -	 */
  -	private static class PredicateBag
  -			extends PredicateCollection
  -			implements Bag {
  -	
  -    	/**
  -    	 * Create a new PredicateBag that wraps another Bag.
  -    	 * It is important that the original Bag is not used again after
  -    	 * this call, as it is a backdoor to add non-validated objects.
  -    	 * @param bag  the bag to wrap and restrict
  -    	 * @param predicate  the predicate used to validate entry into the Bag
  -    	 */
  -    	public PredicateBag(Bag bag, Predicate predicate) {
  -    	    super(bag, predicate);
  -    	}
  -    	
  -        /**
  -         * @see Bag#add(Object, int)
  -         */
  -        public boolean add(Object item, int i) {
  -            validate(iPredicate, item);
  -            return ((Bag) iCollection).add(item, i);
  -        }
  -
  -        /**
  -         * @see Bag#getCount(Object)
  -         */
  -        public int getCount(Object item) {
  -            return ((Bag) iCollection).getCount(item);
  -        }
  -
  -        /**
  -         * @see Bag#remove(Object, int)
  -         */
  -        public boolean remove(Object item, int i) {
  -            return ((Bag) iCollection).remove(item, i);
  -        }
  -
  -        /**
  -         * @see Bag#uniqueSet()
  -         */
  -        public Set uniqueSet() {
  -            return ((Bag) iCollection).uniqueSet();
  -        }
  -	}
  -	
  -	/**
  -	 * PredicateSortedBag validates a SortedBag
  -	 */
  -	private static class PredicateSortedBag
  -			extends PredicateBag
  -			implements SortedBag {
  -	
  -    	/**
  -    	 * Create a new PredicateSortedBag that wraps another SortedBag.
  -    	 * It is important that the original SortedBag is not used again after
  -    	 * this call, as it is a backdoor to add non-validated objects.
  -    	 * @param bag  the bag to wrap and restrict
  -    	 * @param predicate  the predicate used to validate entry into the SortedBag
  -    	 */
  -    	public PredicateSortedBag(SortedBag bag, Predicate predicate) {
  -    	    super(bag, predicate);
  -    	}
  -    	
  -        /**
  -         * @see SortedBag#comparator()
  -         */
  -        public Comparator comparator() {
  -            return ((SortedBag) iCollection).comparator();
  -        }
  -
  -        /**
  -         * @see SortedBag#first()
  -         */
  -        public Object first() {
  -            return ((SortedBag) iCollection).first();
  -        }
  -
  -        /**
  -         * @see SortedBag#last()
  -         */
  -        public Object last() {
  -            return ((SortedBag) iCollection).last();
  -        }
  -	}
  -	
  -	/**
  -	 * PredicateBag validates a Map
  -	 */
  -	private static class PredicateMap
  -			implements Map {
  -	
  -        /** The predicate to control entry into the map */
  -        protected final Predicate iKeyPredicate;
  -        /** The predicate to control entry into the map */
  -        protected final Predicate iValuePredicate;
  -        /** The list being wrapped */
  -        protected final Map iMap;
  -			    
  -    	/**
  -    	 * Create a new PredicateMap that wraps another Map.
  -    	 * It is important that the original Map is not used again after
  -    	 * this call, as it is a backdoor to add non-validated objects.
  -    	 * @param map  the map to wrap and restrict
  -    	 * @param keyPredicate  the predicate used to validate entry into the SortedMap
  -    	 * @param valuePredicate  the predicate used to validate entry into the SortedMap
  -    	 */
  -    	public PredicateMap(Map map, Predicate keyPredicate, Predicate valuePredicate) {
  -    	    super();
  -    	    if (map == null) {
  -    	        throw new IllegalArgumentException("Collection to be wrapped must not be null");
  -    	    }
  -    	    if (keyPredicate == null) {
  -    	        throw new IllegalArgumentException("Key Predicate must not be null");
  -    	    }
  -    	    if (valuePredicate == null) {
  -    	        throw new IllegalArgumentException("Value Predicate must not be null");
  -    	    }
  -    	    iKeyPredicate = keyPredicate;
  -    	    iValuePredicate = valuePredicate;
  -    	    iMap = map;
  -    	    for (Iterator it = iMap.keySet().iterator(); it.hasNext();) {
  -                validate(iKeyPredicate, it.next());
  -            }
  -    	    for (Iterator it = iMap.values().iterator(); it.hasNext();) {
  -                validate(iValuePredicate, it.next());
  -            }
  -    	}
  -    	
  -        /**
  -         * @see Map#put(Object, Object)
  -         */
  -        public Object put(Object key, Object value) {
  -            validate(iKeyPredicate, key);
  -            validate(iValuePredicate, value);
  -            return iMap.put(key, value);
  -        }
  -
  -        /**
  -         * @see Map#putAll(Map)
  -         */
  -        public void putAll(Map map) {
  -            for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
  -                Map.Entry entry = (Map.Entry) it.next();
  -	            validate(iKeyPredicate, entry.getKey());
  -    	        validate(iValuePredicate, entry.getValue());
  -            }
  -            iMap.putAll(map);
  -        }
  -
  -        /**
  -         * @see Map#entrySet()
  -         */
  -        public Set entrySet() {
  -            return new PredicateMapEntrySet(iMap.entrySet(), iValuePredicate);
  -        }
  -
  -        /**
  -         * @see Map#keySet()
  -         */
  -        public Set keySet() {
  -            return new PredicateSet(iMap.keySet(), iKeyPredicate);
  -        }
  -
  -        /**
  -         * @see Map#values()
  -         */
  -        public Collection values() {
  -            return new PredicateCollection(iMap.values(), iValuePredicate);
  -        }
  -
  -        /**
  -         * @see Map#get(Object)
  -         */
  -        public Object get(Object key) {
  -            return iMap.get(key);
  -        }
  -
  -        /**
  -         * @see Map#size()
  -         */
  -        public int size() {
  -            return iMap.size();
  -        }
  -
  -        /**
  -         * @see Map#clear()
  -         */
  -        public void clear() {
  -            iMap.clear();
  -        }
  -
  -        /**
  -         * @see Map#isEmpty()
  -         */
  -        public boolean isEmpty() {
  -            return iMap.isEmpty();
  -        }
  -
  -        /**
  -         * @see Map#containsKey(Object)
  -         */
  -        public boolean containsKey(Object key) {
  -            return iMap.containsKey(key);
  -        }
  -
  -        /**
  -         * @see Map#containsValue(Object)
  -         */
  -        public boolean containsValue(Object value) {
  -            return iMap.containsValue(value);
  -        }
  -
  -        /**
  -         * @see Map#remove(Object)
  -         */
  -        public Object remove(Object key) {
  -            return iMap.remove(key);
  -        }
  -
  -        /**
  -         * @see Object#equals(Object)
  -         */
  -        public boolean equals(Object obj) {
  -            return iMap.equals(obj);
  -        }
  -    
  -        /**
  -         * @see Object#hashCode()
  -         */
  -        public int hashCode() {
  -            return iMap.hashCode();
  -        }
  -    
  -        /**
  -         * @see Object#toString()
  -         */
  -        public String toString() {
  -            return iMap.toString();
  -        }
  -	}   
  -	
  -	/**
  -	 * PredicateSortedBag validates a SortedMap
  -	 */
  -	private static class PredicateSortedMap
  -			extends PredicateMap
  -			implements SortedMap {
  -	
  -    	/**
  -    	 * Create a new PredicateSortedMap that wraps another SortedMap.
  -    	 * It is important that the original SortedBag is not used again after
  -    	 * this call, as it is a backdoor to add non-validated objects.
  -    	 * @param bag  the bag to wrap and restrict
  -    	 * @param keyPredicate  the predicate used to validate entry into the SortedMap
  -    	 * @param valuePredicate  the predicate used to validate entry into the SortedMap
  -    	 */
  -    	public PredicateSortedMap(SortedMap map, Predicate keyPredicate, Predicate valuePredicate) {
  -    	    super(map, keyPredicate, valuePredicate);
  -    	}
  -    	
  -        /**
  -         * @see SortedMap#comparator()
  -         */
  -        public Comparator comparator() {
  -            return ((SortedMap) iMap).comparator();
  -        }
  -
  -        /**
  -         * @see SortedMap#firstKey()
  -         */
  -        public Object firstKey() {
  -            return ((SortedMap) iMap).firstKey();
  -        }
  -
  -        /**
  -         * @see SortedMap#lastKey()
  -         */
  -        public Object lastKey() {
  -            return ((SortedMap) iMap).lastKey();
  -        }
  -
  -        /**
  -         * @see SortedMap#headMap(Object)
  -         */
  -        public SortedMap headMap(Object toKey) {
  -            return new PredicateSortedMap(
  -            	((SortedMap) iMap).headMap(toKey), iKeyPredicate, iValuePredicate);
  -        }
  -
  -        /**
  -         * @see SortedMap#tailMap(Object)
  -         */
  -        public SortedMap tailMap(Object fromKey) {
  -            return new PredicateSortedMap(
  -            	((SortedMap) iMap).tailMap(fromKey), iKeyPredicate, iValuePredicate);
  -        }
  -
  -        /**
  -         * @see SortedMap#subMap(Object, Object)
  -         */
  -        public SortedMap subMap(Object fromKey, Object toKey) {
  -            return new PredicateSortedMap(
  -            	((SortedMap) iMap).subMap(fromKey, toKey), iKeyPredicate, iValuePredicate);
  -        }
  -	}
  -	
  -	/**
  -	 * Map helper class to access iterator
  -	 */
  -	public static class PredicateMapEntrySet
  -	        extends AbstractSet {
  -	    private final Set iSet;
  -        private final Predicate iValuePredicate;
  -	    
  -	    /**
  -	     * Constructor
  -	     */
  -	    private PredicateMapEntrySet(Set set, Predicate predicate) {
  -	        super();
  -	        iSet = set;
  -	        iValuePredicate = predicate;
  -	    }
  -            
  -        /**
  -         * @see Collection#clear()
  -         */
  -        public void clear() {
  -            iSet.clear();
  -        }
  -
  -        /**
  -         * @see Collection#iterator()
  -         */
  -        public Iterator iterator() {
  -            return new PredicateMapEntrySetIterator(iSet.iterator(), iValuePredicate);
  -        }
  -
  -        /**
  -         * @see Collection#remove(Object)
  -         */
  -        public boolean remove(Object obj) {
  -            return iSet.remove(obj);
  -        }
  -
  -        /**
  -         * @see Collection#size()
  -         */
  -        public int size() {
  -            return iSet.size();
  -        }
  -
  -	}
  -	
  -	/**
  -	 * Iterator to protect the setValue method of Map.Entry
  -	 */
  -    public static class PredicateMapEntrySetIterator
  -    		implements Iterator {
  -	    private final Iterator iIterator;
  -        private final Predicate iValuePredicate;
  -	    
  -	    /**
  -	     * Constructor
  -	     */
  -	    private PredicateMapEntrySetIterator(Iterator iterator, Predicate predicate) {
  -	        super();
  -	        iIterator = iterator;
  -	        iValuePredicate = predicate;
  -	    }
  -            
  -        /**
  -         * @see Iterator#next()
  -         */
  -        public Object next() {
  -            Object obj = iIterator.next();
  -            return new PredicateMapEntry((Map.Entry) obj, iValuePredicate);
  -        }
  -
  -        /**
  -         * @see Iterator#hasNext()
  -         */
  -        public boolean hasNext() {
  -            return iIterator.hasNext();
  -        }
  -
  -        /**
  -         * @see Iterator#remove()
  -         */
  -        public void remove() {
  -            iIterator.remove();
  -        }
  -
  -    }
  -    
  -	/**
  -	 * MapEntry to protect the setValue method
  -	 */
  -    public static class PredicateMapEntry
  -    		implements Map.Entry {
  -	    private final Map.Entry iEntry;
  -        private final Predicate iValuePredicate;
  -        
  -	    /**
  -	     * Constructor
  -	     */
  -	    private PredicateMapEntry(Map.Entry entry, Predicate predicate) {
  -	        super();
  -	        iEntry = entry;
  -	        iValuePredicate = predicate;
  -	    }
  -	    
  -        /**
  -         * @see java.util.Map.Entry#getKey()
  -         */
  -        public Object getKey() {
  -            return iEntry.getKey();
  -        }
  -
  -        /**
  -         * @see java.util.Map.Entry#getValue()
  -         */
  -        public Object getValue() {
  -            return iEntry.getValue();
  -        }
  -
  -        /**
  -         * @see java.util.Map.Entry#setValue(Object)
  -         */
  -        public Object setValue(Object object) {
  -            validate(iValuePredicate, object);
  -            return iEntry.setValue(object);
  -        }
  -
  -    }
  -    
   	/**
   	 * True predicate implementation
   	 */    
  
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/BagUtils.java
  
  Index: BagUtils.java
  ===================================================================
  package org.apache.commons.collections;
  
  
  import java.util.Collection;
  import java.util.Comparator;
  import java.util.Set;
  
  
  /**
   *  Provides utility methods and decorators for {@link Bag} 
   *  and {@link SortedBag} instances.<P>
   *
   *  @author Paul Jack
   *  @version $Id: BagUtils.java,v 1.1 2002/08/13 00:26:51 pjack Exp $
   */
  public class BagUtils {
  
  
      /**
       *  Prevents instantiation.
       */
      private BagUtils() {
      }
  
  
      static class PredicatedBag extends CollectionUtils.PredicatedCollection 
      implements Bag {
  
          public PredicatedBag(Bag b, Predicate p) {
              super(b, p);
          }
  
          public boolean add(Object o, int count) {
              validate(o);
              return getBag().add(o, count);
          }
  
          public boolean remove(Object o, int count) {
              return getBag().remove(o, count);
          }
  
          public Set uniqueSet() {
              return getBag().uniqueSet();
          }
  
          public int getCount(Object o) {
              return getBag().getCount(o);
          }
  
          private Bag getBag() {
              return (Bag)collection;
          }
      }
  
  
      static class UnmodifiableBag 
      extends CollectionUtils.UnmodifiableCollection
      implements Bag {
  
          public UnmodifiableBag(Bag bag) {
              super(bag);
          }
  
          private Bag getBag() {
              return (Bag)collection;
          }
  
          public boolean add(Object o, int count) {
              throw new UnsupportedOperationException();
          }
  
          public boolean remove(Object o, int count) {
              throw new UnsupportedOperationException();
          }
  
          public Set uniqueSet() {
              return ((Bag)collection).uniqueSet();
          }
  
          public int getCount(Object o) {
              return ((Bag)collection).getCount(o);
          }
      }
  
  
      static class SynchronizedBag
      extends CollectionUtils.SynchronizedCollection
      implements Bag {
  
          public SynchronizedBag(Bag bag) {
              super(bag);
          }
  
          public synchronized boolean add(Object o, int count) {
              return getBag().add(o, count);
          }
  
          public synchronized boolean remove(Object o, int count) {
              return getBag().remove(o, count);
          }
  
          public synchronized Set uniqueSet() {
              return getBag().uniqueSet();
          }
  
          public synchronized int getCount(Object o) {
              return getBag().getCount(o);
          }
  
          private Bag getBag() {
              return (Bag)collection;
          }
  
      }
  
  
      static class BoundedBag extends CollectionUtils.CollectionWrapper
      implements Bag {
  
          final protected int maxSize;
  
          public BoundedBag(Bag bag, int maxSize) {
              super(bag);
              this.maxSize = maxSize;
          }
  
          public boolean add(Object o) {
              validate(1);
              return collection.add(o);
          }
  
          public boolean addAll(Collection c) {
              validate(c.size());
              return collection.addAll(c);
          }
  
          public boolean add(Object o, int count) {
              validate(count);
              return getBag().add(o, count);
          }
  
          public boolean remove(Object o, int count) {
              return getBag().remove(o, count);
          }
  
          public Set uniqueSet() {
              return getBag().uniqueSet();
          }
  
          public int getCount(Object o) {
              return getBag().getCount(o);
          }
  
          private Bag getBag() {
              return (Bag)collection;
          }
  
          protected void validate(int delta) {
              if (delta + size() > maxSize) {
                  throw new IllegalStateException("Maximum size reached.");
              }
          }
      }
  
  
      static class PredicatedSortedBag extends PredicatedBag 
      implements SortedBag {
  
          public PredicatedSortedBag(SortedBag sb, Predicate p) {
              super(sb, p);
          }
  
          public Comparator comparator() {
              return getSortedBag().comparator();
          }
  
          public Object first() {
              return getSortedBag().first();
          }
  
          public Object last() {
              return getSortedBag().last();
          }
  
          private SortedBag getSortedBag() {
              return (SortedBag)collection;
          }
      }
  
  
      static class SynchronizedSortedBag extends SynchronizedBag
      implements SortedBag {
  
          public SynchronizedSortedBag(SortedBag bag) {
              super(bag);
          }
  
          public synchronized Comparator comparator() {
              return getSortedBag().comparator();
          }
  
          public synchronized Object first() {
              return getSortedBag().first();
          }
  
          public synchronized Object last() {
              return getSortedBag().last();
          }
  
          private SortedBag getSortedBag() {
              return (SortedBag)collection;
          }
  
      }
  
  
      static class UnmodifiableSortedBag extends UnmodifiableBag
      implements SortedBag {
  
          public UnmodifiableSortedBag(SortedBag bag) {
              super(bag);
          }
  
          public Comparator comparator() {
              return getSortedBag().comparator();
          }
  
          public Object first() {
              return getSortedBag().first();
          }
  
          public Object last() {
              return getSortedBag().last();
          }
  
          private SortedBag getSortedBag() {
              return (SortedBag)collection;
          }
  
      }
  
  
      static class BoundedSortedBag extends BoundedBag
      implements SortedBag {
  
          public BoundedSortedBag(SortedBag bag, int maxSize) {
              super(bag, maxSize);
          }
  
          public Comparator comparator() {
              return getSortedBag().comparator();
          }
  
          public Object first() {
              return getSortedBag().first();
          }
  
          public Object last() {
              return getSortedBag().last();
          }
  
          private SortedBag getSortedBag() {
              return (SortedBag)collection;
          }
  
      }
  
  
      /**
       *  Returns a predicated bag backed by the given bag.  Only objects
       *  that pass the test in the given predicate can be added to the bag.
       *  It is important not to use the original bag after invoking this 
       *  method, as it is a backdoor for adding unvalidated objects.
       *
       *  @param b  the bag to predicate
       *  @param p  the predicate for the bag
       *  @return  a predicated bag backed by the given bag
       */
      public static Bag predicatedBag(Bag b, Predicate p) {
          return new PredicatedBag(b, p);
      }
  
  
      /**
       *  Returns an unmodifiable view of the given bag.  Any modification
       *  attempts to the returned bag will raise an 
       *  {@link UnsupportedOperationException}.
       *
       *  @param b  the bag whose unmodifiable view is to be returned
       *  @return  an unmodifiable view of that bag
       */
      public static Bag unmodifiableBag(Bag b) {
          return new UnmodifiableBag(b);
      }
  
  
      /**
       *  Returns a synchronized (thread-safe) bag backed by the given bag.
       *  In order to guarantee serial access, it is critical that all 
       *  access to the backing bag is accomplished through the returned bag.
       *  <P>
       *  It is imperative that the user manually synchronize on the returned
       *  bag when iterating over it:
       *
       *  <Pre>
       *  Bag bag = BagUtils.synchronizedBag(new HashBag());
       *  ...
       *  synchronized(bag) {
       *      Iterator i = bag.iterator(); // Must be in synchronized block
       *      while (i.hasNext())
       *          foo(i.next());
       *      }
       *  }
       *  </Pre>
       *
       *  Failure to follow this advice may result in non-deterministic 
       *  behavior.
       *
       *  @param b  the bag to synchronize
       *  @return  a synchronized bag backed by that bag
       */
      public static Bag synchronizedBag(Bag b) {
          return new SynchronizedBag(b);
      }
  
  
      /**
       *  Returns a bounded bag backed by the given bag.
       *  New elements may only be added to the returned bag if its 
       *  size is less than the specified maximum; otherwise, an
       *  {@link IllegalStateException} will be thrown.
       *
       *  @param b  the bag whose size to bind
       *  @param maxSize  the maximum size of the returned bag
       *  @return  a bounded bag 
       */
      public static Bag boundedBag(Bag b, int maxSize) {
          return new BoundedBag(b, maxSize);
      }
  
  
  
  
      /**
       *  Returns a predicated sorted bag backed by the given sorted bag.  
       *  Only objects that pass the test in the given predicate can be 
       *  added to the bag.
       *  It is important not to use the original bag after invoking this 
       *  method, as it is a backdoor for adding unvalidated objects.
       *
       *  @param b  the sorted bag to predicate
       *  @param p  the predicate for the bag
       *  @return  a predicated bag backed by the given bag
       */
      public static SortedBag predicatedSortedBag(SortedBag b, Predicate p) {
          return new PredicatedSortedBag(b, p);
      }
  
  
      /**
       *  Returns an unmodifiable view of the given sorted bag.  Any modification
       *  attempts to the returned bag will raise an 
       *  {@link UnsupportedOperationException}.
       *
       *  @param b  the bag whose unmodifiable view is to be returned
       *  @return  an unmodifiable view of that bag
       */
      public static SortedBag unmodifiableSortedBag(SortedBag b) {
          return new UnmodifiableSortedBag(b);
      }
  
  
      /**
       *  Returns a synchronized (thread-safe) sorted bag backed by the given 
       *  sorted bag.
       *  In order to guarantee serial access, it is critical that all 
       *  access to the backing bag is accomplished through the returned bag.
       *  <P>
       *  It is imperative that the user manually synchronize on the returned
       *  bag when iterating over it:
       *
       *  <Pre>
       *  SortedBag bag = BagUtils.synchronizedSortedBag(new TreeBag());
       *  ...
       *  synchronized(bag) {
       *      Iterator i = bag.iterator(); // Must be in synchronized block
       *      while (i.hasNext())
       *          foo(i.next());
       *      }
       *  }
       *  </Pre>
       *
       *  Failure to follow this advice may result in non-deterministic 
       *  behavior.
       *
       *  @param b  the bag to synchronize
       *  @return  a synchronized bag backed by that bag
       */
      public static SortedBag synchronizedSortedBag(SortedBag b) {
          return new SynchronizedSortedBag(b);
      }
  
  
      /**
       *  Returns a bounded sorted bag backed by the given sorted bag.
       *  New elements may only be added to the returned bag if its 
       *  size is less than the specified maximum; otherwise, an
       *  {@link IllegalStateException} will be thrown.
       *
       *  @param b  the bag whose size to bind
       *  @param maxSize  the maximum size of the returned bag
       *  @return  a bounded bag 
       */
      public static SortedBag boundedSortedBag(SortedBag b, int maxSize) {
          return new BoundedSortedBag(b, maxSize);
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/SetUtils.java
  
  Index: SetUtils.java
  ===================================================================
  package org.apache.commons.collections;
  
  
  import java.util.Collection;
  import java.util.Comparator;
  import java.util.Iterator;
  import java.util.Set;
  import java.util.SortedSet;
  
  
  /**
   *  Provides static utility methods and decorators for {@link Set} 
   *  and {@link SortedSet} instances.
   *
   *  @author Paul Jack
   *  @version $Id: SetUtils.java,v 1.1 2002/08/13 00:26:51 pjack Exp $
   */
  public class SetUtils {
  
  
      /**
       *  Prevents instantiation.
       */
      private SetUtils() {
      }
  
  
      static class PredicatedSet extends CollectionUtils.PredicatedCollection
      implements Set {
  
          public PredicatedSet(Set set, Predicate p) {
              super(set, p);
          }
  
      }
  
      static class BoundedSet extends CollectionUtils.CollectionWrapper
      implements Set {
  
          final protected int maxSize;
  
  
          public BoundedSet(Set set, int maxSize) {
              super(set);
              this.maxSize = maxSize;
          }
  
          public boolean add(Object o) {
              if (!collection.contains(o)) {
                  validate(1);
              }
              return collection.add(o);
          }
  
          public boolean addAll(Collection c) {
              int delta = 0;
              for (Iterator iter = c.iterator(); iter.hasNext(); ) {
                  if (!collection.contains(iter.next())) delta++;
              }
              validate(delta);
              return collection.addAll(c);
          }
  
  
          private void validate(int delta) {
              if (delta + size() > maxSize) {
                  throw new IllegalStateException("Maximum size reached.");
              }
          }
  
      }
  
  
      static class PredicatedSortedSet extends PredicatedSet 
      implements SortedSet {
  
          public PredicatedSortedSet(SortedSet s, Predicate p) {
              super(s, p);
          }
  
          public SortedSet subSet(Object o1, Object o2) {
              SortedSet sub = getSortedSet().subSet(o1, o2);
              return new PredicatedSortedSet(sub, predicate);
          }
  
          public SortedSet headSet(Object o1) {
              SortedSet sub = getSortedSet().headSet(o1);
              return new PredicatedSortedSet(sub, predicate);
          }
  
          public SortedSet tailSet(Object o1) {
              SortedSet sub = getSortedSet().tailSet(o1);
              return new PredicatedSortedSet(sub, predicate);
          }
  
          public Object first() {
              return getSortedSet().first();
          }
  
          public Object last() {
              return getSortedSet().last();
          }
  
          public Comparator comparator() {
              return getSortedSet().comparator();
          }
  
          private SortedSet getSortedSet() {
              return (SortedSet)collection;
          }
  
      }
  
      /**
       *  Returns a predicated set backed by the given set.  Only objects
       *  that pass the test in the given predicate can be added to the set.
       *  It is important not to use the original set after invoking this 
       *  method, as it is a backdoor for adding unvalidated objects.
       *
       *  @param set  the set to predicate
       *  @param p  the predicate for the set
       *  @return  a predicated set backed by the given set
       */
      public static Set predicatedSet(Set set, Predicate p) {
          return new PredicatedSet(set, p);
      }
  
  
      /**
       *  Returns a bounded set backed by the given set.
       *  New elements may only be added to the returned set if its 
       *  size is less than the specified maximum; otherwise, an
       *  {@link IllegalStateException} will be thrown.
       *
       *  @param set  the set whose size to bind
       *  @param maxSize  the maximum size of the returned set
       *  @return  a bounded set 
       */
      public static Set boundedSet(Set set, int maxSize) {
          return new BoundedSet(set, maxSize);
      }
  
  
      /**
       *  Returns a predicated sorted set backed by the given sorted set.  
       *  Only objects that pass the test in the given predicate can be added
       *  to the sorted set.
       *  It is important not to use the original sorted set after invoking this 
       *  method, as it is a backdoor for adding unvalidated objects.
       *
       *  @param set  the sorted set to predicate
       *  @param p  the predicate for the sorted set
       *  @return  a predicated sorted set backed by the given sorted set
       */
      public static SortedSet predicatedSortedSet(SortedSet set, Predicate p) {
          return new PredicatedSortedSet(set, p);
      }
  
  }
  
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
  1.32      +8 -4      jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- TestAll.java	12 Aug 2002 18:13:09 -0000	1.31
  +++ TestAll.java	13 Aug 2002 00:26:52 -0000	1.32
  @@ -85,6 +85,10 @@
           suite.addTest(TestBoundedFifoBuffer2.suite());
           suite.addTest(TestCollatingIterator.suite());
           suite.addTest(TestCollectionUtils.suite());
  +        suite.addTest(TestBufferUtils.suite());
  +        suite.addTest(TestSetUtils.suite());
  +        suite.addTest(TestListUtils.suite());
  +        suite.addTest(TestMapUtils.suite());
           suite.addTest(TestComparableComparator.suite());
           suite.addTest(TestComparatorChain.suite());
           suite.addTest(TestCursorableLinkedList.suite());
  
  
  
  1.4       +42 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java
  
  Index: TestCollectionUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestCollectionUtils.java	10 Aug 2002 00:36:34 -0000	1.3
  +++ TestCollectionUtils.java	13 Aug 2002 00:26:52 -0000	1.4
  @@ -328,4 +328,42 @@
           test = CollectionUtils.index(bag, 0);
           assertTrue(test.equals("element"));
       }
  +
  +
  +    public BulkTest bulkTestPredicatedCollection1() {
  +        return new TestPredicatedCollection("") {
  +            public Collection predicatedCollection() {
  +                Predicate p = getPredicate();
  +                return CollectionUtils.predicatedCollection(new ArrayList(), p);
  +            }
  +
  +            public BulkTest bulkTestAll() {
  +                return new TestCollection("") {
  +                    public Collection makeCollection() {
  +                        return predicatedCollection();
  +                    }
  +
  +                    public Collection makeConfirmedCollection() {
  +                        return new ArrayList();
  +                    }
  +
  +                    public Collection makeConfirmedFullCollection() {
  +                        ArrayList list = new ArrayList();
  +                        list.addAll(java.util.Arrays.asList(getFullElements()));
  +                        return list;
  +                    }
  +
  +                    public Object[] getFullElements() {
  +                        return getFullNonNullStringElements();
  +                    }
  +
  +                    public Object[] getOtherElements() {
  +                        return getOtherNonNullStringElements();
  +                    }
  +
  +                };
  +            }
  +        };
  +    }
  +
   }
  
  
  
  1.11      +5 -5      jakarta-commons/collections/src/test/org/apache/commons/collections/TestList.java
  
  Index: TestList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestList.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestList.java	21 Jun 2002 03:28:54 -0000	1.10
  +++ TestList.java	13 Aug 2002 00:26:52 -0000	1.11
  @@ -981,7 +981,7 @@
        *  modified when the sublist is.
        */
       public BulkTest bulkTestSubList() {
  -        if (getFullElements().length < 10) return null;
  +        if (getFullElements().length - 6 < 10) return null;
           return new BulkTestSubList(this);
       }
   
  
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/TestBoundedCollection.java
  
  Index: TestBoundedCollection.java
  ===================================================================
  package org.apache.commons.collections;
  
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.List;
  
  
  public abstract class TestBoundedCollection extends BulkTest {
  
      public TestBoundedCollection(String name) {
          super(name);
      }
  
  
      public abstract Collection boundedCollection();
  
  
      public void testIllegalAdd() {
          Collection c = boundedCollection();
          Integer i = new Integer(3);
          try {
              c.add(i);
              fail("Collection should be full.");
          } catch (IllegalStateException e) {
              // expected
          }
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains(i));
      }
  
  
      public void testIllegalAddAll() {
          Collection c = boundedCollection();
          List elements = new ArrayList();
          elements.add("one");
          elements.add("two");
          elements.add(new Integer(3));
          elements.add("four");
          try {
              c.addAll(elements);
              fail("Collection should be full.");
          } catch (IllegalStateException e) {
              // expected
          }
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains("one"));   
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains("two"));   
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains(new Integer(3)));   
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains("four"));   
      }
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/TestBufferUtils.java
  
  Index: TestBufferUtils.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBufferUtils.java,v 1.1 2002/08/13 00:26:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/13 00:26:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections;
  
  import junit.framework.Test;
  import java.util.Collection;
  import java.util.Arrays;
  import java.util.ArrayList;
  
  
  /**
   *  Tests for BufferUtils.
   */
  public class TestBufferUtils extends BulkTest {
  
      public TestBufferUtils(String name) {
          super(name);
      }
  
  
      public static Test suite() {
          return BulkTest.makeSuite(TestBufferUtils.class);
      }
  
      public void testNothing() {
      }
  
      public BulkTest bulkTestPredicatedBuffer() {
          return new TestPredicatedCollection("") {
  
              public Collection predicatedCollection() {
                  Predicate p = getPredicate();
                  return BufferUtils.predicatedBuffer(new ArrayStack(), p);
              }
  
              public BulkTest bulkTestAll() {
                  return new TestCollection("") {
                      public Collection makeCollection() {
                          return predicatedCollection();
                      }
  
                      public Collection makeConfirmedCollection() {
                          return new ArrayStack();
                      }
  
                      public Collection makeConfirmedFullCollection() {
                          ArrayStack list = new ArrayStack();
                          list.addAll(java.util.Arrays.asList(getFullElements()));
                          return list;
                      }
  
                      public Object[] getFullElements() {
                          return getFullNonNullStringElements();
                      }
  
                      public Object[] getOtherElements() {
                          return getOtherNonNullStringElements();
                      }
  
                  };
              }
          };
      }
  
  
      public BulkTest bulkTestBoundedBuffer() {
          return new TestBoundedCollection("") {
  
              public Collection boundedCollection() {
                  return BufferUtils.boundedBuffer(new ArrayStack(), 0);
              }
  
              public BulkTest bulkTestAll() {
                  return new TestCollection("") {
                      public Collection makeCollection() {
                          Object[] full = getFullElements();
                          Object[] other = getOtherElements();
                          int maxSize = full.length + other.length;
                          return BufferUtils.boundedBuffer(new ArrayStack(), maxSize);
                      }
  
                      public Collection makeConfirmedCollection() {
                          return new ArrayStack();
                      }
  
                      public Collection makeConfirmedFullCollection() {
                          ArrayStack list = new ArrayStack();
                          list.addAll(java.util.Arrays.asList(getFullElements()));
                          return list;
                      }
  
                  };
              }
          };
      }
  
  
      public BulkTest bulkTestUnmodifiableBuffer() {
          return new TestCollection("") {
              public boolean isAddSupported() {
                  return false;
              }
  
              public boolean isRemoveSupported() {
                  return false;
              }
  
              public Collection makeCollection() {
                  return BufferUtils.unmodifiableBuffer(new ArrayStack());
              }
  
              public Collection makeFullCollection() {
                  ArrayStack a = new ArrayStack();
                  a.addAll(Arrays.asList(getFullElements()));
                  return BufferUtils.unmodifiableBuffer(a);
              }
  
  
              public Collection makeConfirmedCollection() {
                  return new ArrayStack();
              }
  
              public Collection makeConfirmedFullCollection() {
                  ArrayStack a = new ArrayStack();
                  a.addAll(Arrays.asList(getFullElements()));
                  return a;
              }
  
          };
      }
  
  
  }
  
  
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/TestListUtils.java
  
  Index: TestListUtils.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestListUtils.java,v 1.1 2002/08/13 00:26:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/13 00:26:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections;
  
  import junit.framework.Test;
  import java.util.Collection;
  import java.util.List;
  import java.util.Arrays;
  import java.util.ArrayList;
  
  
  public class TestListUtils extends BulkTest {
  
      public TestListUtils(String name) {
          super(name);
      }
  
      public static Test suite() {
          return BulkTest.makeSuite(TestListUtils.class);
      }
  
      public void testNothing() {
      }
  
      public BulkTest bulkTestPredicatedList() {
          return new TestPredicatedCollection("") {
  
              public Collection predicatedCollection() {
                  Predicate p = getPredicate();
                  return ListUtils.predicatedList(new ArrayList(), p);
              }
  
              public BulkTest bulkTestAll() {
                  return new TestList("") {
                      public List makeEmptyList() {
                          return (List)predicatedCollection();
                      }
  
                      public Object[] getFullElements() {
                          return getFullNonNullStringElements();
                      }
  
                      public Object[] getOtherElements() {
                          return getOtherNonNullStringElements();
                      }
  
                  };
              }
          };
      }
  
  
  
      public BulkTest bulkTestBoundedList() {
          return new TestBoundedCollection("") {
  
              public Collection boundedCollection() {
                  return ListUtils.boundedList(new ArrayList(), 0);
              }
  
              public BulkTest bulkTestAll() {
                  return new TestList("") {
                      public List makeEmptyList() {
                          Object[] full = getFullElements();
                          Object[] other = getOtherElements();
                          int maxSize = full.length * 2; // + other.length;
                          return ListUtils.boundedList(new ArrayList(), maxSize);
                      }
  
                  };
              }
          };
      }
  
  
      public void testLazyList() {
          List list = ListUtils.lazyList(new ArrayList(), new SimpleObjectFactory() {
  
              private int index;
  
              public Object createObject() {
                  index++;
                  return new Integer(index);
              }
          });
  
          Integer I = (Integer)list.get(5);
          assertEquals(6, list.size());
  
          I = (Integer)list.get(5);
          assertEquals(6, list.size());
      }
  
  
  }
  
  
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/TestMapUtils.java
  
  Index: TestMapUtils.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMapUtils.java,v 1.1 2002/08/13 00:26:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/13 00:26:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections;
  
  import junit.framework.Test;
  import java.util.Arrays;
  import java.util.Map;
  import java.util.HashMap;
  import java.util.Iterator;
  
  
  /**
   *  Tests for MapUtils.
   */
  public class TestMapUtils extends BulkTest {
  
      public TestMapUtils(String name) {
          super(name);
      }
  
  
      public static Test suite() {
          return BulkTest.makeSuite(TestMapUtils.class);
      }
  
      public Predicate getPredicate() {
          return new Predicate() {
              public boolean evaluate(Object o) {
                  return o instanceof String;
              }
          };
      }
  
  
      public void testPredicatedMapIllegalPut() {
          Predicate p = getPredicate();
          Map map = MapUtils.predicatedMap(new HashMap(), p, p);
          try {
              map.put("Hi", new Integer(3));
              fail("Illegal value should raise IllegalArgument");
          } catch (IllegalArgumentException e) {
              // expected
          }
  
          try {
              map.put(new Integer(3), "Hi");
              fail("Illegal key should raise IllegalArgument");
          } catch (IllegalArgumentException e) {
              // expected
          }
  
          assertTrue(!map.containsKey(new Integer(3)));
          assertTrue(!map.containsValue(new Integer(3)));
  
          Map map2 = new HashMap();
          map2.put("A", "a");
          map2.put("B", "b");
          map2.put("C", "c");
          map2.put("c", new Integer(3));
  
          try {
              map.putAll(map2);
              fail("Illegal value should raise IllegalArgument");
          } catch (IllegalArgumentException e) {
              // expected
          }
  
          map.put("E", "e");
          Iterator iterator = map.entrySet().iterator();
          try {
              Map.Entry entry = (Map.Entry)iterator.next();
              entry.setValue(new Integer(3));
              fail("Illegal value should raise IllegalArgument");
          } catch (IllegalArgumentException e) {
              // expected
          }
      }
  
  
      public BulkTest bulkTestPredicatedMap() {
          return new TestMap("") {
              public boolean useNullKey() {
                  return false;
              }
  
              public boolean useNullValue() {
                  return false;
              }
  
              public Map makeEmptyMap() {
                  Predicate p = getPredicate();
                  return MapUtils.predicatedMap(new HashMap(), p, p);
              }
          };
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/TestPredicatedCollection.java
  
  Index: TestPredicatedCollection.java
  ===================================================================
  package org.apache.commons.collections;
  
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.List;
  
  
  public abstract class TestPredicatedCollection extends BulkTest {
  
      public TestPredicatedCollection(String name) {
          super(name);
      }
  
  
      protected abstract Collection predicatedCollection();
  
      protected Predicate getPredicate() {
          return new Predicate() {
              public boolean evaluate(Object o) {
                  return o instanceof String;
              }
          };
      }
  
  
      public void testIllegalAdd() {
          Collection c = predicatedCollection();
          Integer i = new Integer(3);
          try {
              c.add(i);
              fail("Integer should fail string predicate.");
          } catch (IllegalArgumentException e) {
              // expected
          }
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains(i));   
      }
  
  
      public void testIllegalAddAll() {
          Collection c = predicatedCollection();
          List elements = new ArrayList();
          elements.add("one");
          elements.add("two");
          elements.add(new Integer(3));
          elements.add("four");
          try {
              c.addAll(elements);
              fail("Integer should fail string predicate.");
          } catch (IllegalArgumentException e) {
              // expected
          }
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains("one"));   
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains("two"));   
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains(new Integer(3)));   
          assertTrue("Collection shouldn't contain illegal element", 
           !c.contains("four"));   
      }
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/TestSetUtils.java
  
  Index: TestSetUtils.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestSetUtils.java,v 1.1 2002/08/13 00:26:52 pjack Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/13 00:26:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.collections;
  
  import junit.framework.Test;
  import java.util.Collection;
  import java.util.Set;
  import java.util.HashSet;
  
  
  /**
   *  Tests for SetUtils.
   */
  public class TestSetUtils extends BulkTest {
  
      public TestSetUtils(String name) {
          super(name);
      }
  
      public static Test suite() {
          return BulkTest.makeSuite(TestSetUtils.class);
      }
  
      public void testNothing() {
      }
  
      public BulkTest bulkTestPredicatedSet() {
          return new TestPredicatedCollection("") {
  
              public Collection predicatedCollection() {
                  Predicate p = getPredicate();
                  return SetUtils.predicatedSet(new HashSet(), p);
              }
  
              public BulkTest bulkTestAll() {
                  return new TestSet("") {
                      public Set makeEmptySet() {
                          return (Set)predicatedCollection();
                      }
  
                      public Object[] getFullElements() {
                          return getFullNonNullStringElements();
                      }
  
                      public Object[] getOtherElements() {
                          return getOtherNonNullStringElements();
                      }
  
                  };
              }
          };
      }
  
  
  
      public BulkTest bulkTestBoundedSet() {
          return new TestBoundedCollection("") {
  
              public Collection boundedCollection() {
                  return SetUtils.boundedSet(new HashSet(), 0);
              }
  
              public BulkTest bulkTestAll() {
                  return new TestSet("") {
                      public Set makeEmptySet() {
                          Object[] full = getFullElements();
                          Object[] other = getOtherElements();
                          int maxSize = full.length + other.length;
                          return SetUtils.boundedSet(new HashSet(), maxSize);
                      }
  
                  };
              }
          };
      }
  
  
  
  
  }
  
  
  
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  
                       
  
  

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


Mime
View raw message