From 1c4942acca1441065ccb714de38a05eb71db81dd Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 28 Sep 2003 21:54:35 +0000 Subject: [PATCH] Add ObservableSortedBag/Set git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131201 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/collections/BagUtils.java | 25 +++++++++++++++++-- .../apache/commons/collections/SetUtils.java | 25 +++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/commons/collections/BagUtils.java b/src/java/org/apache/commons/collections/BagUtils.java index 64c8e14f7..da7624bac 100644 --- a/src/java/org/apache/commons/collections/BagUtils.java +++ b/src/java/org/apache/commons/collections/BagUtils.java @@ -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.13 2003/09/21 16:26:08 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.14 2003/09/28 21:54:35 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -69,13 +69,14 @@ 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; +import org.apache.commons.collections.observed.ObservableSortedBag; /** * Provides utility methods and decorators for * {@link Bag} and {@link SortedBag} instances. * * @since Commons Collections 2.1 - * @version $Revision: 1.13 $ $Date: 2003/09/21 16:26:08 $ + * @version $Revision: 1.14 $ $Date: 2003/09/28 21:54:35 $ * * @author Paul Jack * @author Stephen Colebourne @@ -298,5 +299,25 @@ public class BagUtils { public static SortedBag transformedSortedBag(SortedBag bag, Transformer transformer) { return TransformedSortedBag.decorate(bag, transformer); } + + /** + * Returns an observable sorted bag where changes are notified to listeners. + *

+ * This method creates an observable sorted bag and attaches the specified listener. + * If more than one listener or other complex setup is required then the + * ObservableSortedBag 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 ObservableSortedBag observableSortedBag(SortedBag bag, ModificationListener listener) { + if (listener == null) { + throw new IllegalArgumentException("Listener must not be null"); + } + return ObservableSortedBag.decorate(bag, listener); + } } diff --git a/src/java/org/apache/commons/collections/SetUtils.java b/src/java/org/apache/commons/collections/SetUtils.java index d96d9db46..ff0b3e62c 100644 --- a/src/java/org/apache/commons/collections/SetUtils.java +++ b/src/java/org/apache/commons/collections/SetUtils.java @@ -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.17 2003/09/21 16:26:08 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.18 2003/09/28 21:54:35 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -77,13 +77,14 @@ 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; +import org.apache.commons.collections.observed.ObservableSortedSet; /** * Provides utility methods and decorators for * {@link Set} and {@link SortedSet} instances. * * @since Commons Collections 2.1 - * @version $Revision: 1.17 $ $Date: 2003/09/21 16:26:08 $ + * @version $Revision: 1.18 $ $Date: 2003/09/28 21:54:35 $ * * @author Paul Jack * @author Stephen Colebourne @@ -383,4 +384,24 @@ public class SetUtils { return TransformedSortedSet.decorate(set, transformer); } + /** + * Returns an observable sorted set where changes are notified to listeners. + *

+ * This method creates an observable set and attaches the specified listener. + * If more than one listener or other complex setup is required then the + * ObservableSortedSet 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 ObservableSortedSet observableSortedSet(SortedSet set, ModificationListener listener) { + if (listener == null) { + throw new IllegalArgumentException("Listener must not be null"); + } + return ObservableSortedSet.decorate(set, listener); + } + }