commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/decorators TypedList.java AbstractListIteratorDecorator.java SynchronizedCollection.java PredicatedList.java PredicatedCollection.java AbstractListDecorator.java UnmodifiableCollection.java SynchronizedList.java LazyList.java AbstractCollectionDecorator.java UnmodifiableList.java FixedSizeList.java
Date Wed, 07 May 2003 11:20:22 GMT
scolebourne    2003/05/07 04:20:22

  Modified:    collections/src/java/org/apache/commons/collections/decorators
                        TypedList.java AbstractListIteratorDecorator.java
                        SynchronizedCollection.java PredicatedList.java
                        PredicatedCollection.java
                        AbstractListDecorator.java
                        UnmodifiableCollection.java SynchronizedList.java
                        LazyList.java AbstractCollectionDecorator.java
                        UnmodifiableList.java FixedSizeList.java
  Log:
  Tidy imports, javadoc and field access
  
  Revision  Changes    Path
  1.2       +5 -5      jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/TypedList.java
  
  Index: TypedList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/TypedList.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypedList.java	29 Apr 2003 18:43:47 -0000	1.1
  +++ TypedList.java	7 May 2003 11:20:21 -0000	1.2
  @@ -76,9 +76,9 @@
   public class TypedList extends PredicatedList {
   
       /**
  -     * Factory method to create a typed collection.
  +     * Factory method to create a typed list.
        * <p>
  -     * If there are any elements already in the collection being decorated, they
  +     * If there are any elements already in the list being decorated, they
        * are validated.
        * 
        * @param list  the list to decorate, must not be null
  @@ -93,7 +93,7 @@
       /**
        * Constructor that wraps (not copies).
        * <p>
  -     * If there are any elements already in the collection being decorated, they
  +     * If there are any elements already in the list being decorated, they
        * are validated.
        * 
        * @param list  the list to decorate, must not be null
  
  
  
  1.3       +13 -3     jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/AbstractListIteratorDecorator.java
  
  Index: AbstractListIteratorDecorator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/AbstractListIteratorDecorator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractListIteratorDecorator.java	5 May 2003 23:25:22 -0000	1.2
  +++ AbstractListIteratorDecorator.java	7 May 2003 11:20:21 -0000	1.3
  @@ -77,7 +77,7 @@
   public abstract class AbstractListIteratorDecorator implements ListIterator {
   
       /** The iterator to delegate to */
  -    protected final ListIterator iterator;
  +    private final ListIterator iterator;
   
       /**
        * Constructor that wraps the specified iterator.
  @@ -87,7 +87,17 @@
       public AbstractListIteratorDecorator(ListIterator iterator) {
           this.iterator = iterator;
       }
  +    
  +    /**
  +     * Gets the decorated iterator.
  +     * 
  +     * @return the decorated iterator
  +     */
  +    protected ListIterator getIterator() {
  +        return iterator;
  +    }
   
  +    //-----------------------------------------------------------------------
       public boolean hasNext() {
           return iterator.hasNext();
       }
  
  
  
  1.2       +83 -34    jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/SynchronizedCollection.java
  
  Index: SynchronizedCollection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/SynchronizedCollection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SynchronizedCollection.java	29 Apr 2003 18:43:47 -0000	1.1
  +++ SynchronizedCollection.java	7 May 2003 11:20:21 -0000	1.2
  @@ -80,6 +80,8 @@
   
       /** The collection to decorate */
       protected final Collection collection;
  +    /** The object to lock on, needed for List/SortedSet views */
  +    protected final Object lock;
   
       /**
        * Factory method to create a synchronized collection.
  @@ -102,30 +104,59 @@
               throw new IllegalArgumentException("Collection must not be null");
           }
           this.collection = collection;
  +        this.lock = this;
       }
   
  -    public synchronized boolean add(Object object) {
  -        return collection.add(object);
  +    /**
  +     * Constructor that wraps (not copies).
  +     * 
  +     * @param coll  the collection to decorate, must not be null
  +     * @param lock  the lock object to use, must not be null
  +     * @throws IllegalArgumentException if the collection is null
  +     */
  +    protected SynchronizedCollection(Collection collection, Object lock) {
  +        if (collection == null) {
  +            throw new IllegalArgumentException("Collection must not be null");
  +        }
  +        this.collection = collection;
  +        this.lock = lock;
  +    }
  +
  +    //-----------------------------------------------------------------------
  +    public boolean add(Object object) {
  +        synchronized (lock) {
  +            return collection.add(object);
  +        }
       }
   
  -    public synchronized boolean addAll(Collection coll) {
  -        return collection.addAll(coll);
  +    public boolean addAll(Collection coll) {
  +        synchronized (lock) {
  +            return collection.addAll(coll);
  +        }
       }
   
  -    public synchronized void clear() {
  -        collection.clear();
  +    public void clear() {
  +        synchronized (lock) {
  +            collection.clear();
  +        }
       }
   
  -    public synchronized boolean contains(Object object) {
  -        return collection.contains(object);
  +    public boolean contains(Object object) {
  +        synchronized (lock) {
  +            return collection.contains(object);
  +        }
       }
   
  -    public synchronized boolean containsAll(Collection coll) {
  -        return collection.containsAll(coll);
  +    public boolean containsAll(Collection coll) {
  +        synchronized (lock) {
  +            return collection.containsAll(coll);
  +        }
       }
   
  -    public synchronized boolean isEmpty() {
  -        return collection.isEmpty();
  +    public boolean isEmpty() {
  +        synchronized (lock) {
  +            return collection.isEmpty();
  +        }
       }
   
       /**
  @@ -142,43 +173,61 @@
           return collection.iterator();
       }
   
  -    public synchronized Object[] toArray() {
  -        return collection.toArray();
  +    public Object[] toArray() {
  +        synchronized (lock) {
  +            return collection.toArray();
  +        }
       }
   
  -    public synchronized Object[] toArray(Object[] object) {
  -        return collection.toArray(object);
  +    public Object[] toArray(Object[] object) {
  +        synchronized (lock) {
  +            return collection.toArray(object);
  +        }
       }
   
  -    public synchronized boolean remove(Object object) {
  -        return collection.remove(object);
  +    public boolean remove(Object object) {
  +        synchronized (lock) {
  +            return collection.remove(object);
  +        }
       }
   
  -    public synchronized boolean removeAll(Collection coll) {
  -        return collection.removeAll(coll);
  +    public boolean removeAll(Collection coll) {
  +        synchronized (lock) {
  +            return collection.removeAll(coll);
  +        }
       }
   
  -    public synchronized boolean retainAll(Collection coll) {
  -        return collection.retainAll(coll);
  +    public boolean retainAll(Collection coll) {
  +        synchronized (lock) {
  +            return collection.retainAll(coll);
  +        }
       }
   
  -    public synchronized int size() {
  -        return collection.size();
  +    public int size() {
  +        synchronized (lock) {
  +            return collection.size();
  +        }
       }
   
  -    public synchronized boolean equals(Object object) {
  -        if (object == this) {
  -            return true;
  +    public boolean equals(Object object) {
  +        synchronized (lock) {
  +            if (object == this) {
  +                return true;
  +            }
  +            return collection.equals(object);
           }
  -        return collection.equals(object);
       }
   
  -    public synchronized int hashCode() {
  -        return collection.hashCode();
  +    public int hashCode() {
  +        synchronized (lock) {
  +            return collection.hashCode();
  +        }
       }
   
  -    public synchronized String toString() {
  -        return collection.toString();
  +    public String toString() {
  +        synchronized (lock) {
  +            return collection.toString();
  +        }
       }
   
   }
  
  
  
  1.2       +20 -14    jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/PredicatedList.java
  
  Index: PredicatedList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/PredicatedList.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PredicatedList.java	29 Apr 2003 18:43:47 -0000	1.1
  +++ PredicatedList.java	7 May 2003 11:20:21 -0000	1.2
  @@ -80,15 +80,15 @@
   public class PredicatedList extends PredicatedCollection implements List {
   
       /**
  -     * Factory method to create a predicated (validating) collection.
  +     * Factory method to create a predicated (validating) list.
        * <p>
        * If there are any elements already in the list being decorated, they
        * are validated.
        * 
  -     * @param coll  the collection to decorate, must not be null
  +     * @param list  the list to decorate, must not be null
        * @param predicate  the predicate to use for validation, must not be null
  -     * @throws IllegalArgumentException if collection or predicate is null
  -     * @throws IllegalArgumentException if the collection contains invalid elements
  +     * @throws IllegalArgumentException if list or predicate is null
  +     * @throws IllegalArgumentException if the list contains invalid elements
        */
       public static List decorate(List list, Predicate predicate) {
           return new PredicatedList(list, predicate);
  @@ -102,13 +102,23 @@
        * 
        * @param list  the list to decorate, must not be null
        * @param predicate  the predicate to use for validation, must not be null
  -     * @throws IllegalArgumentException if collection or predicate is null
  -     * @throws IllegalArgumentException if the collection contains invalid elements
  +     * @throws IllegalArgumentException if list or predicate is null
  +     * @throws IllegalArgumentException if the list contains invalid elements
        */
       protected PredicatedList(List list, Predicate predicate) {
           super(list, predicate);
       }
   
  +    /**
  +     * Gets the list being decorated.
  +     * 
  +     * @return the decorated list
  +     */
  +    protected List getList() {
  +        return (List) getCollection();
  +    }
  +
  +    //-----------------------------------------------------------------------
       public void add(int index, Object object) {
           validate(object);
           getList().add(index, object);
  @@ -141,12 +151,12 @@
           return new AbstractListIteratorDecorator(getList().listIterator(i)) {
               public void add(Object object) {
                   validate(object);
  -                iterator.add(object);
  +                getIterator().add(object);
               }
   
               public void set(Object object) {
                   validate(object);
  -                iterator.set(object);
  +                getIterator().set(object);
               }
           };
       }
  @@ -163,10 +173,6 @@
       public List subList(int fromIndex, int toIndex) {
           List sub = getList().subList(fromIndex, toIndex);
           return new PredicatedList(sub, predicate);
  -    }
  -
  -    protected List getList() {
  -        return (List) collection;
       }
   
   }
  
  
  
  1.2       +5 -4      jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/PredicatedCollection.java
  
  Index: PredicatedCollection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/PredicatedCollection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PredicatedCollection.java	29 Apr 2003 18:43:47 -0000	1.1
  +++ PredicatedCollection.java	7 May 2003 11:20:21 -0000	1.2
  @@ -117,6 +117,7 @@
           }
       }
   
  +    //-----------------------------------------------------------------------
       /**
        * Override to validate the object being added to ensure it matches
        * the predicate.
  @@ -127,7 +128,7 @@
        */
       public boolean add(Object object) {
           validate(object);
  -        return collection.add(object);
  +        return getCollection().add(object);
       }
   
       /**
  @@ -143,7 +144,7 @@
           for (Iterator it = coll.iterator(); it.hasNext(); ) {
               validate(it.next());
           }
  -        return collection.addAll(coll);
  +        return getCollection().addAll(coll);
       }
   
       /**
  
  
  
  1.3       +12 -6     jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/AbstractListDecorator.java
  
  Index: AbstractListDecorator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/AbstractListDecorator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractListDecorator.java	5 May 2003 23:25:22 -0000	1.2
  +++ AbstractListDecorator.java	7 May 2003 11:20:21 -0000	1.3
  @@ -83,6 +83,16 @@
           super(list);
       }
   
  +    /**
  +     * Gets the list being decorated.
  +     * 
  +     * @return the decorated list
  +     */
  +    protected List getList() {
  +        return (List) getCollection();
  +    }
  +
  +    //-----------------------------------------------------------------------
       public void add(int index, Object object) {
           getList().add(index, object);
       }
  @@ -121,10 +131,6 @@
   
       public List subList(int fromIndex, int toIndex) {
           return getList().subList(fromIndex, toIndex);
  -    }
  -
  -    protected List getList() {
  -        return (List) collection;
       }
   
   }
  
  
  
  1.3       +4 -3      jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/UnmodifiableCollection.java
  
  Index: UnmodifiableCollection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/UnmodifiableCollection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnmodifiableCollection.java	5 May 2003 23:25:22 -0000	1.2
  +++ UnmodifiableCollection.java	7 May 2003 11:20:21 -0000	1.3
  @@ -96,6 +96,7 @@
           super(coll);
       }
   
  +    //-----------------------------------------------------------------------
       /**
        * Override as method unsupported.
        * @throws UnsupportedOperationException
  @@ -126,7 +127,7 @@
        * @return unmodifiable iterator
        */
       public Iterator iterator() {
  -        return IteratorUtils.unmodifiableIterator(collection.iterator());
  +        return IteratorUtils.unmodifiableIterator(getCollection().iterator());
       }
   
       /**
  
  
  
  1.3       +63 -27    jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/SynchronizedList.java
  
  Index: SynchronizedList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/SynchronizedList.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SynchronizedList.java	5 May 2003 23:25:22 -0000	1.2
  +++ SynchronizedList.java	7 May 2003 11:20:21 -0000	1.3
  @@ -77,7 +77,7 @@
        * Factory method to create a synchronized list.
        * 
        * @param list  the list to decorate, must not be null
  -     * @throws IllegalArgumentException if collection is null
  +     * @throws IllegalArgumentException if list is null
        */
       public static List decorate(List list) {
           return new SynchronizedList(list);
  @@ -93,24 +93,55 @@
           super(list);
       }
   
  -    public synchronized void add(int index, Object object) {
  -        getList().add(index, object);
  +    /**
  +     * Constructor that wraps (not copies).
  +     * 
  +     * @param list  the list to decorate, must not be null
  +     * @param lock  the lock to use, must not be null
  +     * @throws IllegalArgumentException if list is null
  +     */
  +    protected SynchronizedList(List list, Object lock) {
  +        super(list, lock);
  +    }
  +
  +    /**
  +     * Gets the decorated list.
  +     * 
  +     * @return the decorated list
  +     */
  +    protected List getList() {
  +        return (List) collection;
  +    }
  +
  +    //-----------------------------------------------------------------------
  +    public void add(int index, Object object) {
  +        synchronized (lock) {
  +            getList().add(index, object);
  +        }
       }
   
  -    public synchronized boolean addAll(int index, Collection coll) {
  -        return getList().addAll(index, coll);
  +    public boolean addAll(int index, Collection coll) {
  +        synchronized (lock) {
  +            return getList().addAll(index, coll);
  +        }
       }
   
  -    public synchronized Object get(int index) {
  -        return getList().get(index);
  +    public Object get(int index) {
  +        synchronized (lock) {
  +            return getList().get(index);
  +        }
       }
   
  -    public synchronized int indexOf(Object object) {
  -        return getList().indexOf(object);
  +    public int indexOf(Object object) {
  +        synchronized (lock) {
  +            return getList().indexOf(object);
  +        }
       }
   
  -    public synchronized int lastIndexOf(Object object) {
  -        return getList().lastIndexOf(object);
  +    public int lastIndexOf(Object object) {
  +        synchronized (lock) {
  +            return getList().lastIndexOf(object);
  +        }
       }
   
       /**
  @@ -141,20 +172,25 @@
           return getList().listIterator(index);
       }
   
  -    public synchronized Object remove(int index) {
  -        return getList().remove(index);
  -    }
  -
  -    public synchronized Object set(int index, Object object) {
  -        return getList().set(index, object);
  -    }
  -
  -    public synchronized List subList(int fromIndex, int toIndex) {
  -        return getList().subList(fromIndex, toIndex);
  -    }
  -
  -    protected List getList() {
  -        return (List) collection;
  +    public Object remove(int index) {
  +        synchronized (lock) {
  +            return getList().remove(index);
  +        }
  +    }
  +
  +    public Object set(int index, Object object) {
  +        synchronized (lock) {
  +            return getList().set(index, object);
  +        }
  +    }
  +
  +    public List subList(int fromIndex, int toIndex) {
  +        synchronized (lock) {
  +            List list = getList().subList(fromIndex, toIndex);
  +            // the lock is passed into the constructor here to ensure that the sublist
is
  +            // synchronized on the same lock as the parent list
  +            return new SynchronizedList(list, lock);
  +        }
       }
   
   }
  
  
  
  1.2       +3 -3      jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/LazyList.java
  
  Index: LazyList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/LazyList.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LazyList.java	29 Apr 2003 18:43:47 -0000	1.1
  +++ LazyList.java	7 May 2003 11:20:21 -0000	1.2
  @@ -127,7 +127,7 @@
           this.factory = factory;
       }
   
  -    
  +    //-----------------------------------------------------------------------
       /**
        * Decorate the get method to perform the lazy behaviour.
        * <p>
  
  
  
  1.2       +13 -3     jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/AbstractCollectionDecorator.java
  
  Index: AbstractCollectionDecorator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/AbstractCollectionDecorator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractCollectionDecorator.java	29 Apr 2003 18:43:47 -0000	1.1
  +++ AbstractCollectionDecorator.java	7 May 2003 11:20:21 -0000	1.2
  @@ -85,7 +85,7 @@
   public abstract class AbstractCollectionDecorator implements Collection {
   
       /** The collection being decorated */
  -    protected final Collection collection;
  +    private final Collection collection;
   
       /**
        * Constructor that wraps (not copies).
  @@ -100,6 +100,16 @@
           this.collection = coll;
       }
   
  +    /**
  +     * Gets the collection being decorated.
  +     * 
  +     * @return the decorated collection
  +     */
  +    protected Collection getCollection() {
  +        return collection;
  +    }
  +
  +    //-----------------------------------------------------------------------
       public boolean add(Object object) {
           return collection.add(object);
       }
  
  
  
  1.3       +12 -6     jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/UnmodifiableList.java
  
  Index: UnmodifiableList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/UnmodifiableList.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnmodifiableList.java	5 May 2003 23:25:22 -0000	1.2
  +++ UnmodifiableList.java	7 May 2003 11:20:21 -0000	1.3
  @@ -94,6 +94,16 @@
           super(list);
       }
   
  +    /**
  +     * Gets the list being decorated.
  +     * 
  +     * @return the decorated list
  +     */
  +    protected List getList() {
  +        return (List) getCollection();
  +    }
  +
  +    //-----------------------------------------------------------------------
       public void add(int index, Object object) {
           throw new UnsupportedOperationException();
       }
  @@ -133,10 +143,6 @@
       public List subList(int fromIndex, int toIndex) {
           List sub = getList().subList(fromIndex, toIndex);
           return new UnmodifiableList(sub);
  -    }
  -
  -    protected List getList() {
  -        return (List) collection;
       }
   
   }
  
  
  
  1.3       +29 -17    jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/FixedSizeList.java
  
  Index: FixedSizeList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/FixedSizeList.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FixedSizeList.java	5 May 2003 23:25:22 -0000	1.2
  +++ FixedSizeList.java	7 May 2003 11:20:21 -0000	1.3
  @@ -96,6 +96,16 @@
           super(list);
       }
   
  +    /**
  +     * Gets the list being decorated.
  +     * 
  +     * @return the decorated list
  +     */
  +    protected List getList() {
  +        return (List) getCollection();
  +    }
  +
  +    //-----------------------------------------------------------------------
       public void add(int index, Object object) {
           throw new UnsupportedOperationException();
       }
  @@ -121,19 +131,7 @@
       }
   
       public ListIterator listIterator(int index) {
  -        return new AbstractListIteratorDecorator(getList().listIterator(index)) {
  -            public void remove() {
  -                throw new UnsupportedOperationException();
  -            }
  -
  -            public void add(Object object) {
  -                throw new UnsupportedOperationException();
  -            }
  -
  -            public void remove(Object object) {
  -                throw new UnsupportedOperationException();
  -            }
  -        };
  +        return new FixedSizeListIterator(getList().listIterator(index));
       }
   
       public Object remove(int index) {
  @@ -149,8 +147,22 @@
           return new FixedSizeList(sub);
       }
   
  -    protected List getList() {
  -        return (List) collection;
  +    /**
  +     * List iterator that only permits changes via set()
  +     */
  +    public static class FixedSizeListIterator extends AbstractListIteratorDecorator {
  +        protected FixedSizeListIterator(ListIterator iterator) {
  +            super(iterator);
  +        }
  +        public void remove() {
  +            throw new UnsupportedOperationException();
  +        }
  +        public void add(Object object) {
  +            throw new UnsupportedOperationException();
  +        }
  +        public void remove(Object object) {
  +            throw new UnsupportedOperationException();
  +        }
       }
   
   }
  
  
  

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


Mime
View raw message