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 SetUtils.java MapUtils.java ListUtils.java CollectionUtils.java BufferUtils.java BagUtils.java
Date Sun, 21 Sep 2003 16:26:08 GMT
scolebourne    2003/09/21 09:26:08

  Modified:    collections/src/java/org/apache/commons/collections
                        SetUtils.java MapUtils.java ListUtils.java
                        CollectionUtils.java BufferUtils.java BagUtils.java
  Log:
  Add observableXxx methods to Utils classes
  Switch to our Unmodified/Synchonized classes
  
  Revision  Changes    Path
  1.17      +37 -12    jakarta-commons/collections/src/java/org/apache/commons/collections/SetUtils.java
  
  Index: SetUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SetUtils.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- SetUtils.java	9 Sep 2003 22:28:36 -0000	1.16
  +++ SetUtils.java	21 Sep 2003 16:26:08 -0000	1.17
  @@ -67,14 +67,20 @@
   import org.apache.commons.collections.decorators.OrderedSet;
   import org.apache.commons.collections.decorators.PredicatedSet;
   import org.apache.commons.collections.decorators.PredicatedSortedSet;
  +import org.apache.commons.collections.decorators.SynchronizedSet;
  +import org.apache.commons.collections.decorators.SynchronizedSortedSet;
   import org.apache.commons.collections.decorators.TransformedSet;
   import org.apache.commons.collections.decorators.TransformedSortedSet;
   import org.apache.commons.collections.decorators.TypedSet;
   import org.apache.commons.collections.decorators.TypedSortedSet;
  +import org.apache.commons.collections.decorators.UnmodifiableSet;
  +import org.apache.commons.collections.decorators.UnmodifiableSortedSet;
  +import org.apache.commons.collections.observed.ModificationListener;
  +import org.apache.commons.collections.observed.ObservableSet;
   
   /**
  - * Provides static utility methods and decorators for {@link Set} 
  - * and {@link SortedSet} instances.
  + * Provides utility methods and decorators for
  + * {@link Set} and {@link SortedSet} instances.
    *
    * @since Commons Collections 2.1
    * @version $Revision$ $Date$
  @@ -190,27 +196,27 @@
        * }
        * </pre>
        * 
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        * 
        * @param set  the set to synchronize, must not be null
        * @return a synchronized set backed by the given set
        * @throws IllegalArgumentException  if the set is null
        */
       public static Set synchronizedSet(Set set) {
  -        return Collections.synchronizedSet(set);
  +        return SynchronizedSet.decorate(set);
       }
   
       /**
        * Returns an unmodifiable set backed by the given set.
        * <p>
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        *
        * @param set  the set to make unmodifiable, must not be null
        * @return an unmodifiable set backed by the given set
        * @throws IllegalArgumentException  if the set is null
        */
       public static Set unmodifiableSet(Set set) {
  -        return Collections.unmodifiableSet(set);
  +        return UnmodifiableSet.decorate(set);
       }
   
       /**
  @@ -257,6 +263,25 @@
           return TransformedSet.decorate(set, transformer);
       }
       
  +    /**
  +     * Returns an observable set where changes are notified to listeners.
  +     * <p>
  +     * This method creates an observable set and attaches the specified listener.
  +     * If more than one listener or other complex setup is required then the
  +     * ObservableSet class should be accessed directly.
  +     *
  +     * @param set  the set to decorate, must not be null
  +     * @param listener  set listener, must not be null
  +     * @return the observed set
  +     * @throws IllegalArgumentException if the set or listener is null
  +     * @throws IllegalArgumentException if there is no valid handler for the listener
  +     */
  +    public static ObservableSet observableSet(Set set, ModificationListener listener) {
  +        if (listener == null) {
  +            throw new IllegalArgumentException("Listener must not be null");
  +        }
  +        return ObservableSet.decorate(set, listener);
  +    }
       
       /**
        * Returns a set that maintains the order of elements that are added
  @@ -290,27 +315,27 @@
        * }
        * </pre>
        * 
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        * 
        * @param set  the sorted set to synchronize, must not be null
        * @return a synchronized set backed by the given set
        * @throws IllegalArgumentException  if the set is null
        */
       public static SortedSet synchronizedSortedSet(SortedSet set) {
  -        return Collections.synchronizedSortedSet(set);
  +        return SynchronizedSortedSet.decorate(set);
       }
   
       /**
        * Returns an unmodifiable sorted set backed by the given sorted set.
        * <p>
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        *
        * @param set  the sorted set to make unmodifiable, must not be null
        * @return an unmodifiable set backed by the given set
        * @throws IllegalArgumentException  if the set is null
        */
       public static SortedSet unmodifiableSortedSet(SortedSet set) {
  -        return Collections.unmodifiableSortedSet(set);
  +        return UnmodifiableSortedSet.decorate(set);
       }
   
       /**
  
  
  
  1.37      +10 -7     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.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- MapUtils.java	20 Sep 2003 12:03:52 -0000	1.36
  +++ MapUtils.java	21 Sep 2003 16:26:08 -0000	1.37
  @@ -80,9 +80,12 @@
   import org.apache.commons.collections.decorators.TransformedSortedMap;
   import org.apache.commons.collections.decorators.TypedMap;
   import org.apache.commons.collections.decorators.TypedSortedMap;
  +import org.apache.commons.collections.decorators.UnmodifiableMap;
  +import org.apache.commons.collections.decorators.UnmodifiableSortedMap;
   
   /** 
  - * Provides useful utility methods for {@link Map Map} instances.
  + * Provides utility methods and decorators for
  + * {@link Map} and {@link SortedMap} instances.
    * <p>
    * It contains various typesafe methods
    * as well as other useful features like deep copying.
  @@ -890,14 +893,14 @@
       /**
        * Returns an unmodifiable map backed by the given map.
        * <p>
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        *
        * @param map  the map to make unmodifiable, must not be null
        * @return an unmodifiable map backed by the given map
        * @throws IllegalArgumentException  if the map is null
        */
       public static Map unmodifiableMap(Map map) {
  -        return Collections.unmodifiableMap(map);
  +        return UnmodifiableMap.decorate(map);
       }
   
       /**
  @@ -1065,14 +1068,14 @@
       /**
        * Returns an unmodifiable sorted map backed by the given sorted map.
        * <p>
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        *
        * @param map  the sorted map to make unmodifiable, must not be null
        * @return an unmodifiable map backed by the given map
        * @throws IllegalArgumentException  if the map is null
        */
       public static Map unmodifiableSortedMap(SortedMap map) {
  -        return Collections.unmodifiableSortedMap(map);
  +        return UnmodifiableSortedMap.decorate(map);
       }
   
       /**
  
  
  
  1.21      +35 -11    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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ListUtils.java	31 Aug 2003 17:26:44 -0000	1.20
  +++ ListUtils.java	21 Sep 2003 16:26:08 -0000	1.21
  @@ -66,18 +66,21 @@
   import org.apache.commons.collections.decorators.FixedSizeList;
   import org.apache.commons.collections.decorators.LazyList;
   import org.apache.commons.collections.decorators.PredicatedList;
  +import org.apache.commons.collections.decorators.SynchronizedList;
   import org.apache.commons.collections.decorators.TransformedList;
   import org.apache.commons.collections.decorators.TypedList;
  +import org.apache.commons.collections.decorators.UnmodifiableList;
  +import org.apache.commons.collections.observed.ModificationListener;
  +import org.apache.commons.collections.observed.ObservableList;
   
   /**
  - * Contains static utility methods and decorators for {@link List} 
  - * instances.
  + * Provides utility methods and decorators for {@link List} instances.
    *
    * @since Commons Collections 1.0
    * @version $Revision$ $Date$
    * 
  - * @author  <a href="mailto:fede@apache.org">Federico Barbieri</a>
  - * @author  <a href="mailto:donaldp@apache.org">Peter Donald</a>
  + * @author Federico Barbieri
  + * @author Peter Donald
    * @author Paul Jack
    * @author Stephen Colebourne
    * @author Neil O'Toole
  @@ -126,6 +129,7 @@
       /**
        * Subtracts all elements in the second list from the first list,
        * placing the results in a new list.
  +     * <p>
        * This differs from {@link List#removeAll(Collection)} in that
        * cardinality is respected; if <Code>list1</Code> contains two
        * occurrences of <Code>null</Code> and <Code>list2</Code>
only
  @@ -275,27 +279,27 @@
        * }
        * </pre>
        * 
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        * 
        * @param list  the list to synchronize, must not be null
        * @return a synchronized list backed by the given list
        * @throws IllegalArgumentException  if the list is null
        */
       public static List synchronizedList(List list) {
  -        return Collections.synchronizedList(list);
  +        return SynchronizedList.decorate(list);
       }
   
       /**
        * Returns an unmodifiable list backed by the given list.
        * <p>
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        *
        * @param list  the list to make unmodifiable, must not be null
        * @return an unmodifiable list backed by the given list
        * @throws IllegalArgumentException  if the list is null
        */
       public static List unmodifiableList(List list) {
  -        return Collections.unmodifiableList(list);
  +        return UnmodifiableList.decorate(list);
       }
   
       /**
  @@ -343,7 +347,27 @@
       }
       
       /**
  -     * Returns a "lazy" list whose elements will be created on demand.<P>
  +     * Returns an observable list where changes are notified to listeners.
  +     * <p>
  +     * This method creates an observable list and attaches the specified listener.
  +     * If more than one listener or other complex setup is required then the
  +     * ObservableList class should be accessed directly.
  +     *
  +     * @param list  the list to decorate, must not be null
  +     * @param listener  list listener, must not be null
  +     * @return the observed list
  +     * @throws IllegalArgumentException if the list or listener is null
  +     * @throws IllegalArgumentException if there is no valid handler for the listener
  +     */
  +    public static ObservableList observableList(List list, ModificationListener listener)
{
  +        if (listener == null) {
  +            throw new IllegalArgumentException("Listener must not be null");
  +        }
  +        return ObservableList.decorate(list, listener);
  +    }
  +    
  +    /**
  +     * Returns a "lazy" list whose elements will be created on demand.
        * <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
  
  
  
  1.42      +31 -7     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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- CollectionUtils.java	9 Sep 2003 21:53:04 -0000	1.41
  +++ CollectionUtils.java	21 Sep 2003 16:26:08 -0000	1.42
  @@ -70,14 +70,18 @@
   import java.util.Set;
   
   import org.apache.commons.collections.decorators.PredicatedCollection;
  +import org.apache.commons.collections.decorators.SynchronizedCollection;
   import org.apache.commons.collections.decorators.TransformedCollection;
   import org.apache.commons.collections.decorators.TypedCollection;
   import org.apache.commons.collections.decorators.UnmodifiableBoundedCollection;
  +import org.apache.commons.collections.decorators.UnmodifiableCollection;
   import org.apache.commons.collections.iterators.ArrayIterator;
   import org.apache.commons.collections.iterators.EnumerationIterator;
  +import org.apache.commons.collections.observed.ModificationListener;
  +import org.apache.commons.collections.observed.ObservableCollection;
   
   /**
  - * A set of {@link Collection} related utility methods.
  + * Provides utility methods and decorators for {@link Collection} instances.
    *
    * @since Commons Collections 1.0
    * @version $Revision$ $Date$
  @@ -911,27 +915,27 @@
        * }
        * </pre>
        * 
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        * 
        * @param collection  the collection to synchronize, must not be null
        * @return a synchronized collection backed by the given collection
        * @throws IllegalArgumentException  if the collection is null
        */
       public static Collection synchronizedCollection(Collection collection) {
  -        return Collections.synchronizedCollection(collection);
  +        return SynchronizedCollection.decorate(collection);
       }
   
       /**
        * Returns an unmodifiable collection backed by the given collection.
        * <p>
  -     * This method uses the implementation in {@link java.util.Collections Collections}.
  +     * This method uses the implementation in the decorators subpackage.
        *
        * @param collection  the collection to make unmodifiable, must not be null
        * @return an unmodifiable collection backed by the given collection
        * @throws IllegalArgumentException  if the collection is null
        */
       public static Collection unmodifiableCollection(Collection collection) {
  -        return Collections.unmodifiableCollection(collection);
  +        return UnmodifiableCollection.decorate(collection);
       }
   
       /**
  @@ -979,6 +983,26 @@
        */
       public static Collection transformedCollection(Collection collection, Transformer transformer)
{
           return TransformedCollection.decorate(collection, transformer);
  +    }
  +    
  +    /**
  +     * Returns an observable collection where changes are notified to listeners.
  +     * <p>
  +     * This method creates an observable collection and attaches the specified listener.
  +     * If more than one listener or other complex setup is required then the
  +     * ObservableCollection class should be accessed directly.
  +     *
  +     * @param collection  the collection to decorate, must not be null
  +     * @param listener  collection listener, must not be null
  +     * @return the observed collection
  +     * @throws IllegalArgumentException if the collection or listener is null
  +     * @throws IllegalArgumentException if there is no valid handler for the listener
  +     */
  +    public static ObservableCollection observableCollection(Collection collection, ModificationListener
listener) {
  +        if (listener == null) {
  +            throw new IllegalArgumentException("Listener must not be null");
  +        }
  +        return ObservableCollection.decorate(collection, listener);
       }
       
   }
  
  
  
  1.14      +27 -4     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- BufferUtils.java	31 Aug 2003 17:26:44 -0000	1.13
  +++ BufferUtils.java	21 Sep 2003 16:26:08 -0000	1.14
  @@ -63,9 +63,11 @@
   import org.apache.commons.collections.decorators.TransformedBuffer;
   import org.apache.commons.collections.decorators.TypedBuffer;
   import org.apache.commons.collections.decorators.UnmodifiableBuffer;
  +import org.apache.commons.collections.observed.ModificationListener;
  +import org.apache.commons.collections.observed.ObservableBuffer;
   
   /**
  - * Contains static utility methods for operating on {@link Buffer} objects.
  + * Provides utility methods and decorators for {@link Buffer} instances.
    *
    * @since Commons Collections 2.1
    * @version $Revision$ $Date$
  @@ -78,7 +80,7 @@
       /**
        * An empty unmodifiable buffer.
        */
  -    public static final Buffer EMPTY_BUFFER = UnmodifiableBuffer.decorate(new ArrayStack());
  +    public static final Buffer EMPTY_BUFFER = UnmodifiableBuffer.decorate(new ArrayStack(1));
       
       /**
        * <code>BufferUtils</code> should not normally be instantiated.
  @@ -86,6 +88,7 @@
       public BufferUtils() {
       }
   
  +    //-----------------------------------------------------------------------
       /**
        * Returns a synchronized buffer backed by the given buffer.
        * Much like the synchronized collections returned by 
  @@ -181,6 +184,26 @@
        */
       public static Buffer transformedBuffer(Buffer buffer, Transformer transformer) {
           return TransformedBuffer.decorate(buffer, transformer);
  +    }
  +    
  +    /**
  +     * Returns an observable buffer where changes are notified to listeners.
  +     * <p>
  +     * This method creates an observable buffer and attaches the specified listener.
  +     * If more than one listener or other complex setup is required then the
  +     * ObservableBuffer class should be accessed directly.
  +     *
  +     * @param buffer  the buffer to decorate, must not be null
  +     * @param listener  buffer listener, must not be null
  +     * @return the observed buffer
  +     * @throws IllegalArgumentException if the buffer or listener is null
  +     * @throws IllegalArgumentException if there is no valid handler for the listener
  +     */
  +    public static ObservableBuffer observableBuffer(Buffer buffer, ModificationListener
listener) {
  +        if (listener == null) {
  +            throw new IllegalArgumentException("Listener must not be null");
  +        }
  +        return ObservableBuffer.decorate(buffer, listener);
       }
       
   }
  
  
  
  1.13      +26 -4     jakarta-commons/collections/src/java/org/apache/commons/collections/BagUtils.java
  
  Index: BagUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/BagUtils.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BagUtils.java	31 Aug 2003 17:26:43 -0000	1.12
  +++ BagUtils.java	21 Sep 2003 16:26:08 -0000	1.13
  @@ -67,10 +67,12 @@
   import org.apache.commons.collections.decorators.TypedSortedBag;
   import org.apache.commons.collections.decorators.UnmodifiableBag;
   import org.apache.commons.collections.decorators.UnmodifiableSortedBag;
  +import org.apache.commons.collections.observed.ModificationListener;
  +import org.apache.commons.collections.observed.ObservableBag;
   
   /**
  - * Provides utility methods and decorators for {@link Bag} 
  - * and {@link SortedBag} instances.
  + * Provides utility methods and decorators for
  + * {@link Bag} and {@link SortedBag} instances.
    *
    * @since Commons Collections 2.1
    * @version $Revision$ $Date$
  @@ -185,6 +187,26 @@
        */
       public static Bag transformedBag(Bag bag, Transformer transformer) {
           return TransformedBag.decorate(bag, transformer);
  +    }
  +    
  +    /**
  +     * Returns an observable bag where changes are notified to listeners.
  +     * <p>
  +     * This method creates an observable bag and attaches the specified listener.
  +     * If more than one listener or other complex setup is required then the
  +     * ObservableBag class should be accessed directly.
  +     *
  +     * @param bag  the bag to decorate, must not be null
  +     * @param listener  bag listener, must not be null
  +     * @return the observed bag
  +     * @throws IllegalArgumentException if the bag or listener is null
  +     * @throws IllegalArgumentException if there is no valid handler for the listener
  +     */
  +    public static ObservableBag observableBag(Bag bag, ModificationListener listener) {
  +        if (listener == null) {
  +            throw new IllegalArgumentException("Listener must not be null");
  +        }
  +        return ObservableBag.decorate(bag, listener);
       }
       
       //-----------------------------------------------------------------------
  
  
  

Mime
View raw message