Refactor observed classes and packages to make better use of scoping

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131131 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-09-03 23:54:26 +00:00
parent b8dba646f1
commit 4c0753a53e
25 changed files with 856 additions and 394 deletions

View File

@ -1,200 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/event/Attic/ModificationHandlerFactory.java,v 1.1 2003/09/03 00:11:28 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements 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 Software Foundation.
*
* 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.event;
import java.util.Collection;
import org.apache.commons.collections.decorators.ObservedCollection;
/**
* Defines a factory for creating ModificationHandler instances and utilities
* for using the factories.
* <p>
* If an application wants to register its own event handler classes, it should
* do so using this class. This must be done during initialization to be
* fully thread-safe. There are two steps:
* <ol>
* <li>A factory must be created that is a subclass of this class
* <li>One of the <code>addFactory</code> methods must be called
* </ol>
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 00:11:28 $
*
* @author Stephen Colebourne
*/
public abstract class ModificationHandlerFactory {
/** The list of factories, cannot pre-populate as factories are subclasses */
private static ModificationHandlerFactory[] factories = new ModificationHandlerFactory[0];
// Static access to factories
//-----------------------------------------------------------------------
/**
* Creates a handler subclass based on the specified listener.
* <p>
* The method is defined in terms of an Object to allow for unusual
* listeners, such as a Swing model object.
*
* @param listener a listener object to create a handler for
* @return an instantiated handler with the listener attached
* @throws IllegalArgumentException if no suitable handler
*/
public static final ModificationHandler createHandler(final Collection coll, final Object listener) {
for (int i = 0; i < factories.length; i++) {
ModificationHandler handler = factories[i].create(coll, listener);
if (handler != null) {
return handler;
}
}
throw new IllegalArgumentException("Unrecognised listener type: " +
(listener == null ? "null" : listener.getClass().getName()));
}
/**
* Adds a handler factory to the list available for use.
* This factory will be checked after the others in the list.
* <p>
* This method is used to add your own event handler to the supplied ones.
* Registering the factory will enable the standard <code>decorate</code>
* method on <code>ObservedColection</code> to create your handler.
* <p>
* This method is NOT threadsafe! It should only be called during initialization.
*
* @param factory the factory to add, may be null
*/
public static void addFactory(final ModificationHandlerFactory factory) {
addFactory(factory, false);
}
/**
* Adds a handler factory to the list available for use selecting whether
* to override existing factories or not.
* <p>
* This method is used to add your own event handler to the supplied ones.
* Registering the factory will enable the standard <code>decorate</code>
* method on <code>ObservedColection</code> to create your handler.
* <p>
* It is also possible to replace the Jakarta handlers using this method.
* Obviously this should be done with care in a shared web environment!
* <p>
* This method is NOT threadsafe! It should only be called during initialization.
*
* @param factory the factory to add, may be null
*/
public static void addFactory(final ModificationHandlerFactory factory, final boolean override) {
if (factory != null) {
ModificationHandlerFactory[] array = new ModificationHandlerFactory[factories.length + 1];
if (override) {
System.arraycopy(factories, 0, array, 1, factories.length);
array[0] = factory;
} else {
System.arraycopy(factories, 0, array, 0, factories.length);
array[factories.length] = factory;
}
factories = array;
}
}
// Initialize the collection-handler pair
//-----------------------------------------------------------------------
/**
* Initializes handler specified with the collection.
* <p>
* The method avoids exposing an implementation detail on ModificationHandler.
*
* @param handler the handler to initialize
* @param coll the collection to store
* @return an instantiated handler with the listener attached
*/
public static void initHandler(final ModificationHandler handler, final ObservedCollection coll) {
handler.init(coll);
}
// Constructor
//-----------------------------------------------------------------------
/**
* Restrictive constructor.
*/
protected ModificationHandlerFactory() {
super();
}
// Abstract factory
//-----------------------------------------------------------------------
/**
* Creates a handler subclass for the specified listener.
* <p>
* The implementation will normally check to see if the listener
* is of a suitable type, and then cast it. <code>null</code> is
* returned if this factory does not handle the specified type.
* <p>
* The listener is defined in terms of an Object to allow for unusual
* listeners, such as a Swing model object.
* <p>
* The collection the handler is for is passed in to allow for a different
* handler to be selected for the same listener type based on the collection.
*
* @param coll the collection being decorated
* @param listener a listener object to create a handler for
* @return an instantiated handler with the listener attached,
* or null if the listener type is unsuited to this factory
*/
protected abstract ModificationHandler create(Collection coll, Object 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/event/Attic/ModificationEvent.java,v 1.2 2003/08/31 17:25:49 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ModificationEvent.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,7 +55,7 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed;
import java.util.Collection;
import java.util.EventObject;
@ -66,7 +66,7 @@ import java.util.EventObject;
* This class can be used as is, but generally it is subclassed.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/08/31 17:25:49 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/

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/event/Attic/ModificationEventType.java,v 1.2 2003/08/31 17:25:49 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ModificationEventType.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,7 +55,7 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed;
/**
* Defines event constants for event handling and matching.
@ -74,7 +74,7 @@ package org.apache.commons.collections.event;
* They may negated using the bitwise NOT, <code>~</code>.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/08/31 17:25:49 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/
@ -84,29 +84,37 @@ public class ModificationEventType {
public static final int ADD = 0x00000001;
/** The method add(int,Object) */
public static final int ADD_INDEXED = 0x00000002;
/** The method add(Object,int) */
public static final int ADD_NCOPIES = 0x00000004;
/** The method addAll(Collection) */
public static final int ADD_ALL = 0x00000004;
public static final int ADD_ALL = 0x00000010;
/** The method addAll(int,Collection) */
public static final int ADD_ALL_INDEXED=0x00000008;
public static final int ADD_ALL_INDEXED=0x00000020;
/** The method remove(Object) */
public static final int REMOVE = 0x00000010;
public static final int REMOVE = 0x00000100;
/** The method remove(int) */
public static final int REMOVE_INDEXED =0x00000020;
public static final int REMOVE_INDEXED =0x00000200;
/** The method remove(Object,int) */
public static final int REMOVE_NCOPIES =0x00000400;
/** The method removeAll(Collection) */
public static final int REMOVE_ALL = 0x00000040;
public static final int REMOVE_ALL = 0x00001000;
/** The method retainAll(Collection) */
public static final int RETAIN_ALL = 0x00000080;
public static final int RETAIN_ALL = 0x00002000;
/** The method clear() */
public static final int CLEAR = 0x00000100;
public static final int CLEAR = 0x00004000;
/** The method set(int,Object) */
public static final int SET_INDEXED = 0x00000200;
public static final int SET_INDEXED = 0x00010000;
/** All add methods */
public static final int GROUP_ADD = ADD | ADD_INDEXED | ADD_ALL | ADD_ALL_INDEXED;
public static final int GROUP_ADD = ADD | ADD_INDEXED | ADD_NCOPIES | ADD_ALL | ADD_ALL_INDEXED;
/** All methods that change without structure modification */
public static final int GROUP_CHANGE = SET_INDEXED;
/** All remove methods */
public static final int GROUP_REMOVE = REMOVE | REMOVE_INDEXED | REMOVE_ALL;
public static final int GROUP_REMOVE = REMOVE | REMOVE_NCOPIES | REMOVE_INDEXED | REMOVE_ALL;
/** All retain methods */
public static final int GROUP_RETAIN = RETAIN_ALL;
/** All clear methods */
@ -117,14 +125,14 @@ public class ModificationEventType {
/** All indexed methods */
public static final int GROUP_INDEXED = ADD_INDEXED | ADD_ALL_INDEXED | REMOVE_INDEXED | SET_INDEXED;
/** All non indexed methods */
public static final int GROUP_NON_INDEXED = ADD | ADD_ALL | REMOVE | REMOVE_ALL | RETAIN_ALL | CLEAR;
/** All bulk methods (xxxAll and clear) */
public static final int GROUP_BULK = ADD_ALL | ADD_ALL_INDEXED | REMOVE_ALL | RETAIN_ALL | CLEAR;
public static final int GROUP_NON_INDEXED = ADD | ADD_NCOPIES | ADD_ALL | REMOVE | REMOVE_NCOPIES | REMOVE_ALL | RETAIN_ALL | CLEAR;
/** All bulk methods (xxxAll, clear, Bag nCopies) */
public static final int GROUP_BULK = ADD_NCOPIES | ADD_ALL | ADD_ALL_INDEXED | REMOVE_NCOPIES | REMOVE_ALL | RETAIN_ALL | CLEAR;
/** All non bulk methods */
public static final int GROUP_NON_BULK = ADD | ADD_INDEXED | REMOVE | REMOVE_INDEXED | SET_INDEXED;
/** All methods that modify the structure */
public static final int GROUP_STRUCTURE_MODIFIED =
ADD | ADD_INDEXED | ADD_ALL | ADD_ALL_INDEXED | REMOVE | REMOVE_INDEXED | REMOVE_ALL | RETAIN_ALL | CLEAR;
ADD | ADD_NCOPIES | ADD_INDEXED | ADD_ALL | ADD_ALL_INDEXED | REMOVE | REMOVE_NCOPIES | REMOVE_INDEXED | REMOVE_ALL | RETAIN_ALL | CLEAR;
/** All non structure modifying methods */
public static final int GROUP_NON_STRUCTURE_MODIFIED = SET_INDEXED;
@ -134,6 +142,8 @@ public class ModificationEventType {
public static final int GROUP_FROM_SET = GROUP_FROM_COLLECTION;
/** All methods sent by a List */
public static final int GROUP_FROM_LIST = GROUP_FROM_COLLECTION | ADD_INDEXED | ADD_ALL_INDEXED | REMOVE_INDEXED | SET_INDEXED;
/** All methods sent by a List */
public static final int GROUP_FROM_BAG = GROUP_FROM_COLLECTION | ADD_NCOPIES | REMOVE_NCOPIES;
/** No methods */
public static final int GROUP_NONE = 0x00000000;
@ -159,12 +169,16 @@ public class ModificationEventType {
return "Add";
case ADD_INDEXED:
return "AddIndexed";
case ADD_NCOPIES:
return "AddNCopies";
case ADD_ALL:
return "AddAll";
case ADD_ALL_INDEXED:
return "AddAllIndexed";
case REMOVE:
return "Remove";
case REMOVE_NCOPIES:
return "RemoveNCopies";
case REMOVE_INDEXED:
return "RemoveIndexed";
case REMOVE_ALL:

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/event/Attic/ModificationHandler.java,v 1.5 2003/09/03 00:11:28 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ModificationHandler.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,11 +55,10 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed;
import java.util.Collection;
import org.apache.commons.collections.decorators.ObservedCollection;
/**
* Defines a handler for collection modification events.
@ -69,15 +68,20 @@ import org.apache.commons.collections.decorators.ObservedCollection;
* It also provides a default implementation that forwards to single methods.
* <p>
* This class could have been implemented as an interface, however to do so
* would prevent the addition of extra events in the future.
* would prevent the addition of extra events in the future. It does mean
* that if you subclass this class, you must check it when you upgrade to a
* later collections release.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/09/03 00:11:28 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/
public abstract class ModificationHandler {
/** Singleton factory */
static final ModificationHandlerFactory FACTORY = new Factory();
/** The collection being observed */
private ObservedCollection collection = null;
@ -233,27 +237,27 @@ public abstract class ModificationHandler {
protected abstract boolean preEvent(int type, int index, Object object, int repeat);
/**
* Handles the post event.
* Handles the post event where the collections method returns boolean for success.
*
* @param success true if the method succeeded in changing the collection
* @param modified true if the method succeeded in changing the collection
* @param type the event type to send
* @param index the index where the change starts
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
*/
protected abstract void postEvent(boolean success, int type, int index, Object object, int repeat);
protected abstract void postEvent(boolean modified, int type, int index, Object object, int repeat);
/**
* Handles the post event.
* Handles the post event where the collections method has a return value.
*
* @param success true if the method succeeded in changing the collection
* @param modified true if the method succeeded in changing the collection
* @param type the event type to send
* @param index the index where the change starts
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
* @param result the result of the method
*/
protected abstract void postEvent(boolean success, int type, int index, Object object, int repeat, Object result);
protected abstract void postEvent(boolean modified, int type, int index, Object object, int repeat, Object result);
// Event handling
//-----------------------------------------------------------------------
@ -263,9 +267,9 @@ public abstract class ModificationHandler {
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param object the object being added
* @return true
* @return true to process modification
*/
public boolean preAdd(Object object) {
protected boolean preAdd(Object object) {
return preEvent(ModificationEventType.ADD, -1, object, 1);
}
@ -277,36 +281,62 @@ public abstract class ModificationHandler {
* @param object the object being added
* @param result the result from the add method
*/
public void postAdd(Object object, boolean result) {
protected void postAdd(Object object, boolean result) {
postEvent(result, ModificationEventType.ADD, -1, object, 1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before add(int,obj) is called.
* Store data and send event before add(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param index the index to add at
* @param object the object being added
* @return true
* @return true to process modification
*/
public boolean preAdd(int index, Object object) {
protected boolean preAdd(int index, Object object) {
return preEvent(ModificationEventType.ADD_INDEXED, index, object, 1);
}
/**
* Send an event after add(int,obj) is called.
* Send an event after add(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param index the index to add at
* @param object the object being added
*/
public void postAdd(int index, Object object) {
protected void postAdd(int index, Object object) {
postEvent(true, ModificationEventType.ADD_INDEXED, index, object, 1, null);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before add(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param object the object being added
* @param nCopies the number of copies being added
* @return true to process modification
*/
protected boolean preAdd(Object object, int nCopies) {
return preEvent(ModificationEventType.ADD_NCOPIES, -1, object, nCopies);
}
/**
* Send an event after add(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param object the object being added
* @param nCopies the number of copies being added
*/
protected void postAdd(Object object, int nCopies, boolean result) {
postEvent(true, ModificationEventType.ADD_NCOPIES, -1, object, nCopies, (result ? Boolean.TRUE : Boolean.FALSE));
}
//-----------------------------------------------------------------------
/**
* Store data and send event before addAll(coll) is called.
@ -314,9 +344,9 @@ public abstract class ModificationHandler {
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param coll the collection being added
* @return true
* @return true to process modification
*/
public boolean preAddAll(Collection coll) {
protected boolean preAddAll(Collection coll) {
return preEvent(ModificationEventType.ADD_ALL, -1, coll, 1);
}
@ -328,26 +358,26 @@ public abstract class ModificationHandler {
* @param coll the collection being added
* @param result the result from the addAll method
*/
public void postAddAll(Collection coll, boolean result) {
protected void postAddAll(Collection coll, boolean result) {
postEvent(result, ModificationEventType.ADD_ALL, -1, coll, 1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before addAll(int,coll) is called.
* Store data and send event before addAll(int,coll) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param index the index to addAll at
* @param coll the collection being added
* @return true
* @return true to process modification
*/
public boolean preAddAll(int index, Collection coll) {
protected boolean preAddAll(int index, Collection coll) {
return preEvent(ModificationEventType.ADD_ALL_INDEXED, index, coll, 1);
}
/**
* Send an event after addAll(int,coll) is called.
* Send an event after addAll(int,coll) is called on a List.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int)}.
*
@ -355,7 +385,7 @@ public abstract class ModificationHandler {
* @param coll the collection being added
* @param result the result from the addAll method
*/
public void postAddAll(int index, Collection coll, boolean result) {
protected void postAddAll(int index, Collection coll, boolean result) {
postEvent(result, ModificationEventType.ADD_ALL_INDEXED, index, coll, 1);
}
@ -365,9 +395,9 @@ public abstract class ModificationHandler {
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @return true
* @return true to process modification
*/
public boolean preClear() {
protected boolean preClear() {
return preEvent(ModificationEventType.CLEAR, -1, null, 1);
}
@ -376,7 +406,7 @@ public abstract class ModificationHandler {
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int)}.
*/
public void postClear() {
protected void postClear() {
// assumes a modification occurred
postEvent(true, ModificationEventType.CLEAR, -1, null, 1, null);
}
@ -388,9 +418,9 @@ public abstract class ModificationHandler {
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param object the object being removed
* @return true
* @return true to process modification
*/
public boolean preRemove(Object object) {
protected boolean preRemove(Object object) {
return preEvent(ModificationEventType.REMOVE, -1, object, 1);
}
@ -402,35 +432,61 @@ public abstract class ModificationHandler {
* @param object the object being removed
* @param result the result from the remove method
*/
public void postRemove(Object object, boolean result) {
protected void postRemove(Object object, boolean result) {
postEvent(result, ModificationEventType.REMOVE, -1, object, 1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove(int) is called.
* Store data and send event before remove(int) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param index the index to remove at
* @return true
* @return true to process modification
*/
public boolean preRemove(int index) {
protected boolean preRemove(int index) {
return preEvent(ModificationEventType.REMOVE_INDEXED, index, null, 1);
}
/**
* Send an event after remove(int) is called.
* Send an event after remove(int) is called on a List.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param index the index to remove at
* @param result the result from the remove method
*/
public void postRemove(int index, Object result) {
protected void postRemove(int index, Object result) {
postEvent(true, ModificationEventType.REMOVE_INDEXED, index, null, 1, result);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param object the object being removed
* @param nCopies the number of copies being removed
* @return true to process modification
*/
protected boolean preRemove(Object object, int nCopies) {
return preEvent(ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies);
}
/**
* Send an event after remove(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param object the object being removed
* @param nCopies the number of copies being removed
*/
protected void postRemove(Object object, int nCopies, boolean result) {
postEvent(result, ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before removeAll(coll) is called.
@ -438,9 +494,9 @@ public abstract class ModificationHandler {
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param coll the collection being removed
* @return true
* @return true to process modification
*/
public boolean preRemoveAll(Collection coll) {
protected boolean preRemoveAll(Collection coll) {
return preEvent(ModificationEventType.REMOVE_ALL, -1, coll, 1);
}
@ -452,7 +508,7 @@ public abstract class ModificationHandler {
* @param coll the collection being removed
* @param result the result from the removeAll method
*/
public void postRemoveAll(Collection coll, boolean result) {
protected void postRemoveAll(Collection coll, boolean result) {
postEvent(result, ModificationEventType.REMOVE_ALL, -1, coll, 1);
}
@ -463,9 +519,9 @@ public abstract class ModificationHandler {
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param coll the collection being retained
* @return true
* @return true to process modification
*/
public boolean preRetainAll(Collection coll) {
protected boolean preRetainAll(Collection coll) {
return preEvent(ModificationEventType.RETAIN_ALL, -1, coll, 1);
}
@ -477,26 +533,26 @@ public abstract class ModificationHandler {
* @param coll the collection being retained
* @param result the result from the retainAll method
*/
public void postRetainAll(Collection coll, boolean result) {
protected void postRetainAll(Collection coll, boolean result) {
postEvent(result, ModificationEventType.RETAIN_ALL, -1, coll, 1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before set(int,obj) is called.
* Store data and send event before set(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
*
* @param index the index to add at
* @param object the object being added
* @return true
* @return true to process modification
*/
public boolean preSet(int index, Object object) {
protected boolean preSet(int index, Object object) {
return preEvent(ModificationEventType.SET_INDEXED, index, object, 1);
}
/**
* Send an event after set(int,obj) is called.
* Send an event after set(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
@ -504,8 +560,9 @@ public abstract class ModificationHandler {
* @param object the object being added
* @param result the result from the set method
*/
public void postSet(int index, Object object, Object result) {
postEvent(true, ModificationEventType.SET_INDEXED, index, object, 1, result);
protected void postSet(int index, Object object, Object result) {
// reference check for modification, in case equals() has issues (eg. performance)
postEvent((object != result), ModificationEventType.SET_INDEXED, index, object, 1, result);
}
// toString
@ -523,5 +580,19 @@ public abstract class ModificationHandler {
}
return name + '[' + (collection == null ? "" : "initialised") + ']';
}
// Factory to create handler from handler
//-----------------------------------------------------------------------
/**
* Factory that casts the listener to a handler.
*/
static class Factory implements ModificationHandlerFactory {
public ModificationHandler createHandler(Collection coll, Object listener) {
if (listener instanceof ModificationHandler) {
return (ModificationHandler) listener;
}
return null;
}
}
}

View File

@ -0,0 +1,101 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ModificationHandlerFactory.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements 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 Software Foundation.
*
* 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.observed;
import java.util.Collection;
/**
* Defines a factory for creating ModificationHandler instances.
* <p>
* If an application wants to register its own event handler classes, it should
* do so using this class. This must be done during initialization to be
* fully thread-safe. There are two steps:
* <ol>
* <li>A factory must be created that is an implementation of this class
* <li>One of the <code>registerFactory</code> methods must be called on ObservedCollection
* </ol>
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/
public interface ModificationHandlerFactory {
/**
* Creates a handler subclass for the specified listener.
* <p>
* The implementation will normally check to see if the listener
* is of a suitable type, and then cast it. <code>null</code> is
* returned if this factory does not handle the specified type.
* <p>
* The listener is defined in terms of an Object to allow for unusual
* listeners, such as a Swing model object.
* <p>
* The collection the handler is for is passed in to allow for a different
* handler to be selected for the same listener type based on the collection.
*
* @param coll the collection being decorated
* @param listener a listener object to create a handler for
* @return an instantiated handler with the listener attached,
* or null if the listener type is unsuited to this factory
*/
ModificationHandler createHandler(Collection coll, Object 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/event/Attic/ModificationListener.java,v 1.4 2003/08/31 22:44:54 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ModificationListener.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,7 +55,7 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed;
import java.util.EventListener;
@ -66,7 +66,7 @@ import java.util.EventListener;
* role of an event listener for collection modification events.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/08/31 22:44:54 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/

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/event/Attic/ModificationVetoedException.java,v 1.3 2003/08/31 17:25:49 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ModificationVetoedException.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,14 +55,14 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed;
/**
* Exception thrown when a modification to a collection is vetoed.
* It extends IllegalArgumentException for compatibility with the collections API.
*
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/08/31 17:25:49 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/

View File

@ -0,0 +1,203 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedBag.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements 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 Software Foundation.
*
* 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.observed;
import java.util.Set;
import org.apache.commons.collections.Bag;
/**
* Decorates a <code>Bag</code> implementation to observe modifications.
* <p>
* Each modifying method call made on this <code>Bag</code> is forwarded to a
* {@link ModificationHandler}.
* The handler manages the event, notifying listeners and optionally vetoing changes.
* The default handler is {@link StandardModificationHandler}.
* See this class for details of configuration available.
* <p>
* NOTE: The {@link #uniqueSet()} method returns a <code>Set</code> that is
* NOT observed. This is because the set should be unmodifiable.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/
public class ObservedBag extends ObservedCollection implements Bag {
// Factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable bag.
* <p>
* A {@link StandardModificationHandler} will be created.
* This can be accessed by {@link #getHandler()} to add listeners.
*
* @param bag the bag to decorate, must not be null
* @return the observed Bag
* @throws IllegalArgumentException if the bag is null
*/
public static ObservedBag decorate(final Bag bag) {
return new ObservedBag(bag, null);
}
/**
* Factory method to create an observable bag using a listener or a handler.
* <p>
* A lot of functionality is available through this method.
* If you don't need the extra functionality, simply implement the
* {@link org.apache.commons.collections.observed.standard.StandardModificationListener}
* interface and pass it in as the second parameter.
* <p>
* Internally, an <code>ObservedBag</code> relies on a {@link ModificationHandler}.
* The handler receives all the events and processes them, typically by
* calling listeners. Different handler implementations can be plugged in
* to provide a flexible event system.
* <p>
* The handler implementation is determined by the listener parameter via
* the registered factories. The listener may be a manually configured
* <code>ModificationHandler</code> instance.
* <p>
* The listener is defined as an Object for maximum flexibility.
* It does not have to be a listener in the classic JavaBean sense.
* It is entirely up to the factory and handler as to how the parameter
* is interpretted. An IllegalArgumentException is thrown if no suitable
* handler can be found for this listener.
* <p>
* A <code>null</code> listener will create a {@link StandardModificationHandler}.
*
* @param bag the bag to decorate, must not be null
* @param listener bag listener, may be null
* @return the observed bag
* @throws IllegalArgumentException if the bag is null
* @throws IllegalArgumentException if there is no valid handler for the listener
*/
public static ObservedBag decorate(
final Bag bag,
final Object listener) {
if (bag == null) {
throw new IllegalArgumentException("Bag must not be null");
}
return new ObservedBag(bag, listener);
}
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies).
*
* @param bag the bag to decorate, must not be null
* @param listener the listener, may be null
* @throws IllegalArgumentException if the bag is null
*/
protected ObservedBag(
final Bag bag,
final Object listener) {
super(bag, listener);
}
/**
* Typecast the collection to a Bag.
*
* @return the wrapped collection as a Bag
*/
private Bag getBag() {
return (Bag) getCollection();
}
// Bag API
//-----------------------------------------------------------------------
public int getCount(Object object) {
return getBag().getCount(object);
}
public Set uniqueSet() {
return getBag().uniqueSet();
}
//-----------------------------------------------------------------------
public boolean add(Object object) {
// override as Bag violates Collection contract
boolean result = false;
if (handler.preAdd(object)) {
result = collection.add(object);
handler.postAdd(object, true); // true, as result is misleading
}
return result;
}
public boolean add(Object object, int nCopies) {
boolean result = false;
if (handler.preAdd(object, nCopies)) {
result = getBag().add(object, nCopies);
handler.postAdd(object, nCopies, result);
}
return result;
}
public boolean remove(Object object, int nCopies) {
boolean result = false;
if (handler.preRemove(object, nCopies)) {
result = getBag().remove(object, nCopies);
handler.postRemove(object, nCopies, result);
}
return result;
}
}

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/decorators/Attic/ObservedCollection.java,v 1.6 2003/09/03 22:29:51 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedCollection.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,14 +55,14 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.decorators;
package org.apache.commons.collections.observed;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.collections.event.ModificationHandler;
import org.apache.commons.collections.event.ModificationHandlerFactory;
import org.apache.commons.collections.event.StandardModificationHandler;
import org.apache.commons.collections.decorators.AbstractCollectionDecorator;
import org.apache.commons.collections.decorators.AbstractIteratorDecorator;
import org.apache.commons.collections.observed.standard.StandardModificationHandler;
/**
* Decorates a <code>Collection</code> implementation to observe modifications.
@ -74,16 +74,22 @@ import org.apache.commons.collections.event.StandardModificationHandler;
* See this class for details of configuration available.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2003/09/03 22:29:51 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/
public class ObservedCollection extends AbstractCollectionDecorator {
/** The list of registered factories, checked in reverse order */
private static ModificationHandlerFactory[] factories = new ModificationHandlerFactory[] {
ModificationHandler.FACTORY,
StandardModificationHandler.FACTORY
};
/** The handler to delegate event handling to */
protected final ModificationHandler handler;
// Factories
// ObservedCollection factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable collection.
@ -104,7 +110,7 @@ public class ObservedCollection extends AbstractCollectionDecorator {
* <p>
* A lot of functionality is available through this method.
* If you don't need the extra functionality, simply implement the
* {@link org.apache.commons.collections.event.StandardModificationListener}
* {@link org.apache.commons.collections.observed.standard.StandardModificationListener}
* interface and pass it in as the second parameter.
* <p>
* Internally, an <code>ObservedCollection</code> relies on a {@link ModificationHandler}.
@ -112,10 +118,9 @@ public class ObservedCollection extends AbstractCollectionDecorator {
* calling listeners. Different handler implementations can be plugged in
* to provide a flexible event system.
* <p>
* The handler implementation is determined by the listener parameter.
* If the parameter is a <code>ModificationHandler</code> it is used directly.
* Otherwise, the factory mechanism of {@link ModificationHandlerFactory} is used
* to create the handler for the listener parameter.
* The handler implementation is determined by the listener parameter via
* the registered factories. The listener may be a manually configured
* <code>ModificationHandler</code> instance.
* <p>
* The listener is defined as an Object for maximum flexibility.
* It does not have to be a listener in the classic JavaBean sense.
@ -123,9 +128,7 @@ public class ObservedCollection extends AbstractCollectionDecorator {
* is interpretted. An IllegalArgumentException is thrown if no suitable
* handler can be found for this listener.
* <p>
* A <code>null</code> listener will throw an IllegalArgumentException
* unless a special handler factory has been registered.
* <p>
* A <code>null</code> listener will create a {@link StandardModificationHandler}.
*
* @param coll the collection to decorate, must not be null
* @param listener collection listener, may be null
@ -140,11 +143,36 @@ public class ObservedCollection extends AbstractCollectionDecorator {
if (coll == null) {
throw new IllegalArgumentException("Collection must not be null");
}
if (listener instanceof ModificationHandler) {
return new ObservedCollection(coll, (ModificationHandler) listener);
} else {
ModificationHandler handler = ModificationHandlerFactory.createHandler(coll, listener);
return new ObservedCollection(coll, handler);
return new ObservedCollection(coll, listener);
}
// Register for ModificationHandlerFactory
//-----------------------------------------------------------------------
/**
* Registers a handler factory to be used for looking up a listener to
* a handler.
* <p>
* This method is used to add your own event handler to the supplied ones.
* Registering the factory will enable the {@link #decorate(Collection, Object)}
* method to create your handler.
* <p>
* Each handler added becomes the first in the lookup chain. Thus it is
* possible to override the default setup.
* Obviously this should be done with care in a shared web environment!
* <p>
* This method is not guaranteed to be threadsafe.
* It should only be called during initialization.
* Problems will occur if two threads call this method at the same time.
*
* @param factory the factory to add, may be null
*/
public static void registerFactory(final ModificationHandlerFactory factory) {
if (factory != null) {
// add at end, as checked in reverse order
ModificationHandlerFactory[] array = new ModificationHandlerFactory[factories.length + 1];
System.arraycopy(factories, 0, array, 0, factories.length);
array[factories.length] = factory;
factories = array; // atomic operation
}
}
@ -162,10 +190,35 @@ public class ObservedCollection extends AbstractCollectionDecorator {
*/
protected ObservedCollection(
final Collection coll,
final ModificationHandler handler) {
final Object listener) {
super(coll);
this.handler = (handler == null ? new StandardModificationHandler() : handler);
ModificationHandlerFactory.initHandler(this.handler, this);
this.handler = createHandler(coll, listener);
this.handler.init(this);
}
/**
* Creates a handler subclass based on the specified listener.
* <p>
* The method is defined in terms of an Object to allow for unusual
* listeners, such as a Swing model object.
*
* @param listener a listener object to create a handler for
* @return an instantiated handler with the listener attached
* @throws IllegalArgumentException if no suitable handler
*/
protected ModificationHandler createHandler(final Collection coll, final Object listener) {
if (listener == null) {
return new StandardModificationHandler();
}
ModificationHandlerFactory[] array = factories; // atomic operation
for (int i = array.length - 1; i >= 0 ; i--) {
ModificationHandler handler = array[i].createHandler(coll, listener);
if (handler != null) {
return handler;
}
}
throw new IllegalArgumentException("Unrecognised listener type: " +
(listener == null ? "null" : listener.getClass().getName()));
}
// Handler access

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/decorators/Attic/ObservedList.java,v 1.5 2003/09/03 22:29:51 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedList.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,14 +55,13 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.decorators;
package org.apache.commons.collections.observed;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import org.apache.commons.collections.event.ModificationHandler;
import org.apache.commons.collections.event.ModificationHandlerFactory;
import org.apache.commons.collections.decorators.AbstractListIteratorDecorator;
/**
* Decorates a <code>List</code> implementation to observe modifications.
@ -74,7 +73,7 @@ import org.apache.commons.collections.event.ModificationHandlerFactory;
* See this class for details of configuration available.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/09/03 22:29:51 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/
@ -101,7 +100,7 @@ public class ObservedList extends ObservedCollection implements List {
* <p>
* A lot of functionality is available through this method.
* If you don't need the extra functionality, simply implement the
* {@link org.apache.commons.collections.event.StandardModificationListener}
* {@link org.apache.commons.collections.observed.standard.StandardModificationListener}
* interface and pass it in as the second parameter.
* <p>
* Internally, an <code>ObservedList</code> relies on a {@link ModificationHandler}.
@ -109,10 +108,9 @@ public class ObservedList extends ObservedCollection implements List {
* calling listeners. Different handler implementations can be plugged in
* to provide a flexible event system.
* <p>
* The handler implementation is determined by the listener parameter.
* If the parameter is a <code>ModificationHandler</code> it is used directly.
* Otherwise, the factory mechanism of {@link ModificationHandlerFactory} is used
* to create the handler for the listener parameter.
* The handler implementation is determined by the listener parameter via
* the registered factories. The listener may be a manually configured
* <code>ModificationHandler</code> instance.
* <p>
* The listener is defined as an Object for maximum flexibility.
* It does not have to be a listener in the classic JavaBean sense.
@ -120,9 +118,7 @@ public class ObservedList extends ObservedCollection implements List {
* is interpretted. An IllegalArgumentException is thrown if no suitable
* handler can be found for this listener.
* <p>
* A <code>null</code> listener will throw an IllegalArgumentException
* unless a special handler factory has been registered.
* <p>
* A <code>null</code> listener will create a {@link StandardModificationHandler}.
*
* @param list the list to decorate, must not be null
* @param listener list listener, may be null
@ -137,12 +133,7 @@ public class ObservedList extends ObservedCollection implements List {
if (list == null) {
throw new IllegalArgumentException("List must not be null");
}
if (listener instanceof ModificationHandler) {
return new ObservedList(list, (ModificationHandler) listener);
} else {
ModificationHandler handler = ModificationHandlerFactory.createHandler(list, listener);
return new ObservedList(list, handler);
}
return new ObservedList(list, listener);
}
// Constructors
@ -154,13 +145,13 @@ public class ObservedList extends ObservedCollection implements List {
* <code>ObservedHandler</code> is created.
*
* @param list the list to decorate, must not be null
* @param handler the observing handler, may be null
* @param listener the listener, may be null
* @throws IllegalArgumentException if the list is null
*/
protected ObservedList(
final List list,
final ModificationHandler handler) {
super(list, handler);
final Object listener) {
super(list, 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/decorators/Attic/ObservedSet.java,v 1.5 2003/09/03 22:29:50 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedSet.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,12 +55,10 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.decorators;
package org.apache.commons.collections.observed;
import java.util.Set;
import org.apache.commons.collections.event.ModificationHandler;
import org.apache.commons.collections.event.ModificationHandlerFactory;
/**
* Decorates a <code>Set</code> implementation to observe modifications.
@ -72,7 +70,7 @@ import org.apache.commons.collections.event.ModificationHandlerFactory;
* See this class for details of configuration available.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/09/03 22:29:50 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/
@ -99,7 +97,7 @@ public class ObservedSet extends ObservedCollection implements Set {
* <p>
* A lot of functionality is available through this method.
* If you don't need the extra functionality, simply implement the
* {@link org.apache.commons.collections.event.StandardModificationListener}
* {@link org.apache.commons.collections.observed.standard.StandardModificationListener}
* interface and pass it in as the second parameter.
* <p>
* Internally, an <code>ObservedSet</code> relies on a {@link ModificationHandler}.
@ -107,10 +105,9 @@ public class ObservedSet extends ObservedCollection implements Set {
* calling listeners. Different handler implementations can be plugged in
* to provide a flexible event system.
* <p>
* The handler implementation is determined by the listener parameter.
* If the parameter is a <code>ModificationHandler</code> it is used directly.
* Otherwise, the factory mechanism of {@link ModificationHandlerFactory} is used
* to create the handler for the listener parameter.
* The handler implementation is determined by the listener parameter via
* the registered factories. The listener may be a manually configured
* <code>ModificationHandler</code> instance.
* <p>
* The listener is defined as an Object for maximum flexibility.
* It does not have to be a listener in the classic JavaBean sense.
@ -118,9 +115,7 @@ public class ObservedSet extends ObservedCollection implements Set {
* is interpretted. An IllegalArgumentException is thrown if no suitable
* handler can be found for this listener.
* <p>
* A <code>null</code> listener will throw an IllegalArgumentException
* unless a special handler factory has been registered.
* <p>
* A <code>null</code> listener will create a {@link StandardModificationHandler}.
*
* @param set the set to decorate, must not be null
* @param listener set listener, may be null
@ -135,12 +130,7 @@ public class ObservedSet extends ObservedCollection implements Set {
if (set == null) {
throw new IllegalArgumentException("Set must not be null");
}
if (listener instanceof ModificationHandler) {
return new ObservedSet(set, (ModificationHandler) listener);
} else {
ModificationHandler handler = ModificationHandlerFactory.createHandler(set, listener);
return new ObservedSet(set, handler);
}
return new ObservedSet(set, listener);
}
// Constructors
@ -152,13 +142,13 @@ public class ObservedSet extends ObservedCollection implements Set {
* <code>ObservedHandler</code> is created.
*
* @param set the set to decorate, must not be null
* @param handler the observing handler, may be null
* @param listener the listener, may be null
* @throws IllegalArgumentException if the set is null
*/
protected ObservedSet(
final Set set,
final ModificationHandler handler) {
super(set, handler);
final Object listener) {
super(set, listener);
}
}

View File

@ -0,0 +1,14 @@
<BODY>
<p>
This package contains collection decorators that allow you to register to listen
to changes in the underlying collection. A standard listener based event system
is supplied, but alternatives can be added, see ModificationHandler.
<p>
Each decorator can be constructed using a static <code>decorate()</code> method on
the ObservedXxx class. They can also be constructed from the <code>XxxUtils</code>
class (where Xxx is the collection type).
<p>
<code>List observedList = ObservedList.decorate(new ArrayList(), listener);</code>
<br />OR<br />
<code>List observedList = ListUtils.observedList(new ArrayList(), listener);</code>
</BODY>

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/event/Attic/StandardModificationEvent.java,v 1.2 2003/08/31 17:25:49 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardModificationEvent.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,7 +55,7 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed.standard;
import java.util.Collection;
import java.util.Collections;
@ -64,6 +64,9 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.Bag;
import org.apache.commons.collections.observed.ModificationEvent;
import org.apache.commons.collections.observed.ModificationEventType;
import org.apache.commons.collections.observed.ModificationHandler;
/**
* Event class that encapsulates all the event information for a
@ -75,7 +78,7 @@ import org.apache.commons.collections.Bag;
* All objects used are the real objects from the method calls, not clones.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/08/31 17:25:49 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/

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/event/Attic/StandardModificationHandler.java,v 1.5 2003/09/03 00:11:28 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardModificationHandler.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,10 +55,14 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed.standard;
import java.util.Collection;
import org.apache.commons.collections.observed.ModificationEventType;
import org.apache.commons.collections.observed.ModificationHandler;
import org.apache.commons.collections.observed.ModificationHandlerFactory;
/**
* The standard implementation of a <code>ModificationHandler</code> that
* sends standard JavaBean style events to listeners.
@ -72,15 +76,14 @@ import java.util.Collection;
* modification events.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/09/03 00:11:28 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/
public class StandardModificationHandler extends ModificationHandler {
static {
ModificationHandlerFactory.addFactory(new Factory());
}
/** The singleton factory */
public static final ModificationHandlerFactory FACTORY = new Factory();
/** A reusable empty holders array. */
protected static final PreHolder[] EMPTY_PRE_HOLDERS = new PreHolder[0];
@ -537,7 +540,7 @@ public class StandardModificationHandler extends ModificationHandler {
*
* @author Stephen Colebourne
*/
static class Factory extends ModificationHandlerFactory {
static class Factory implements ModificationHandlerFactory {
/**
* Creates a StandardModificationHandler using the listener.
@ -547,7 +550,7 @@ public class StandardModificationHandler extends ModificationHandler {
* @return an instantiated handler with the listener attached,
* or null if the listener type is unsuited to this factory
*/
protected ModificationHandler create(Collection coll, Object listener) {
public ModificationHandler createHandler(Collection coll, Object listener) {
if (listener instanceof StandardPreModificationListener) {
if (listener instanceof StandardPostModificationListener) {
return new StandardModificationHandler(

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/event/Attic/StandardModificationListener.java,v 1.4 2003/08/31 22:44:54 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardModificationListener.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,14 +55,14 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed.standard;
/**
* A listener for the <code>StandardModificationHandler</code> that is called
* both before the collection is changed and after the change has occurred.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/08/31 22:44:54 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/

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/event/Attic/StandardPostModificationListener.java,v 1.1 2003/08/31 22:44:54 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardPostModificationListener.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,14 +55,16 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed.standard;
import org.apache.commons.collections.observed.ModificationListener;
/**
* A listener for the <code>StandardModificationHandler</code> that is called
* when a collection has been changed.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/08/31 22:44:54 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/

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/event/Attic/StandardPreModificationListener.java,v 1.1 2003/08/31 22:44:54 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardPreModificationListener.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,14 +55,16 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.event;
package org.apache.commons.collections.observed.standard;
import org.apache.commons.collections.observed.ModificationListener;
/**
* A listener for the <code>StandardModificationHandler</code> that is called
* when a collection is about to be modified.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/08/31 22:44:54 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
*
* @author Stephen Colebourne
*/

View File

@ -0,0 +1,5 @@
<BODY>
<p>
This package contains a standard implementation of the modification event classes
that are used with ObservedCollection.
</BODY>

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestAll.java,v 1.6 2003/09/03 00:11:28 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestAll.java,v 1.7 2003/09/03 23:54:25 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -65,7 +65,7 @@ import junit.framework.TestSuite;
* Entry point for all collections decorators tests.
*
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2003/09/03 00:11:28 $
* @version $Revision: 1.7 $ $Date: 2003/09/03 23:54:25 $
*
* @author Stephen Colebourne
*/
@ -87,10 +87,6 @@ public class TestAll extends TestCase {
suite.addTest(TestFixedSizeMap.suite());
suite.addTest(TestFixedSizeSortedMap.suite());
suite.addTest(TestObservedCollection.suite());
suite.addTest(TestObservedList.suite());
suite.addTest(TestObservedSet.suite());
suite.addTest(TestSequencedSet.suite());
suite.addTest(TestTransformedBag.suite());

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/ObservedTestHelper.java,v 1.5 2003/09/03 00:11:28 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/ObservedTestHelper.java,v 1.1 2003/09/03 23:54:25 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,7 +55,7 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.decorators;
package org.apache.commons.collections.observed;
import java.util.ArrayList;
import java.util.Iterator;
@ -63,19 +63,19 @@ import java.util.List;
import junit.framework.Assert;
import org.apache.commons.collections.event.ModificationEventType;
import org.apache.commons.collections.event.StandardModificationEvent;
import org.apache.commons.collections.event.StandardModificationHandler;
import org.apache.commons.collections.event.StandardModificationListener;
import org.apache.commons.collections.event.StandardPostModificationListener;
import org.apache.commons.collections.event.StandardPreModificationListener;
import org.apache.commons.collections.observed.ModificationEventType;
import org.apache.commons.collections.observed.standard.StandardModificationEvent;
import org.apache.commons.collections.observed.standard.StandardModificationHandler;
import org.apache.commons.collections.observed.standard.StandardModificationListener;
import org.apache.commons.collections.observed.standard.StandardPostModificationListener;
import org.apache.commons.collections.observed.standard.StandardPreModificationListener;
/**
* Helper for testing
* {@link ObservedCollection} implementations.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/09/03 00:11:28 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:25 $
*
* @author Stephen Colebourne
*/
@ -173,7 +173,16 @@ public class ObservedTestHelper {
doTestAddAllIndexed(factory);
doTestRemoveIndexed(factory);
doTestSetIndexed(factory);
// ITERATOR add/set
// TODO: ITERATOR add/set
}
public static void bulkTestObservedBag(ObservedFactory factory) {
Assert.assertTrue(factory.createObservedCollection() instanceof ObservedBag);
Assert.assertTrue(factory.createObservedCollection(LISTENER) instanceof ObservedBag);
Assert.assertTrue(factory.createObservedCollection(new StandardModificationHandler()) instanceof ObservedBag);
bulkTestObservedCollection(factory);
// TODO: bag nCopies
}
//-----------------------------------------------------------------------
@ -244,10 +253,11 @@ public class ObservedTestHelper {
}
public static void doTestFactoryWithNull(ObservedFactory factory) {
try {
factory.createObservedCollection(null);
Assert.fail();
} catch (IllegalArgumentException ex) {}
ObservedCollection coll = factory.createObservedCollection(null);
Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass());
Assert.assertEquals(0, coll.getHandler().getPreModificationListeners().length);
Assert.assertEquals(0, coll.getHandler().getPostModificationListeners().length);
}
//-----------------------------------------------------------------------

View File

@ -0,0 +1,94 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestAll.java,v 1.1 2003/09/03 23:54:25 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements 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 Software Foundation.
*
* 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.observed;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Entry point for all collections observed tests.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:25 $
*
* @author Stephen Colebourne
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
super(testName);
}
public static void main(String args[]) {
String[] testCaseName = { TestAll.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(TestObservedBag.suite());
suite.addTest(TestObservedCollection.suite());
suite.addTest(TestObservedList.suite());
suite.addTest(TestObservedSet.suite());
return suite;
}
}

View File

@ -0,0 +1,110 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservedBag.java,v 1.1 2003/09/03 23:54:25 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 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 acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements 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 Software Foundation.
*
* 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.observed;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.Bag;
import org.apache.commons.collections.HashBag;
import org.apache.commons.collections.TestBag;
/**
* Extension of {@link TestBag} for exercising the
* {@link ObservedBag} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:25 $
*
* @author Stephen Colebourne
*/
public class TestObservedBag extends TestBag implements ObservedTestHelper.ObservedFactory {
public TestObservedBag(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservedBag.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservedBag.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Bag makeBag() {
return ObservedBag.decorate(new HashBag(), ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedSet() {
ObservedTestHelper.bulkTestObservedBag(this);
}
//-----------------------------------------------------------------------
public ObservedCollection createObservedCollection() {
return ObservedBag.decorate(new HashBag());
}
public ObservedCollection createObservedCollection(Object listener) {
return ObservedBag.decorate(new HashBag(), listener);
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestObservedCollection.java,v 1.4 2003/09/03 00:11:28 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservedCollection.java,v 1.1 2003/09/03 23:54:25 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,7 +55,7 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.decorators;
package org.apache.commons.collections.observed;
import java.util.ArrayList;
import java.util.Arrays;
@ -72,7 +72,7 @@ import org.apache.commons.collections.TestCollection;
* {@link ObservedCollection} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/09/03 00:11:28 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:25 $
*
* @author Stephen Colebourne
*/

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestObservedList.java,v 1.4 2003/09/03 00:11:28 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservedList.java,v 1.1 2003/09/03 23:54:25 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,7 +55,7 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.decorators;
package org.apache.commons.collections.observed;
import java.util.ArrayList;
import java.util.Arrays;
@ -71,7 +71,7 @@ import org.apache.commons.collections.TestList;
* {@link ObservedList} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/09/03 00:11:28 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:25 $
*
* @author Stephen Colebourne
*/

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/decorators/Attic/TestObservedSet.java,v 1.4 2003/09/03 00:11:28 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservedSet.java,v 1.1 2003/09/03 23:54:25 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -55,7 +55,7 @@
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.decorators;
package org.apache.commons.collections.observed;
import java.util.Arrays;
import java.util.HashSet;
@ -71,7 +71,7 @@ import org.apache.commons.collections.TestSet;
* {@link ObservedSet} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/09/03 00:11:28 $
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:25 $
*
* @author Stephen Colebourne
*/