Add observableXxx methods to Utils classes

Switch to our Unmodified/Synchonized classes


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-09-21 16:26:08 +00:00
parent 93534d8124
commit 74e8d90a8c
6 changed files with 166 additions and 45 deletions

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BagUtils.java,v 1.12 2003/08/31 17:26:43 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BagUtils.java,v 1.13 2003/09/21 16:26:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -67,13 +67,15 @@ import org.apache.commons.collections.decorators.TypedBag;
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: 1.12 $ $Date: 2003/08/31 17:26:43 $
* @version $Revision: 1.13 $ $Date: 2003/09/21 16:26:08 $
*
* @author Paul Jack
* @author Stephen Colebourne
@ -187,6 +189,26 @@ public class BagUtils {
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);
}
//-----------------------------------------------------------------------
/**
* Returns a synchronized (thread-safe) sorted bag backed by the given

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BufferUtils.java,v 1.13 2003/08/31 17:26:44 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BufferUtils.java,v 1.14 2003/09/21 16:26:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -63,12 +63,14 @@ import org.apache.commons.collections.decorators.SynchronizedBuffer;
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: 1.13 $ $Date: 2003/08/31 17:26:44 $
* @version $Revision: 1.14 $ $Date: 2003/09/21 16:26:08 $
*
* @author Paul Jack
* @author Stephen Colebourne
@ -78,7 +80,7 @@ public class BufferUtils {
/**
* 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 class BufferUtils {
public BufferUtils() {
}
//-----------------------------------------------------------------------
/**
* Returns a synchronized buffer backed by the given buffer.
* Much like the synchronized collections returned by
@ -183,4 +186,24 @@ public class BufferUtils {
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);
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.41 2003/09/09 21:53:04 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.42 2003/09/21 16:26:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -70,17 +70,21 @@ import java.util.Map;
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: 1.41 $ $Date: 2003/09/09 21:53:04 $
* @version $Revision: 1.42 $ $Date: 2003/09/21 16:26:08 $
*
* @author Rodney Waldhoff
* @author Paul Jack
@ -911,27 +915,27 @@ public class CollectionUtils {
* }
* </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);
}
/**
@ -981,4 +985,24 @@ public class CollectionUtils {
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);
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/ListUtils.java,v 1.20 2003/08/31 17:26:44 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/ListUtils.java,v 1.21 2003/09/21 16:26:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -66,18 +66,21 @@ import java.util.List;
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: 1.20 $ $Date: 2003/08/31 17:26:44 $
* @version $Revision: 1.21 $ $Date: 2003/09/21 16:26:08 $
*
* @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 @@ public class ListUtils {
/**
* 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 @@ public class ListUtils {
* }
* </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 @@ public class ListUtils {
}
/**
* 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

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/MapUtils.java,v 1.36 2003/09/20 12:03:52 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/MapUtils.java,v 1.37 2003/09/21 16:26:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -80,9 +80,12 @@ import org.apache.commons.collections.decorators.TransformedMap;
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.
@ -105,7 +108,7 @@ import org.apache.commons.collections.decorators.TypedSortedMap;
* </ul>
*
* @since Commons Collections 1.0
* @version $Revision: 1.36 $ $Date: 2003/09/20 12:03:52 $
* @version $Revision: 1.37 $ $Date: 2003/09/21 16:26:08 $
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author <a href="mailto:nissim@nksystems.com">Nissim Karpenstein</a>
@ -890,14 +893,14 @@ public class MapUtils {
/**
* 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 @@ public class MapUtils {
/**
* 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);
}
/**

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SetUtils.java,v 1.16 2003/09/09 22:28:36 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SetUtils.java,v 1.17 2003/09/21 16:26:08 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -67,17 +67,23 @@ import java.util.TreeSet;
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: 1.16 $ $Date: 2003/09/09 22:28:36 $
* @version $Revision: 1.17 $ $Date: 2003/09/21 16:26:08 $
*
* @author Paul Jack
* @author Stephen Colebourne
@ -190,27 +196,27 @@ public class SetUtils {
* }
* </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 @@ public class SetUtils {
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 @@ public class SetUtils {
* }
* </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);
}
/**