Removed prior to release 3.0, now available in commons-events

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131507 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2004-01-04 18:03:41 +00:00
parent 79c48c8ddf
commit 274b6c5b5b
36 changed files with 19 additions and 6795 deletions

View File

@ -1,10 +1,10 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BagUtils.java,v 1.16 2003/11/27 22:55:16 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.17 2004/01/04 18:03:41 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* Copyright (c) 2002-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -57,26 +57,25 @@
*/
package org.apache.commons.collections;
import org.apache.commons.collections.bag.HashBag;
import org.apache.commons.collections.bag.PredicatedBag;
import org.apache.commons.collections.bag.PredicatedSortedBag;
import org.apache.commons.collections.bag.SynchronizedBag;
import org.apache.commons.collections.bag.SynchronizedSortedBag;
import org.apache.commons.collections.bag.TransformedBag;
import org.apache.commons.collections.bag.TransformedSortedBag;
import org.apache.commons.collections.bag.TreeBag;
import org.apache.commons.collections.bag.TypedBag;
import org.apache.commons.collections.bag.TypedSortedBag;
import org.apache.commons.collections.bag.UnmodifiableBag;
import org.apache.commons.collections.bag.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.16 $ $Date: 2003/11/27 22:55:16 $
* @version $Revision: 1.17 $ $Date: 2004/01/04 18:03:41 $
*
* @author Paul Jack
* @author Stephen Colebourne
@ -190,27 +189,6 @@ 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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @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
@ -301,25 +279,4 @@ public class BagUtils {
return TransformedSortedBag.decorate(bag, transformer);
}
/**
* Returns an observable sorted bag where changes are notified to listeners.
* <p>
* 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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @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);
}
}

View File

@ -1,10 +1,10 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BufferUtils.java,v 1.16 2003/11/27 22:55:16 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.17 2004/01/04 18:03:41 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* Copyright (c) 2002-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -63,14 +63,12 @@ import org.apache.commons.collections.buffer.SynchronizedBuffer;
import org.apache.commons.collections.buffer.TransformedBuffer;
import org.apache.commons.collections.buffer.TypedBuffer;
import org.apache.commons.collections.buffer.UnmodifiableBuffer;
import org.apache.commons.collections.observed.ModificationListener;
import org.apache.commons.collections.observed.ObservableBuffer;
/**
* Provides utility methods and decorators for {@link Buffer} instances.
*
* @since Commons Collections 2.1
* @version $Revision: 1.16 $ $Date: 2003/11/27 22:55:16 $
* @version $Revision: 1.17 $ $Date: 2004/01/04 18:03:41 $
*
* @author Paul Jack
* @author Stephen Colebourne
@ -186,25 +184,4 @@ 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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @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,10 +1,10 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.51 2003/12/11 23:01:02 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.52 2004/01/04 18:03:41 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* Copyright (c) 2001-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -76,14 +76,12 @@ import org.apache.commons.collections.collection.UnmodifiableBoundedCollection;
import org.apache.commons.collections.collection.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;
/**
* Provides utility methods and decorators for {@link Collection} instances.
*
* @since Commons Collections 1.0
* @version $Revision: 1.51 $ $Date: 2003/12/11 23:01:02 $
* @version $Revision: 1.52 $ $Date: 2004/01/04 18:03:41 $
*
* @author Rodney Waldhoff
* @author Paul Jack
@ -730,7 +728,7 @@ public class CollectionUtils {
* @throws IndexOutOfBoundsException
* @throws ArrayIndexOutOfBoundsException
*
* @deprecated use {@link #get(Object, int)} instead
* @deprecated use {@link #get(Object, int)} instead. Will be removed in v4.0
*/
public static Object index(Object obj, int idx) {
return index(obj, new Integer(idx));
@ -757,7 +755,7 @@ public class CollectionUtils {
* @throws IndexOutOfBoundsException
* @throws ArrayIndexOutOfBoundsException
*
* @deprecated use {@link #get(Object, int)} instead
* @deprecated use {@link #get(Object, int)} instead. Will be removed in v4.0
*/
public static Object index(Object obj, Object index) {
if(obj instanceof Map) {
@ -897,36 +895,6 @@ public class CollectionUtils {
throw new IndexOutOfBoundsException("Entry does not exist.");
}
/**
* Returns an Iterator for the given object. Currently this method can handle
* Iterator, Enumeration, Collection, Map, Object[] or array.
*
* @deprecated use IteratorUtils version instead
*/
public static Iterator getIterator(Object obj) {
if(obj instanceof Iterator) {
return (Iterator)obj;
}
else if(obj instanceof Collection) {
return ((Collection)obj).iterator();
}
else if(obj instanceof Object[]) {
return new ArrayIterator( obj );
}
else if(obj instanceof Enumeration) {
return new EnumerationIterator( (Enumeration)obj );
}
else if(obj instanceof Map) {
return ((Map)obj).values().iterator();
}
else if(obj != null && obj.getClass().isArray()) {
return new ArrayIterator( obj );
}
else{
return null;
}
}
/**
* Reverses the order of the given array.
*
@ -1103,25 +1071,4 @@ 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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @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,10 +1,10 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/ListUtils.java,v 1.23 2003/11/27 22:55:16 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.24 2004/01/04 18:03:41 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* Copyright (c) 2001-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -70,14 +70,12 @@ import org.apache.commons.collections.list.SynchronizedList;
import org.apache.commons.collections.list.TransformedList;
import org.apache.commons.collections.list.TypedList;
import org.apache.commons.collections.list.UnmodifiableList;
import org.apache.commons.collections.observed.ModificationListener;
import org.apache.commons.collections.observed.ObservableList;
/**
* Provides utility methods and decorators for {@link List} instances.
*
* @since Commons Collections 1.0
* @version $Revision: 1.23 $ $Date: 2003/11/27 22:55:16 $
* @version $Revision: 1.24 $ $Date: 2004/01/04 18:03:41 $
*
* @author Federico Barbieri
* @author Peter Donald
@ -346,27 +344,6 @@ public class ListUtils {
return TransformedList.decorate(list, transformer);
}
/**
* 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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @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>

View File

@ -1,10 +1,10 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SetUtils.java,v 1.21 2003/12/03 11:37:44 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.22 2004/01/04 18:03:41 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* Copyright (c) 2002-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -64,9 +64,6 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.commons.collections.observed.ModificationListener;
import org.apache.commons.collections.observed.ObservableSet;
import org.apache.commons.collections.observed.ObservableSortedSet;
import org.apache.commons.collections.set.ListOrderedSet;
import org.apache.commons.collections.set.PredicatedSet;
import org.apache.commons.collections.set.PredicatedSortedSet;
@ -84,7 +81,7 @@ import org.apache.commons.collections.set.UnmodifiableSortedSet;
* {@link Set} and {@link SortedSet} instances.
*
* @since Commons Collections 2.1
* @version $Revision: 1.21 $ $Date: 2003/12/03 11:37:44 $
* @version $Revision: 1.22 $ $Date: 2004/01/04 18:03:41 $
*
* @author Paul Jack
* @author Stephen Colebourne
@ -264,27 +261,6 @@ 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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @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
* backed by the given set.
@ -385,25 +361,4 @@ public class SetUtils {
return TransformedSortedSet.decorate(set, transformer);
}
/**
* Returns an observable sorted 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
* ObservableSortedSet class should be accessed directly.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @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);
}
}

View File

@ -1,171 +0,0 @@
/*
* $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.4 2003/11/27 22:55:15 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;
import java.util.EventObject;
/**
* Base event class extended by each class that encapsulates event information.
* <p>
* This class can be used as is, but generally it is subclassed.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ModificationEvent extends EventObject {
/** The source collection */
protected final ObservableCollection collection;
/** The handler */
protected final ModificationHandler handler;
/** The event code */
protected final int type;
// Constructor
//-----------------------------------------------------------------------
/**
* Constructor.
*
* @param obsCollection the event source
* @param handler the handler
* @param type the event type
*/
public ModificationEvent(
final ObservableCollection obsCollection,
final ModificationHandler handler,
final int type) {
super(obsCollection);
this.collection = obsCollection;
this.handler = handler;
this.type = type;
}
// Basic info
//-----------------------------------------------------------------------
/**
* Gets the collection the event is reporting on.
* <p>
* Using this collection will bypass any decorators that have been added
* to the <code>ObservableCollection</code>. For example, if a synchronized
* decorator was added it will not be called by changes to this collection.
* <p>
* For the synchronization case, you are normally OK however. If you
* process the event in the same thread as the original change then your
* code will be protected by the original synchronized decorator and this
* collection may be used freely.
*
* @return the collection
*/
public ObservableCollection getObservedCollection() {
return collection;
}
/**
* Gets the base collection underlying the observable collection.
* <p>
* Using this collection will bypass the event sending mechanism.
* It will also bypass any other decorators, such as synchronization.
* Use with care.
*
* @return the collection
*/
public Collection getBaseCollection() {
return handler.getBaseCollection();
}
/**
* Gets the handler of the events.
*
* @return the handler
*/
public ModificationHandler getHandler() {
return handler;
}
/**
* Gets the event type constant.
* <p>
* This is one of the <i>method</i> constants from {@link ModificationEventType}.
*
* @return the method event type constant
*/
public int getType() {
return type;
}
// toString
//-----------------------------------------------------------------------
/**
* Gets a debugging string version of the event.
*
* @return a debugging string
*/
public String toString() {
StringBuffer buf = new StringBuffer(64);
buf.append("ModificationEvent[type=");
buf.append(ModificationEventType.toString(type));
buf.append(']');
return buf.toString();
}
}

View File

@ -1,215 +0,0 @@
/*
* $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.4 2003/11/27 22:55:15 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;
/**
* Defines event constants for event handling and matching.
* <p>
* The constants in this class are of two types:
* <ol>
* <li>Methods - the base definitions (unique bits)
* <li>Groups - combination definitions (method bits combined)
* </ol>
* <p>
* Only a method constant may be compared using == to an event type.
* This can include use in a switch statement
* <p>
* Any constant may be used for filtering.
* They may combined using the bitwise OR, <code>|</code>.
* They may negated using the bitwise NOT, <code>~</code>.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ModificationEventType {
/** The method add(Object) */
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 iterator.add(Object) */
public static final int ADD_ITERATED = 0x00000008;
/** The method addAll(Collection) */
public static final int ADD_ALL = 0x00000010;
/** The method addAll(int,Collection) */
public static final int ADD_ALL_INDEXED=0x00000020;
/** The method remove(Object) */
public static final int REMOVE = 0x00000100;
/** The method remove(int) */
public static final int REMOVE_INDEXED =0x00000200;
/** The method remove(Object,int) */
public static final int REMOVE_NCOPIES =0x00000400;
/** The method remove() */
public static final int REMOVE_NEXT =0x00000800;
/** The method iterator.remove() */
public static final int REMOVE_ITERATED=0x00001000;
/** The method removeAll(Collection) */
public static final int REMOVE_ALL = 0x00002000;
/** The method retainAll(Collection) */
public static final int RETAIN_ALL = 0x00004000;
/** The method clear() */
public static final int CLEAR = 0x00008000;
/** The method set(int,Object) */
public static final int SET_INDEXED = 0x00010000;
/** The method iterator.set(Object) */
public static final int SET_ITERATED = 0x00020000;
/** All add methods */
public static final int GROUP_ADD = ADD | ADD_INDEXED | ADD_NCOPIES | ADD_ITERATED | ADD_ALL | ADD_ALL_INDEXED;
/** All methods that change without structure modification */
public static final int GROUP_CHANGE = SET_INDEXED | SET_ITERATED;
/** All remove methods */
public static final int GROUP_REMOVE = REMOVE | REMOVE_INDEXED | REMOVE_NCOPIES | REMOVE_ITERATED | REMOVE_NEXT | REMOVE_ALL;
/** All retain methods */
public static final int GROUP_RETAIN = RETAIN_ALL;
/** All clear methods */
public static final int GROUP_CLEAR = CLEAR;
/** All reducing methods (remove, retain and clear) */
public static final int GROUP_REDUCE = GROUP_REMOVE | GROUP_CLEAR | GROUP_RETAIN;
/** All indexed methods */
public static final int GROUP_INDEXED = ADD_INDEXED | ADD_ALL_INDEXED | REMOVE_INDEXED | SET_INDEXED;
/** All ncopies methods */
public static final int GROUP_NCOPIES = ADD_NCOPIES | REMOVE_NCOPIES;
/** All iterated methods */
public static final int GROUP_ITERATED = ADD_ITERATED | REMOVE_ITERATED | SET_ITERATED;
/** All 'next' methods */
public static final int GROUP_NEXT = REMOVE_NEXT;
/** All bulk methods (xxxAll, clear) */
public static final int GROUP_BULK = ADD_ALL | ADD_ALL_INDEXED | REMOVE_ALL | RETAIN_ALL | CLEAR;
/** All methods that modify the structure */
public static final int GROUP_STRUCTURE_MODIFIED = GROUP_ADD | GROUP_REDUCE;
/** All methods sent by a Collection */
public static final int GROUP_FROM_COLLECTION = ADD | ADD_ALL | REMOVE | REMOVE_ALL | RETAIN_ALL | CLEAR;
/** All methods sent by a Set */
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 Bag */
public static final int GROUP_FROM_BAG = GROUP_FROM_COLLECTION | ADD_NCOPIES | REMOVE_NCOPIES;
/** All methods sent by a Buffer */
public static final int GROUP_FROM_BUFFER = GROUP_FROM_COLLECTION | REMOVE_NEXT;
/** No methods */
public static final int GROUP_NONE = 0x00000000;
/** All methods */
public static final int GROUP_ALL = 0xFFFFFFFF;
/**
* Constructor.
*/
protected ModificationEventType() {
super();
}
/**
* Gets a string version of a method event type.
*
* @param methodType the method event type constant
* @return a string description
*/
public static String toString(final int methodType) {
switch (methodType) {
case ADD:
return "Add";
case ADD_INDEXED:
return "AddIndexed";
case ADD_NCOPIES:
return "AddNCopies";
case ADD_ITERATED:
return "AddIterated";
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_ITERATED:
return "RemoveIterated";
case REMOVE_NEXT:
return "RemoveNext";
case REMOVE_ALL:
return "RemoveAll";
case RETAIN_ALL:
return "RetainAll";
case CLEAR:
return "Clear";
case SET_INDEXED:
return "SetIndexed";
case SET_ITERATED:
return "SetIterated";
default:
return "Unknown";
}
}
}

View File

@ -1,905 +0,0 @@
/*
* $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.9 2003/11/27 22:55:15 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 handler for collection modification events.
* <p>
* This class defines the event handling methods, following the
* <code>preXxx</code> and <code>postXxx</code> naming convention.
* It also provides a default implementation that forwards to single methods.
* <p>
* To write your own handler, you will normally subclass and override the
* <code>preEvent</code> and <code>postEvent</code> methods. However, you
* could choose to override any individual event method.
* <p>
* This class could have been implemented as an interface, however to do so
* 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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.9 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ModificationHandler {
/** Singleton factory */
static final ModificationHandlerFactory FACTORY = new Factory();
/** The collection being observed */
private ObservableCollection obsCollection = null;
/** The underlying base collection being decorated */
private Collection baseCollection = null;
/** The root handler */
private final ModificationHandler rootHandler;
/** The view offset, 0 if not a view */
private final int viewOffset;
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor.
*/
protected ModificationHandler() {
super();
this.rootHandler = this;
this.viewOffset = 0;
}
/**
* Constructor.
*
* @param rootHandler the base underlying handler
* @param viewOffset the offset on the base collection
*/
protected ModificationHandler(ModificationHandler rootHandler, int viewOffset) {
super();
this.rootHandler = rootHandler;
this.viewOffset = viewOffset;
}
/**
* Initialize the handler.
* <p>
* The handler cannot be used until this method is called.
* However, the handler's setup methods can be called.
* All other methods will throw NullPointerException until then.
*
* @param coll the observed collection, must not be null
* @param baseColl the base collection, must not be null
* @throws IllegalArgumentException if the collection is null
* @throws IllegalStateException if init has already been called
*/
void init(final ObservableCollection coll, Collection baseColl) {
if (coll == null) {
throw new IllegalArgumentException("Collection must not be null");
}
if (baseColl == null) {
throw new IllegalArgumentException("Base Collection must not be null");
}
if (this.obsCollection != null) {
throw new IllegalArgumentException("init() has already been called");
}
this.obsCollection = coll;
this.baseCollection = baseColl;
}
// Field access
//-----------------------------------------------------------------------
/**
* Gets the observed collection.
*
* @return the observed collection
*/
public ObservableCollection getObservedCollection() {
return obsCollection;
}
/**
* Gets the base collection.
*
* @return the base collection
*/
protected Collection getBaseCollection() {
return baseCollection;
}
/**
* Gets the root handler.
*
* @return the root handler
*/
protected ModificationHandler getRootHandler() {
return rootHandler;
}
/**
* Gets the view offset.
*
* @return the view offset
*/
protected int getViewOffset() {
return viewOffset;
}
// PreListeners
//----------------------------------------------------------------------
/**
* Gets an array of all the pre listeners active in the handler.
* <p>
* This implementation throws UnsupportedOperationException.
*
* @return the listeners
* @throws UnsupportedOperationException if the handler does not support listeners
*/
public Object[] getPreModificationListeners() {
throw new UnsupportedOperationException("Listeners not supported by " + getClass().getName());
}
/**
* Adds a pre listener to the list held in the handler.
* <p>
* No error occurs if the listener is <code>null</code>.
* <p>
* The listener does not necessarily have to be a listener in the classic
* JavaBean sense. It is entirely up to the handler as to how it interprets
* the listener parameter. A ClassCastException is thrown if the handler
* cannot interpret the parameter.
* <p>
* This implementation throws UnsupportedOperationException.
*
* @param listener the listener to add, may be null (ignored)
* @throws ClassCastException if the listener is not of the correct type
* @throws UnsupportedOperationException if the handler does not support listeners
*/
public void addPreModificationListener(Object listener) {
throw new UnsupportedOperationException("Listeners not supported by " + getClass().getName());
}
/**
* Removes a pre listener to the list held in the handler.
* <p>
* No error occurs if the listener is not in the list or the type
* of the listener is incorrect.
* <p>
* This implementation throws UnsupportedOperationException.
*
* @param listener the listener to remove, may be null (ignored)
* @throws UnsupportedOperationException if the handler does not support listeners
*/
public void removePreModificationListener(Object listener) {
throw new UnsupportedOperationException("Listeners not supported by " + getClass().getName());
}
// PostListeners
//----------------------------------------------------------------------
/**
* Gets an array of all the post listeners active in the handler.
* <p>
* This implementation throws UnsupportedOperationException.
*
* @return the listeners
* @throws UnsupportedOperationException if the handler does not support listeners
*/
public Object[] getPostModificationListeners() {
throw new UnsupportedOperationException("Listeners not supported by " + getClass().getName());
}
/**
* Adds a post listener to the list held in the handler.
* <p>
* No error occurs if the listener is <code>null</code>.
* <p>
* The listener does not necessarily have to be a listener in the classic
* JavaBean sense. It is entirely up to the handler as to how it interprets
* the listener parameter. A ClassCastException is thrown if the handler
* cannot interpret the parameter.
* <p>
* This implementation throws UnsupportedOperationException.
*
* @param listener the listener to add, may be null (ignored)
* @throws ClassCastException if the listener is not of the correct type
* @throws UnsupportedOperationException if the handler does not support listeners
*/
public void addPostModificationListener(Object listener) {
throw new UnsupportedOperationException("Listeners not supported by " + getClass().getName());
}
/**
* Removes a post listener to the list held in the handler.
* <p>
* No error occurs if the listener is not in the list or the type
* of the listener is incorrect.
* <p>
* This implementation throws UnsupportedOperationException.
*
* @param listener the listener to remove, may be null (ignored)
* @throws UnsupportedOperationException if the handler does not support listeners
*/
public void removePostModificationListener(Object listener) {
throw new UnsupportedOperationException("Listeners not supported by " + getClass().getName());
}
// Event sending
//-----------------------------------------------------------------------
/**
* Handles the pre event.
* <p>
* This implementation does nothing.
*
* @param type the event type to send
* @param index the index where the change starts, the method param or derived
* @param object the object that will be added/removed/set, the method param or derived
* @param repeat the number of repeats of the add/remove, the method param or derived
* @param previous the previous value that will be removed/replaced, must exist in coll
* @param view the view collection that the change was actioned on, null if no view
* @param viewOffset the offset of the subList view, -1 if unknown
*/
protected boolean preEvent(
int type, int index, Object object, int repeat,
Object previous, ObservableCollection view, int viewOffset) {
return true;
}
/**
* Handles the post event.
* <p>
* This implementation does nothing.
*
* @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, the method param or derived
* @param object the object that was added/removed/set, the method param or derived
* @param repeat the number of repeats of the add/remove, the method param or derived
* @param previous the previous value that was removed/replace, must have existed in coll
* @param view the view collection that the change was actioned on, null if no view
* @param viewOffset the offset of the subList view, -1 if unknown
*/
protected void postEvent(
boolean modified, int type, int index, Object object, int repeat,
Object previous, ObservableCollection view, int viewOffset) {
}
// Event handling
//-----------------------------------------------------------------------
/**
* Store data and send event before add(obj) is called.
* <p>
* This implementation forwards to {@link #preEvent}.
* It does not set the index for List implementations.
*
* @param object the object being added
* @return true to process modification
*/
protected boolean preAdd(Object object) {
return preEvent(ModificationEventType.ADD, -1, object, 1, null, null, -1);
}
/**
* Send an event after add(obj) is called.
* <p>
* This implementation forwards to {@link #postEvent}.
* It does not set the index for List implementations.
*
* @param object the object being added
* @param result the result from the add method
*/
protected void postAdd(Object object, boolean result) {
postEvent(result, ModificationEventType.ADD, -1, object, 1, null, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before add(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param index the index to add at
* @param object the object being added
* @return true to process modification
*/
protected boolean preAddIndexed(int index, Object object) {
return preEvent(ModificationEventType.ADD_INDEXED, index + viewOffset, object, 1, null, null, -1);
}
/**
* Send an event after add(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param index the index to add at
* @param object the object being added
*/
protected void postAddIndexed(int index, Object object) {
postEvent(true, ModificationEventType.ADD_INDEXED, index + viewOffset, object, 1, null, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before add(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param object the object being added
* @param nCopies the number of copies being added
* @return true to process modification
*/
protected boolean preAddNCopies(Object object, int nCopies) {
return preEvent(ModificationEventType.ADD_NCOPIES, -1, object, nCopies, null, null, -1);
}
/**
* Send an event after add(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #postEvent}.
* The method result is not used by this implementation (Bag violates the
* Collection contract)
*
* @param object the object being added
* @param nCopies the number of copies being added
* @param result the method result
*/
protected void postAddNCopies(Object object, int nCopies, boolean result) {
postEvent(true, ModificationEventType.ADD_NCOPIES, -1, object, nCopies, null, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before add(obj) is called on a ListIterator.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param index the index of the iterator
* @param object the object being added
* @return true to process modification
*/
protected boolean preAddIterated(int index, Object object) {
return preEvent(ModificationEventType.ADD_ITERATED, index + viewOffset, object, 1, null, null, -1);
}
/**
* Send an event after add(obj) is called on a ListIterator.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param index the index of the iterator
* @param object the object being added
*/
protected void postAddIterated(int index, Object object) {
// assume collection changed
postEvent(true, ModificationEventType.ADD_ITERATED, index + viewOffset, object, 1, null, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before addAll(coll) is called.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param coll the collection being added
* @return true to process modification
*/
protected boolean preAddAll(Collection coll) {
return preEvent(ModificationEventType.ADD_ALL, -1, coll, 1, null, null, -1);
}
/**
* Send an event after addAll(coll) is called.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param coll the collection being added
* @param collChanged the result from the addAll method
*/
protected void postAddAll(Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.ADD_ALL, -1, coll, 1, null, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before addAll(int,coll) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param index the index to addAll at
* @param coll the collection being added
* @return true to process modification
*/
protected boolean preAddAllIndexed(int index, Collection coll) {
return preEvent(ModificationEventType.ADD_ALL_INDEXED, index + viewOffset, coll, 1, null, null, -1);
}
/**
* Send an event after addAll(int,coll) is called on a List.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param index the index to addAll at
* @param coll the collection being added
* @param collChanged the result from the addAll method
*/
protected void postAddAllIndexed(int index, Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.ADD_ALL_INDEXED, index + viewOffset, coll, 1, null, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before clear() is called.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @return true to process modification
*/
protected boolean preClear() {
return preEvent(ModificationEventType.CLEAR, -1, null, 1, null, null, -1);
}
/**
* Send an event after clear() is called.
* <p>
* This implementation forwards to {@link #postEvent}.
*/
protected void postClear() {
// assumes a modification occurred
postEvent(true, ModificationEventType.CLEAR, -1, null, 1, null, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove(obj) is called.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param object the object being removed
* @return true to process modification
*/
protected boolean preRemove(Object object) {
return preEvent(ModificationEventType.REMOVE, -1, object, 1, null, null, -1);
}
/**
* Send an event after remove(obj) is called.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param object the object being removed
* @param collChanged the result from the remove method
*/
protected void postRemove(Object object, boolean collChanged) {
postEvent(collChanged, ModificationEventType.REMOVE, -1, object, 1, (collChanged ? object : null), null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove(int) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param index the index to remove at
* @return true to process modification
*/
protected boolean preRemoveIndexed(int index) {
// could do a get(index) to determine previousValue
// we don't for performance, but subclass may override
return preEvent(ModificationEventType.REMOVE_INDEXED, index + viewOffset, null, 1, null, null, -1);
}
/**
* Send an event after remove(int) is called on a List.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param index the index to remove at
* @param previousValue the result from the remove method
*/
protected void postRemoveIndexed(int index, Object previousValue) {
postEvent(true, ModificationEventType.REMOVE_INDEXED, index + viewOffset, null, 1, previousValue, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param object the object being removed
* @param nCopies the number of copies being removed
* @return true to process modification
*/
protected boolean preRemoveNCopies(Object object, int nCopies) {
return preEvent(ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies, null, null, -1);
}
/**
* Send an event after remove(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param object the object being removed
* @param nCopies the number of copies being removed
* @param collChanged the result from the remove method
*/
protected void postRemoveNCopies(Object object, int nCopies, boolean collChanged) {
postEvent(collChanged, ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies, (collChanged ? object : null), null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove() is called on a Buffer.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @return true to process modification
*/
protected boolean preRemoveNext() {
return preEvent(ModificationEventType.REMOVE_NEXT, -1, null, 1, null, null, -1);
}
/**
* Send an event after remove() is called on a Buffer.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param removedValue the previous value at this index
*/
protected void postRemoveNext(Object removedValue) {
// assume collection changed
postEvent(true, ModificationEventType.REMOVE_NEXT, -1, removedValue, 1, removedValue, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove(obj) is called on an Iterator.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param index the index of the iterator
* @param removedValue the object being removed
* @return true to process modification
*/
protected boolean preRemoveIterated(int index, Object removedValue) {
return preEvent(ModificationEventType.REMOVE_ITERATED, index + viewOffset, removedValue, 1, removedValue, null, -1);
}
/**
* Send an event after remove(obj) is called on an Iterator.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param index the index of the iterator
* @param removedValue the previous value at this index
*/
protected void postRemoveIterated(int index, Object removedValue) {
// assume collection changed
postEvent(true, ModificationEventType.REMOVE_ITERATED, index + viewOffset, removedValue, 1, removedValue, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before removeAll(coll) is called.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param coll the collection being removed
* @return true to process modification
*/
protected boolean preRemoveAll(Collection coll) {
return preEvent(ModificationEventType.REMOVE_ALL, -1, coll, 1, null, null, -1);
}
/**
* Send an event after removeAll(coll) is called.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param coll the collection being removed
* @param collChanged the result from the removeAll method
*/
protected void postRemoveAll(Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.REMOVE_ALL, -1, coll, 1, null, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before retainAll(coll) is called.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param coll the collection being retained
* @return true to process modification
*/
protected boolean preRetainAll(Collection coll) {
return preEvent(ModificationEventType.RETAIN_ALL, -1, coll, 1, null, null, -1);
}
/**
* Send an event after retainAll(coll) is called.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param coll the collection being retained
* @param collChanged the result from the retainAll method
*/
protected void postRetainAll(Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.RETAIN_ALL, -1, coll, 1, null, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before set(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param index the index to add at
* @param object the object being added
* @return true to process modification
*/
protected boolean preSetIndexed(int index, Object object) {
// could do a get(index) to determine previousValue
// we don't for performance, but subclass may override
return preEvent(ModificationEventType.SET_INDEXED, index + viewOffset, object, 1, null, null, -1);
}
/**
* Send an event after set(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param index the index to add at
* @param object the object being added
* @param previousValue the result from the set method
*/
protected void postSetIndexed(int index, Object object, Object previousValue) {
// reference check for modification, in case equals() has issues (eg. performance)
postEvent((object != previousValue), ModificationEventType.SET_INDEXED, index + viewOffset, object, 1, previousValue, null, -1);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before set(obj) is called on a ListIterator.
* <p>
* This implementation forwards to {@link #preEvent}.
*
* @param index the index to set at
* @param object the object being added
* @param previousValue the previous value at this index
* @return true to process modification
*/
protected boolean preSetIterated(int index, Object object, Object previousValue) {
return preEvent(ModificationEventType.SET_ITERATED, index + viewOffset, object, 1, previousValue, null, -1);
}
/**
* Send an event after set(obj) is called on a ListIterator.
* <p>
* This implementation forwards to {@link #postEvent}.
*
* @param index the index to set at
* @param object the object being added
* @param previousValue the previous value at this index
*/
protected void postSetIterated(int index, Object object, Object previousValue) {
// reference check for modification, in case equals() has issues (eg. performance)
postEvent((object != previousValue), ModificationEventType.SET_ITERATED, index + viewOffset, object, 1, previousValue, null, -1);
}
// SortedSet Views
//-----------------------------------------------------------------------
/**
* Creates a new handler for SortedSet subSet.
*
* @param fromElement the from element
* @param toElement the to element
*/
protected ModificationHandler createSubSetHandler(Object fromElement, Object toElement) {
return new SetViewHandler(rootHandler);
}
/**
* Creates a new handler for SortedSet headSet.
*
* @param toElement the to element
*/
protected ModificationHandler createHeadSetHandler(Object toElement) {
return new SetViewHandler(rootHandler);
}
/**
* Creates a new handler for SortedSet tailSet.
*
* @param fromElement the from element
*/
protected ModificationHandler createTailSetHandler(Object fromElement) {
return new SetViewHandler(rootHandler);
}
/**
* Inner class for views.
*/
protected static class SetViewHandler extends ModificationHandler {
/**
* Constructor.
*
* @param rootHandler the base underlying handler
*/
protected SetViewHandler(ModificationHandler rootHandler) {
super(rootHandler, 0);
}
/**
* Override the preEvent method to forward all events to the
* underlying handler. This method also inserts details of the view
* that caused the event.
*/
protected boolean preEvent(
int type, int index, Object object, int repeat,
Object previous, ObservableCollection ignoredView, int offset) {
return getRootHandler().preEvent(
type, index, object, repeat,
previous, getObservedCollection(), offset);
}
/**
* Override the postEvent method to forward all events to the
* underlying handler. This method also inserts details of the view
* that caused the event.
*/
protected void postEvent(
boolean modified, int type, int index, Object object, int repeat,
Object previous, ObservableCollection ignoredView, int offset) {
getRootHandler().postEvent(
modified, type, index, object, repeat,
previous, getObservedCollection(), offset);
}
}
// List View
//-----------------------------------------------------------------------
/**
* Creates a new handler for subLists that is aware of the offset.
*
* @param fromIndex the sublist fromIndex (inclusive)
* @param toIndex the sublist toIndex (exclusive)
*/
protected ModificationHandler createSubListHandler(int fromIndex, int toIndex) {
return new SubListHandler(rootHandler, fromIndex + viewOffset);
}
/**
* Inner class for subLists.
*/
protected static class SubListHandler extends ModificationHandler {
/**
* Constructor.
*
* @param rootHandler the base underlying handler
* @param viewOffset the offset on the base collection
*/
protected SubListHandler(ModificationHandler rootHandler, int viewOffset) {
super(rootHandler, viewOffset);
}
/**
* Override the preEvent method to forward all events to the
* underlying handler. This method also inserts details of the view
* that caused the event.
*/
protected boolean preEvent(
int type, int index, Object object, int repeat,
Object previous, ObservableCollection ignoredView, int ignoredOffset) {
return getRootHandler().preEvent(
type, index, object, repeat,
previous, getObservedCollection(), getViewOffset());
}
/**
* Override the postEvent method to forward all events to the
* underlying handler. This method also inserts details of the view
* that caused the event.
*/
protected void postEvent(
boolean modified, int type, int index, Object object, int repeat,
Object previous, ObservableCollection ignoredView, int ignoredOffset) {
getRootHandler().postEvent(
modified, type, index, object, repeat,
previous, getObservedCollection(), getViewOffset());
}
}
// toString
//-----------------------------------------------------------------------
/**
* Gets a debugging string version of this object.
*
* @return a debugging string
*/
public String toString() {
String name = getClass().getName();
int pos = name.lastIndexOf('.');
if (pos != -1) {
name = name.substring(pos + 1);
}
return name + '[' + (obsCollection == 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

@ -1,101 +0,0 @@
/*
* $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.3 2003/11/27 22:55:15 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 ObservableCollection
* </ol>
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/11/27 22:55:15 $
*
* @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,78 +0,0 @@
/*
* $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.2 2003/11/27 22:55:15 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.EventListener;
/**
* An empty listener designed to be subclassed.
* <p>
* This interface exists to mark independent subclasses as fulfilling the
* role of an event listener for collection modification events.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public interface ModificationListener extends EventListener {
// no methods - subinterfaces define them
}

View File

@ -1,99 +0,0 @@
/*
* $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.2 2003/11/27 22:55:15 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;
/**
* Exception thrown when a modification to a collection is vetoed.
* It extends IllegalArgumentException for compatibility with the collections API.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ModificationVetoedException extends IllegalArgumentException {
/** The source event */
protected final ModificationEvent event;
// Constructor
//-----------------------------------------------------------------------
/**
* Constructor.
*
* @param message the text message, may be null
* @param event the observed event, should not be null
*/
public ModificationVetoedException(final String message, final ModificationEvent event) {
super((message == null ? "Modification vetoed" : message));
this.event = event;
}
// Event access
//-----------------------------------------------------------------------
/**
* Gets the event that caused the veto.
*
* @return the event
*/
public ModificationEvent getEvent() {
return event;
}
}

View File

@ -1,210 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservableBag.java,v 1.4 2003/11/27 22:55:15 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 org.apache.commons.collections.observed.standard.StandardModificationHandler 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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ObservableBag extends ObservableCollection implements Bag {
// Factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable bag.
* <p>
* A {@link org.apache.commons.collections.observed.standard.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 ObservableBag decorate(final Bag bag) {
return new ObservableBag(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>ObservableBag</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 org.apache.commons.collections.observed.standard.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 ObservableBag decorate(
final Bag bag,
final Object listener) {
if (bag == null) {
throw new IllegalArgumentException("Bag must not be null");
}
return new ObservableBag(bag, listener);
}
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies).
* <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.
*
* @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 ObservableBag(
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.preAddNCopies(object, nCopies)) {
result = getBag().add(object, nCopies);
handler.postAddNCopies(object, nCopies, result);
}
return result;
}
public boolean remove(Object object, int nCopies) {
boolean result = false;
if (handler.preRemoveNCopies(object, nCopies)) {
result = getBag().remove(object, nCopies);
handler.postRemoveNCopies(object, nCopies, result);
}
return result;
}
}

View File

@ -1,182 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservableBuffer.java,v 1.4 2003/11/27 22:55:15 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 org.apache.commons.collections.Buffer;
/**
* Decorates a <code>Buffer</code> implementation to observe modifications.
* <p>
* Each modifying method call made on this <code>Buffer</code> is forwarded to a
* {@link ModificationHandler}.
* The handler manages the event, notifying listeners and optionally vetoing changes.
* The default handler is
* {@link org.apache.commons.collections.observed.standard.StandardModificationHandler StandardModificationHandler}.
* See this class for details of configuration available.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ObservableBuffer extends ObservableCollection implements Buffer {
// Factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable buffer.
* <p>
* A {@link org.apache.commons.collections.observed.standard.StandardModificationHandler} will be created.
* This can be accessed by {@link #getHandler()} to add listeners.
*
* @param buffer the buffer to decorate, must not be null
* @return the observed Buffer
* @throws IllegalArgumentException if the buffer is null
*/
public static ObservableBuffer decorate(final Buffer buffer) {
return new ObservableBuffer(buffer, null);
}
/**
* Factory method to create an observable buffer 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>ObservableBuffer</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 org.apache.commons.collections.observed.standard.StandardModificationHandler}.
*
* @param buffer the buffer to decorate, must not be null
* @param listener buffer listener, may be null
* @return the observed buffer
* @throws IllegalArgumentException if the buffer is null
* @throws IllegalArgumentException if there is no valid handler for the listener
*/
public static ObservableBuffer decorate(
final Buffer buffer,
final Object listener) {
if (buffer == null) {
throw new IllegalArgumentException("Buffer must not be null");
}
return new ObservableBuffer(buffer, listener);
}
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies).
* <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.
*
* @param buffer the buffer to decorate, must not be null
* @param listener the listener, may be null
* @throws IllegalArgumentException if the buffer is null
*/
protected ObservableBuffer(
final Buffer buffer,
final Object listener) {
super(buffer, listener);
}
/**
* Typecast the collection to a Buffer.
*
* @return the wrapped collection as a Buffer
*/
private Buffer getBuffer() {
return (Buffer) getCollection();
}
// Buffer API
//-----------------------------------------------------------------------
public Object get() {
return getBuffer().get();
}
//-----------------------------------------------------------------------
public Object remove() {
Object result = null;
if (handler.preRemoveNext()) {
result = getBuffer().remove();
handler.postRemoveNext(result);
}
return result;
}
}

View File

@ -1,338 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservableCollection.java,v 1.4 2003/11/27 22:55:15 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;
import java.util.Iterator;
import org.apache.commons.collections.collection.AbstractCollectionDecorator;
import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
import org.apache.commons.collections.observed.standard.StandardModificationHandler;
/**
* Decorates a <code>Collection</code> implementation to observe modifications.
* <p>
* Each modifying method call made on this <code>Collection</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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ObservableCollection 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;
// ObservableCollection factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable collection.
* <p>
* A {@link StandardModificationHandler} will be created.
* This can be accessed by {@link #getHandler()} to add listeners.
*
* @param coll the collection to decorate, must not be null
* @return the observed collection
* @throws IllegalArgumentException if the collection is null
*/
public static ObservableCollection decorate(final Collection coll) {
return new ObservableCollection(coll, null);
}
/**
* Factory method to create an observable collection 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>ObservableCollection</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 coll the collection to decorate, must not be null
* @param listener collection listener, may be null
* @return the observed collection
* @throws IllegalArgumentException if the collection is null
* @throws IllegalArgumentException if there is no valid handler for the listener
*/
public static ObservableCollection decorate(
final Collection coll,
final Object listener) {
if (coll == null) {
throw new IllegalArgumentException("Collection must not be null");
}
return new ObservableCollection(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
}
}
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies) and takes a handler.
* <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.
*
* @param coll the collection to decorate, must not be null
* @param listener the observing handler, may be null
* @throws IllegalArgumentException if the collection is null
*/
protected ObservableCollection(
final Collection coll,
final Object listener) {
super(coll);
this.handler = createHandler(coll, listener);
this.handler.init(this, coll);
}
/**
* Constructor used by subclass views, such as subList.
*
* @param handler the observing handler, may be null
* @param coll the collection to decorate, must not be null
* @throws IllegalArgumentException if the collection is null
*/
protected ObservableCollection(
final ModificationHandler handler,
final Collection coll) {
super(coll);
this.handler = handler;
}
/**
* 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
//-----------------------------------------------------------------------
/**
* Gets the handler that is observing this collection.
*
* @return the observing handler, never null
*/
public ModificationHandler getHandler() {
return handler;
}
// Collection
//-----------------------------------------------------------------------
public boolean add(Object object) {
boolean result = false;
if (handler.preAdd(object)) {
result = collection.add(object);
handler.postAdd(object, result);
}
return result;
}
public boolean addAll(Collection coll) {
boolean result = false;
if (handler.preAddAll(coll)) {
result = collection.addAll(coll);
handler.postAddAll(coll, result);
}
return result;
}
public void clear() {
if (handler.preClear()) {
collection.clear();
handler.postClear();
}
}
public Iterator iterator() {
return new ObservableIterator(collection.iterator());
}
public boolean remove(Object object) {
boolean result = false;
if (handler.preRemove(object)) {
result = collection.remove(object);
handler.postRemove(object, result);
}
return result;
}
public boolean removeAll(Collection coll) {
boolean result = false;
if (handler.preRemoveAll(coll)) {
result = collection.removeAll(coll);
handler.postRemoveAll(coll, result);
}
return result;
}
public boolean retainAll(Collection coll) {
boolean result = false;
if (handler.preRetainAll(coll)) {
result = collection.retainAll(coll);
handler.postRetainAll(coll, result);
}
return result;
}
// Iterator
//-----------------------------------------------------------------------
/**
* Inner class Iterator for the ObservableCollection.
*/
protected class ObservableIterator extends AbstractIteratorDecorator {
protected int lastIndex = -1;
protected Object last;
protected ObservableIterator(Iterator iterator) {
super(iterator);
}
public Object next() {
last = super.next();
lastIndex++;
return last;
}
public void remove() {
if (handler.preRemoveIterated(lastIndex, last)) {
iterator.remove();
handler.postRemoveIterated(lastIndex, last);
lastIndex--;
}
}
}
}

View File

@ -1,306 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservableList.java,v 1.5 2003/11/27 22:55:15 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;
import java.util.List;
import java.util.ListIterator;
import org.apache.commons.collections.iterators.AbstractListIteratorDecorator;
/**
* Decorates a <code>List</code> implementation to observe modifications.
* <p>
* Each modifying method call made on this <code>List</code> is forwarded to a
* {@link ModificationHandler}.
* The handler manages the event, notifying listeners and optionally vetoing changes.
* The default handler is
* {@link org.apache.commons.collections.observed.standard.StandardModificationHandler StandardModificationHandler}.
* See this class for details of configuration available.
* <p>
* All indices on events returned by <code>subList</code> are relative to the
* base <code>List</code>.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ObservableList extends ObservableCollection implements List {
// Factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable list.
* <p>
* A {@link org.apache.commons.collections.observed.standard.StandardModificationHandler} will be created.
* This can be accessed by {@link #getHandler()} to add listeners.
*
* @param list the list to decorate, must not be null
* @return the observed List
* @throws IllegalArgumentException if the list is null
*/
public static ObservableList decorate(final List list) {
return new ObservableList(list, null);
}
/**
* Factory method to create an observable list 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>ObservableList</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 org.apache.commons.collections.observed.standard.StandardModificationHandler}.
*
* @param list the list to decorate, must not be null
* @param listener list listener, may be null
* @return the observed list
* @throws IllegalArgumentException if the list is null
* @throws IllegalArgumentException if there is no valid handler for the listener
*/
public static ObservableList decorate(
final List list,
final Object listener) {
if (list == null) {
throw new IllegalArgumentException("List must not be null");
}
return new ObservableList(list, listener);
}
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies) and takes a handler.
* <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.
*
* @param list the list to decorate, must not be null
* @param listener the listener, may be null
* @throws IllegalArgumentException if the list is null
*/
protected ObservableList(
final List list,
final Object listener) {
super(list, listener);
}
/**
* Constructor used by subclass views, such as subList.
*
* @param handler the handler to use, must not be null
* @param list the subList to decorate, must not be null
* @throws IllegalArgumentException if the list is null
*/
protected ObservableList(
final ModificationHandler handler,
final List list) {
super(handler, list);
}
/**
* Typecast the collection to a List.
*
* @return the wrapped collection as a List
*/
private List getList() {
return (List) getCollection();
}
// List API
//-----------------------------------------------------------------------
public Object get(int index) {
return getList().get(index);
}
public int indexOf(Object object) {
return getList().indexOf(object);
}
public int lastIndexOf(Object object) {
return getList().lastIndexOf(object);
}
//-----------------------------------------------------------------------
public void add(int index, Object object) {
if (handler.preAddIndexed(index, object)) {
getList().add(index, object);
handler.postAddIndexed(index, object);
}
}
public boolean addAll(int index, Collection coll) {
boolean result = false;
if (handler.preAddAllIndexed(index, coll)) {
result = getList().addAll(index, coll);
handler.postAddAllIndexed(index, coll, result);
}
return result;
}
public Object remove(int index) {
Object result = null;
if (handler.preRemoveIndexed(index)) {
result = getList().remove(index);
handler.postRemoveIndexed(index, result);
}
return result;
}
public Object set(int index, Object object) {
Object result = null;
if (handler.preSetIndexed(index, object)) {
result = getList().set(index, object);
handler.postSetIndexed(index, object, result);
}
return result;
}
public ListIterator listIterator() {
return new ObservableListIterator(getList().listIterator());
}
public ListIterator listIterator(int index) {
return new ObservableListIterator(getList().listIterator(index));
}
/**
* Returns a subList view on the original base <code>List</code>.
* <p>
* Changes to the subList affect the underlying List. Change events will
* return change indices relative to the underlying List, not the subList.
*
* @param fromIndex inclusive start index of the range
* @param toIndex exclusive end index of the range
* @return the subList view
*/
public List subList(int fromIndex, int toIndex) {
List subList = getList().subList(fromIndex, toIndex);
return new ObservableList(subList, getHandler().createSubListHandler(fromIndex, toIndex));
}
// ListIterator
//-----------------------------------------------------------------------
/**
* Inner class ListIterator for the ObservableList.
*/
protected class ObservableListIterator extends AbstractListIteratorDecorator {
protected Object last;
protected ObservableListIterator(ListIterator iterator) {
super(iterator);
}
public Object next() {
last = super.next();
return last;
}
public Object previous() {
last = iterator.previous();
return last;
}
public void remove() {
int index = iterator.previousIndex();
if (handler.preRemoveIterated(index, last)) {
iterator.remove();
handler.postRemoveIterated(index, last);
}
}
public void add(Object object) {
int index = iterator.nextIndex();
if (handler.preAddIterated(index, object)) {
iterator.add(object);
handler.postAddIterated(index, object);
}
}
public void set(Object object) {
int index = iterator.previousIndex();
if (handler.preSetIterated(index, object, last)) {
iterator.set(object);
handler.postSetIterated(index, object, last);
}
}
}
}

View File

@ -1,157 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservableSet.java,v 1.4 2003/11/27 22:55:15 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;
/**
* Decorates a <code>Set</code> implementation to observe modifications.
* <p>
* Each modifying method call made on this <code>Set</code> is forwarded to a
* {@link ModificationHandler}.
* The handler manages the event, notifying listeners and optionally vetoing changes.
* The default handler is
* {@link org.apache.commons.collections.observed.standard.StandardModificationHandler}.
* See this class for details of configuration available.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ObservableSet extends ObservableCollection implements Set {
// Factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable set.
* <p>
* A {@link org.apache.commons.collections.observed.standard.StandardModificationHandler} will be created.
* This can be accessed by {@link #getHandler()} to add listeners.
*
* @param set the set to decorate, must not be null
* @return the observed Set
* @throws IllegalArgumentException if the collection is null
*/
public static ObservableSet decorate(final Set set) {
return new ObservableSet(set, null);
}
/**
* Factory method to create an observable set 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>ObservableSet</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 org.apache.commons.collections.observed.standard.StandardModificationHandler}.
*
* @param set the set to decorate, must not be null
* @param listener set listener, may be null
* @return the observed set
* @throws IllegalArgumentException if the set is null
* @throws IllegalArgumentException if there is no valid handler for the listener
*/
public static ObservableSet decorate(
final Set set,
final Object listener) {
if (set == null) {
throw new IllegalArgumentException("Set must not be null");
}
return new ObservableSet(set, listener);
}
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies) and takes a handler.
* <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.
*
* @param set the set to decorate, must not be null
* @param listener the listener, may be null
* @throws IllegalArgumentException if the set is null
*/
protected ObservableSet(
final Set set,
final Object listener) {
super(set, listener);
}
}

View File

@ -1,182 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservableSortedBag.java,v 1.4 2003/11/27 22:55:15 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.Comparator;
import org.apache.commons.collections.SortedBag;
/**
* Decorates a <code>SortedBag</code> implementation to observe modifications.
* <p>
* Each modifying method call made on this <code>SortedBag</code> is forwarded to a
* {@link ModificationHandler}.
* The handler manages the event, notifying listeners and optionally vetoing changes.
* The default handler is
* {@link org.apache.commons.collections.observed.standard.StandardModificationHandler StandardModificationHandler}.
* See this class for details of configuration available.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ObservableSortedBag extends ObservableBag implements SortedBag {
// Factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable bag.
* <p>
* A {@link org.apache.commons.collections.observed.standard.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 collection is null
*/
public static ObservableSortedBag decorate(final SortedBag bag) {
return new ObservableSortedBag(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>ObservableSortedBag</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 org.apache.commons.collections.observed.standard.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 ObservableSortedBag decorate(
final SortedBag bag,
final Object listener) {
if (bag == null) {
throw new IllegalArgumentException("SortedBag must not be null");
}
return new ObservableSortedBag(bag, listener);
}
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies) and takes a handler.
* <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.
*
* @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 ObservableSortedBag(
final SortedBag bag,
final Object listener) {
super(bag, listener);
}
/**
* Typecast the collection to a SortedBag.
*
* @return the wrapped collection as a SortedBag
*/
private SortedBag getSortedBag() {
return (SortedBag) getCollection();
}
// SortedBag API
//-----------------------------------------------------------------------
public Comparator comparator() {
return getSortedBag().comparator();
}
public Object first() {
return getSortedBag().first();
}
public Object last() {
return getSortedBag().last();
}
}

View File

@ -1,197 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservableSortedSet.java,v 1.5 2003/11/27 22:55:15 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.Comparator;
import java.util.SortedSet;
/**
* Decorates a <code>SortedSet</code> implementation to observe modifications.
* <p>
* Each modifying method call made on this <code>SortedSet</code> is forwarded to a
* {@link ModificationHandler}.
* The handler manages the event, notifying listeners and optionally vetoing changes.
* The default handler is
* {@link org.apache.commons.collections.observed.standard.StandardModificationHandler StandardModificationHandler}.
* See this class for details of configuration available.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/11/27 22:55:15 $
*
* @author Stephen Colebourne
*/
public class ObservableSortedSet extends ObservableSet implements SortedSet {
// Factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable set.
* <p>
* A {@link org.apache.commons.collections.observed.standard.StandardModificationHandler} will be created.
* This can be accessed by {@link #getHandler()} to add listeners.
*
* @param set the set to decorate, must not be null
* @return the observed Set
* @throws IllegalArgumentException if the collection is null
*/
public static ObservableSortedSet decorate(final SortedSet set) {
return new ObservableSortedSet(set, null);
}
/**
* Factory method to create an observable set 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>ObservableSortedSet</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 org.apache.commons.collections.observed.standard.StandardModificationHandler}.
*
* @param set the set to decorate, must not be null
* @param listener set listener, may be null
* @return the observed set
* @throws IllegalArgumentException if the set is null
* @throws IllegalArgumentException if there is no valid handler for the listener
*/
public static ObservableSortedSet decorate(
final SortedSet set,
final Object listener) {
if (set == null) {
throw new IllegalArgumentException("SortedSet must not be null");
}
return new ObservableSortedSet(set, listener);
}
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies) and takes a handler.
* <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.
*
* @param set the set to decorate, must not be null
* @param listener the listener, may be null
* @throws IllegalArgumentException if the set is null
*/
protected ObservableSortedSet(
final SortedSet set,
final Object listener) {
super(set, listener);
}
/**
* Typecast the collection to a SortedSet.
*
* @return the wrapped collection as a SortedSet
*/
private SortedSet getSortedSet() {
return (SortedSet) getCollection();
}
// SortedSet API
//-----------------------------------------------------------------------
public Comparator comparator() {
return getSortedSet().comparator();
}
public Object first() {
return getSortedSet().first();
}
public Object last() {
return getSortedSet().last();
}
//-----------------------------------------------------------------------
public SortedSet subSet(Object fromElement, Object toElement) {
SortedSet subSet = getSortedSet().subSet(fromElement, toElement);
return new ObservableSortedSet(subSet, getHandler().createSubSetHandler(fromElement, toElement));
}
public SortedSet headSet(Object toElement) {
SortedSet headSet = getSortedSet().headSet(toElement);
return new ObservableSortedSet(headSet, getHandler().createHeadSetHandler(toElement));
}
public SortedSet tailSet(Object fromElement) {
SortedSet tailSet = getSortedSet().tailSet(fromElement);
return new ObservableSortedSet(tailSet, getHandler().createTailSetHandler(fromElement));
}
}

View File

@ -1,14 +0,0 @@
<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 ObservableXxx class. They can also be constructed from the <code>XxxUtils</code>
class (where Xxx is the collection type).
<p>
<code>List observableList = ObservableList.decorate(new ArrayList(), listener);</code>
<br />OR<br />
<code>List observableList = ListUtils.observableList(new ArrayList(), listener);</code>
</BODY>

View File

@ -1,355 +0,0 @@
/*
* $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.8 2003/11/27 22:55:16 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.standard;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
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;
import org.apache.commons.collections.observed.ObservableCollection;
/**
* Event class that encapsulates the event information for a
* standard collection event. Two subclasses are provided, one for
* pre and one for post events.
* <p>
* The information stored in this event is all that is available as
* parameters or return values.
* In addition, the <code>size</code> method is used on the collection.
* All objects used are the real objects from the method calls, not clones.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.8 $ $Date: 2003/11/27 22:55:16 $
*
* @author Stephen Colebourne
*/
public class StandardModificationEvent extends ModificationEvent {
/** The size before the event */
protected final int preSize;
/** The index of the change */
protected final int index;
/** The object of the change */
protected final Object object;
/** The number of changes */
protected final int repeat;
/** The result of the method call */
protected final Object previous;
/** The view that the event came from, null if none */
protected final ObservableCollection view;
/** The offset index within the main collection of the view, -1 if none */
protected final int viewOffset;
// Constructor
//-----------------------------------------------------------------------
/**
* Constructor.
*
* @param obsCollection the event source
* @param handler the handler
* @param type the event type
* @param preSize the size before the change
* @param index the index that changed
* @param object the value that changed
* @param repeat the number of repeats
* @param previous the previous value being removed/replaced
* @param view the view collection, null if event from main collection
* @param viewOffset the offset within the main collection of the view, -1 if unknown
*/
public StandardModificationEvent(
final ObservableCollection obsCollection,
final ModificationHandler handler,
final int type,
final int preSize,
final int index,
final Object object,
final int repeat,
final Object previous,
final ObservableCollection view,
final int viewOffset) {
super(obsCollection, handler, type);
this.preSize = preSize;
this.index = index;
this.object = object;
this.repeat = repeat;
this.previous = previous;
this.view = view;
this.viewOffset = viewOffset;
}
// Change info
//-----------------------------------------------------------------------
/**
* Gets the index of the change.
* <p>
* This is <code>-1</code> when not applicable. Typically only used
* for {@link java.util.List} events.
*
* @return the change index
*/
public int getChangeIndex() {
return index;
}
/**
* Gets the object that was added/removed/set.
* <p>
* This is <code>null</code> when not applicable, such as for clear().
*
* @return the changing object
*/
public Object getChangeObject() {
return object;
}
/**
* Gets the collection of changed objects.
* <p>
* For clear, it is an empty list.
* For bulk operations, it is the collection.
* For non-bulk operations, it is a size one list.
*
* @return the changing collection, never null
*/
public Collection getChangeCollection() {
if (object == null) {
return Collections.EMPTY_LIST;
} else if (isType(ModificationEventType.GROUP_BULK)) {
if (object instanceof Collection) {
return (Collection) object;
} else {
throw new IllegalStateException(
"Bulk operations must involve a Collection, but was " + object.getClass().getName());
}
} else {
return Collections.singletonList(object);
}
}
/**
* Gets the number of times the object was added/removed.
* <p>
* This is normally <code>1</code>, but will be used for
* {@link org.apache.commons.collections.Bag Bag} events.
*
* @return the repeat
*/
public int getChangeRepeat() {
return repeat;
}
/**
* Gets the previous value that is being replaced or removed.
* <p>
* This is only returned if the value definitely was previously in the
* collection. Bulk operatons will not return this.
*
* @return the previous value that was removed/replaced
*/
public Object getPrevious() {
return previous;
}
// Size info
//-----------------------------------------------------------------------
/**
* Gets the size before the change.
*
* @return the size before the change
*/
public int getPreSize() {
return preSize;
}
// View info
//-----------------------------------------------------------------------
/**
* Gets the view, <code>null</code> if none.
* <p>
* A view is a subSet, headSet, tailSet, subList and so on.
*
* @return the view
*/
public ObservableCollection getView() {
return view;
}
/**
* Checks whether the event originated from a view.
*
* @return true if event came from a view
*/
public boolean isView() {
return (view != null);
}
/**
* Gets the view offset, <code>-1</code> if no view or unknown offset.
* <p>
* This refers to the index of the start of the view within the main collection.
*
* @return the view offset
*/
public int getViewOffset() {
return viewOffset;
}
// Event type
//-----------------------------------------------------------------------
/**
* Checks to see if the event is an add event (add/addAll).
*
* @return true if of the specified type
*/
public boolean isTypeAdd() {
return (type & ModificationEventType.GROUP_ADD) > 0;
}
/**
* Checks to see if the event is a remove event (remove/removeAll/retainAll/clear).
*
* @return true if of the specified type
*/
public boolean isTypeReduce() {
return (type & ModificationEventType.GROUP_REDUCE) > 0;
}
/**
* Checks to see if the event is a change event (set).
*
* @return true if of the specified type
*/
public boolean isTypeChange() {
return (type & ModificationEventType.GROUP_CHANGE) > 0;
}
/**
* Checks to see if the event is a bulk event (addAll/removeAll/retainAll/clear).
*
* @return true if of the specified type
*/
public boolean isTypeBulk() {
return (type & ModificationEventType.GROUP_BULK) > 0;
}
/**
* Checks to see if the event is of the specified type.
* <p>
* This is any combination of constants from {@link ModificationEventType}.
*
* @param eventType an event type constant
* @return true if of the specified type
*/
public boolean isType(final int eventType) {
return (type & eventType) > 0;
}
// toString
//-----------------------------------------------------------------------
/**
* Gets a debugging string version of the event.
*
* @return a debugging string
*/
public String toString() {
StringBuffer buf = new StringBuffer(64);
buf.append("ModificationEvent[type=");
buf.append(ModificationEventType.toString(type));
if (index >= 0) {
buf.append(",index=");
buf.append(index);
}
if (type != ModificationEventType.CLEAR) {
buf.append(",object=");
if (object instanceof List) {
buf.append("List:size:");
buf.append(((List) object).size());
} else if (object instanceof Set) {
buf.append("Set:size:");
buf.append(((Set) object).size());
} else if (object instanceof Bag) {
buf.append("Bag:size:");
buf.append(((Bag) object).size());
} else if (object instanceof Collection) {
buf.append("Collection:size:");
buf.append(((Collection) object).size());
} else if (object instanceof Map) {
buf.append("Map:size:");
buf.append(((Map) object).size());
} else if (object instanceof Object[]) {
buf.append("Array:size:");
buf.append(((Object[]) object).length);
} else if (object == null) {
buf.append("null");
} else {
buf.append(object.toString());
}
}
buf.append(']');
return buf.toString();
}
}

View File

@ -1,581 +0,0 @@
/*
* $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.8 2003/11/27 22:55:16 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.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;
import org.apache.commons.collections.observed.ObservableCollection;
/**
* The standard implementation of a <code>ModificationHandler</code> that
* sends standard JavaBean style events to listeners.
* <p>
* The information gathered by this implementation is all that is available
* as parameters or return values.
* In addition, the <code>size</code> method is used on the collection.
* All objects used are the real objects from the method calls, not clones.
* <p>
* Each listener can be filtered. There are separate filters for pre and post
* modification events.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.8 $ $Date: 2003/11/27 22:55:16 $
*
* @author Stephen Colebourne
*/
public class StandardModificationHandler extends ModificationHandler {
/** 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];
/** A reusable empty holders array. */
protected static final PostHolder[] EMPTY_POST_HOLDERS = new PostHolder[0];
/** The event mask as to which event types to send on pre events. */
protected int preMask = ModificationEventType.GROUP_NONE;
/** The event mask as to which event types to send on post events. */
protected int postMask = ModificationEventType.GROUP_NONE;
/** The event listeners. */
protected PreHolder[] preHolder = EMPTY_PRE_HOLDERS;
/** The event listeners. */
protected PostHolder[] postHolder = EMPTY_POST_HOLDERS;
/**
* Temporary store for the size.
* This makes the class thread-unsafe, but you should sync collections anyway.
*/
protected int preSize;
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor the creates the handler but leaves it invalid.
* <p>
* The handler can only be used after it has been properly initialized.
* This is normally done automatically by
* {@link ObservableCollection#decorate(Collection, Object)}.
*/
public StandardModificationHandler() {
super();
}
/**
* Constructor the creates the handler but leaves it invalid.
* <p>
* The handler can only be used after it has been properly initialized.
* This is normally done automatically by
* {@link ObservableCollection#decorate(Collection, Object)}.
*
* @param pre the pre listener
* @param preMask the mask for the pre listener
* @param post the post listener
* @param postMask the mask for the post listener
*/
public StandardModificationHandler(
StandardPreModificationListener pre, int preMask,
StandardPostModificationListener post, int postMask) {
super();
if (pre != null) {
preHolder = new PreHolder[1];
preHolder[0] = new PreHolder(pre, preMask);
this.preMask = preMask;
}
if (post != null) {
postHolder = new PostHolder[1];
postHolder[0] = new PostHolder(post, postMask);
this.postMask = postMask;
}
}
// Pre Listeners
//----------------------------------------------------------------------
/**
* Gets an array of all the pre listeners active in the handler.
* <p>
* All listeners will be instances of StandardPreModificationListener.
*
* @return the listeners
*/
public synchronized Object[] getPreModificationListeners() {
Object[] lnrs = new Object[preHolder.length];
for (int i = 0; i < preHolder.length; i++) {
lnrs[i] = preHolder[i].listener;
}
return lnrs;
}
/**
* Adds a listener to the handler for pre modification events.
* <p>
* No error occurs if the listener is <code>null</code>.
*
* @param listener the listener to add, may be null (ignored)
* @throws ClassCastException if the listener is not a StandardPreModificationListener
*/
public void addPreModificationListener(Object listener) {
addPreModificationListener((StandardPreModificationListener) listener, -1);
}
/**
* Adds a pre listener to the list held in the handler.
* <p>
* No error occurs if the listener is <code>null</code>.
*
* @param listener the listener to add, may be null (ignored)
* @param mask the mask for events (0 for none, -1 for all)
*/
public synchronized void addPreModificationListener(StandardPreModificationListener listener, int mask) {
if (listener != null) {
int oldSize = preHolder.length;
PreHolder[] array = new PreHolder[oldSize + 1];
System.arraycopy(preHolder, 0, array, 0, oldSize);
array[oldSize] = new PreHolder(listener, mask);
preHolder = array;
calculatePreMask();
}
}
/**
* Removes a pre listener to the list held in the handler.
* <p>
* No error occurs if the listener is not in the list or the type
* of the listener is incorrect.
* The listener is matched using ==.
*
* @param listener the listener to remove, may be null (ignored)
*/
public synchronized void removePreModificationListener(Object listener) {
if (listener != null) {
switch (preHolder.length) {
case 0:
return;
case 1:
if (preHolder[0].listener == listener) {
preHolder = EMPTY_PRE_HOLDERS;
calculatePreMask();
}
return;
default:
PreHolder[] array = new PreHolder[preHolder.length - 1];
boolean match = false;
for (int i = 0; i < preHolder.length; i++) {
if (match) {
array[i - 1] = preHolder[i];
} else if (preHolder[i].listener == listener) {
match = true;
} else {
array[i] = preHolder[i];
}
}
preHolder = array;
calculatePreMask();
return;
}
}
}
/**
* Sets the masks of a listener.
* <p>
* No error occurs if the listener is not in the list.
* The listener is matched using ==.
*
* @param listener the listener to change, may be null
* @param mask the new mask (0 for none, -1 for all)
*/
public synchronized void setPreModificationListenerMask(StandardPreModificationListener listener, int mask) {
if (listener != null) {
for (int i = 0; i < preHolder.length; i++) {
if (preHolder[i].listener == listener) {
preHolder[i].mask = mask;
calculatePreMask();
break;
}
}
}
}
/**
* Calculate the combined masks.
*/
protected void calculatePreMask() {
preMask = ModificationEventType.GROUP_NONE;
for (int i = 0; i < preHolder.length; i++) {
preMask |= preHolder[i].mask;
}
}
protected static class PreHolder {
final StandardPreModificationListener listener;
int mask;
PreHolder(StandardPreModificationListener listener, int mask) {
this.listener = listener;
this.mask = mask;
}
public String toString() {
return "[" + listener + "," + ModificationEventType.toString(mask) + "]";
}
}
// Post Listeners
//----------------------------------------------------------------------
/**
* Gets an array of all the post listeners active in the handler.
* <p>
* All listeners will be instances of StandardModificationListener.
*
* @return the listeners
*/
public synchronized Object[] getPostModificationListeners() {
Object[] lnrs = new Object[postHolder.length];
for (int i = 0; i < postHolder.length; i++) {
lnrs[i] = postHolder[i].listener;
}
return lnrs;
}
/**
* Adds a listener to the handler for post modification events.
* <p>
* No error occurs if the listener is <code>null</code>.
*
* @param listener the listener to add, may be null (ignored)
* @throws ClassCastException if the listener is not a StandardPreModificationListener
*/
public void addPostModificationListener(Object listener) {
addPostModificationListener((StandardPostModificationListener) listener, -1);
}
/**
* Adds a post listener to the list held in the handler.
* <p>
* No error occurs if the listener is <code>null</code>.
*
* @param listener the listener to add, may be null (ignored)
* @param mask the mask for events (0 for none, -1 for all)
*/
public synchronized void addPostModificationListener(StandardPostModificationListener listener, int mask) {
if (listener != null) {
int oldSize = postHolder.length;
PostHolder[] array = new PostHolder[oldSize + 1];
System.arraycopy(postHolder, 0, array, 0, oldSize);
array[oldSize] = new PostHolder(listener, mask);
postHolder = array;
calculatePostMask();
}
}
/**
* Removes a post listener to the list held in the handler.
* <p>
* No error occurs if the listener is not in the list or the type
* of the listener is incorrect.
* The listener is matched using ==.
*
* @param listener the listener to remove, may be null (ignored)
*/
public synchronized void removePostModificationListener(Object listener) {
if (listener != null) {
switch (postHolder.length) {
case 0:
return;
case 1:
if (postHolder[0].listener == listener) {
postHolder = EMPTY_POST_HOLDERS;
calculatePostMask();
}
return;
default:
PostHolder[] array = new PostHolder[postHolder.length - 1];
boolean match = false;
for (int i = 0; i < postHolder.length; i++) {
if (match) {
array[i - 1] = postHolder[i];
} else if (postHolder[i].listener == listener) {
match = true;
} else {
array[i] = postHolder[i];
}
}
postHolder = array;
calculatePostMask();
return;
}
}
}
/**
* Sets the masks of a listener.
* <p>
* No error occurs if the listener is not in the list.
* The listener is matched using ==.
*
* @param listener the listener to change, may be null
* @param mask the new mask (0 for none, -1 for all)
*/
public synchronized void setPostModificationListenerMask(StandardPostModificationListener listener, int mask) {
if (listener != null) {
for (int i = 0; i < postHolder.length; i++) {
if (postHolder[i].listener == listener) {
postHolder[i].mask = mask;
calculatePostMask();
break;
}
}
}
}
/**
* Calculate the combined masks.
*/
protected void calculatePostMask() {
postMask = ModificationEventType.GROUP_NONE;
for (int i = 0; i < postHolder.length; i++) {
postMask |= postHolder[i].mask;
}
}
protected static class PostHolder {
final StandardPostModificationListener listener;
int mask;
PostHolder(StandardPostModificationListener listener, int mask) {
this.listener = listener;
this.mask = mask;
}
public String toString() {
return "[" + listener + "," + ModificationEventType.toString(mask) + "]";
}
}
// Pre event sending
//-----------------------------------------------------------------------
/**
* Handles the pre event.
*
* @param type the event type to send
* @param index the index where the change starts, the method param or derived
* @param object the object that will be added/removed/set, the method param or derived
* @param repeat the number of repeats of the add/remove, the method param or derived
* @param previous the previous value that will be removed/replaced, must exist in coll
* @param view the view collection that the change was actioned on, null if no view
* @param viewOffset the offset of the subList view, -1 if unknown
* @return true to call the decorated collection
*/
protected boolean preEvent(
int type, int index, Object object,
int repeat, Object previous, ObservableCollection view, int viewOffset) {
preSize = getObservedCollection().size();
return firePreEvent(type, index, object, repeat, previous, view, viewOffset);
}
/**
* Sends the pre event to the listeners.
*
* @param type the event type to send
* @param index the index where the change starts, the method param or derived
* @param object the object that will be added/removed/set, the method param or derived
* @param repeat the number of repeats of the add/remove, the method param or derived
* @param previous the previous value that will be removed/replaced, must exist in coll
* @param view the view collection that the change was actioned on, null if no view
* @param viewOffset the offset of the subList view, -1 if unknown
* @return true to call the decorated collection
*/
protected boolean firePreEvent(
int type, int index, Object object, int repeat,
Object previous, ObservableCollection view, int viewOffset) {
if ((preMask & type) > 0) {
StandardPreModificationEvent event = null;
synchronized (this) {
for (int i = 0; i < preHolder.length; i++) {
PreHolder holder = preHolder[i];
if ((holder.mask & type) > 0) {
if (event == null) {
event = new StandardPreModificationEvent(
getObservedCollection(), this, type, preSize, index, object,
repeat, previous, view, viewOffset);
}
holder.listener.modificationOccurring(event);
}
}
}
}
return true;
}
// Post event sending
//-----------------------------------------------------------------------
/**
* Handles the post event.
*
* @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, the method param or derived
* @param object the object that was added/removed/set, the method param or derived
* @param repeat the number of repeats of the add/remove, the method param or derived
* @param previous the previous value that was removed/replace, must have existed in coll
* @param view the view collection that the change was actioned on, null if no view
* @param viewOffset the offset of the subList view, -1 if unknown
*/
protected void postEvent(
boolean modified, int type, int index, Object object,
int repeat, Object previous, ObservableCollection view, int viewOffset) {
if (modified) {
firePostEvent(type, index, object, repeat, previous, view, viewOffset);
}
}
/**
* Sends the post event to the listeners.
*
* @param type the event type to send
* @param index the index where the change starts, the method param or derived
* @param object the object that was added/removed/set, the method param or derived
* @param repeat the number of repeats of the add/remove, the method param or derived
* @param previous the previous value that was removed/replace, must have existed in coll
* @param view the view collection that the change was actioned on, null if no view
* @param viewOffset the offset of the subList view, -1 if unknown
*/
protected void firePostEvent(
int type, int index, Object object, int repeat,
Object previous, ObservableCollection view, int viewOffset) {
if ((postMask & type) > 0) {
StandardPostModificationEvent event = null;
synchronized (this) {
for (int i = 0; i < postHolder.length; i++) {
PostHolder holder = postHolder[i];
if ((holder.mask & type) > 0) {
if (event == null) {
event = new StandardPostModificationEvent(
getObservedCollection(), this, type, preSize, index,
object, repeat, previous, view, viewOffset);
}
holder.listener.modificationOccurred(event);
}
}
}
}
}
// Event handling
//-----------------------------------------------------------------------
/**
* Send an event after clear() is called.
* <p>
* Override to only send event if something actually cleared.
*/
protected void postClear() {
postEvent(preSize > 0, ModificationEventType.CLEAR, -1, null, 1, null, null, -1);
}
// Factory
//-----------------------------------------------------------------------
/**
* Factory implementation for the StandardModificationHandler.
*
* @author Stephen Colebourne
*/
static class Factory implements ModificationHandlerFactory {
/**
* Creates a StandardModificationHandler using the listener.
*
* @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
*/
public ModificationHandler createHandler(Collection coll, Object listener) {
if (listener instanceof StandardPreModificationListener) {
if (listener instanceof StandardPostModificationListener) {
return new StandardModificationHandler(
(StandardPreModificationListener) listener, -1,
(StandardPostModificationListener) listener, -1);
} else {
return new StandardModificationHandler(
(StandardPreModificationListener) listener, -1, null, 0);
}
}
if (listener instanceof StandardPostModificationListener) {
return new StandardModificationHandler(
null, 0, (StandardPostModificationListener) listener, -1);
}
return null;
}
}
}

View File

@ -1,73 +0,0 @@
/*
* $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.2 2003/11/27 22:55:16 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.standard;
/**
* A listener for the <code>StandardModificationHandler</code> that is called
* both before the collection is changed and after the change has occurred.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/11/27 22:55:16 $
*
* @author Stephen Colebourne
*/
public interface StandardModificationListener
extends StandardPreModificationListener, StandardPostModificationListener {
}

View File

@ -1,145 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardPostModificationEvent.java,v 1.6 2003/11/27 22:55:16 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.standard;
import org.apache.commons.collections.observed.ModificationHandler;
import org.apache.commons.collections.observed.ObservableCollection;
/**
* Event class that encapsulates all the event information for a
* standard collection event.
* <p>
* The information stored in this event is all that is available as
* parameters or return values.
* In addition, the <code>size</code> method is used on the collection.
* All objects used are the real objects from the method calls, not clones.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2003/11/27 22:55:16 $
*
* @author Stephen Colebourne
*/
public class StandardPostModificationEvent extends StandardModificationEvent {
/** The size after the event */
protected final int postSize;
// Constructor
//-----------------------------------------------------------------------
/**
* Constructor.
*
* @param obsCollection the event source
* @param handler the handler
* @param type the event type
* @param preSize the size before the change
* @param index the index that changed
* @param object the value that changed
* @param repeat the number of repeats
* @param previous the previous value being removed/replaced
* @param view the view collection, null if event from main collection
* @param viewOffset the offset within the main collection of the view, -1 if unknown
*/
public StandardPostModificationEvent(
final ObservableCollection obsCollection,
final ModificationHandler handler,
final int type,
final int preSize,
final int index,
final Object object,
final int repeat,
final Object previous,
final ObservableCollection view,
final int viewOffset) {
super(obsCollection, handler, type, preSize, index,
object, repeat, previous, view, viewOffset);
postSize = collection.size();
}
// Size info
//-----------------------------------------------------------------------
/**
* Gets the size after the change.
*
* @return the size after the change
*/
public int getPostSize() {
return postSize;
}
/**
* Gets the size change, negative for remove/clear.
*
* @return the size before the change
*/
public int getSizeChange() {
return postSize - preSize;
}
/**
* Returns true if the size of the collection changed.
*
* @return true is the size changed
*/
public boolean isSizeChanged() {
return (preSize != postSize);
}
}

View File

@ -1,85 +0,0 @@
/*
* $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.3 2003/11/27 22:55:16 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.standard;
import org.apache.commons.collections.observed.ModificationListener;
/**
* A listener for the <code>StandardModificationHandler</code> that is called
* when a collection has been changed.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/11/27 22:55:16 $
*
* @author Stephen Colebourne
*/
public interface StandardPostModificationListener extends ModificationListener {
/**
* A collection modification occurred.
* <p>
* This method should be processed quickly, as with all event handling.
* It should also avoid modifying the event source (the collection).
* Finally it should avoid throwing an exception.
*
* @param event the event detail
*/
public void modificationOccurred(StandardPostModificationEvent event);
}

View File

@ -1,112 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardPreModificationEvent.java,v 1.6 2003/11/27 22:55:16 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.standard;
import org.apache.commons.collections.observed.ModificationHandler;
import org.apache.commons.collections.observed.ObservableCollection;
/**
* Event class that encapsulates all the event information for a
* standard collection event.
* <p>
* The information stored in this event is all that is available as
* parameters or return values.
* In addition, the <code>size</code> method is used on the collection.
* All objects used are the real objects from the method calls, not clones.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.6 $ $Date: 2003/11/27 22:55:16 $
*
* @author Stephen Colebourne
*/
public class StandardPreModificationEvent extends StandardModificationEvent {
// Constructor
//-----------------------------------------------------------------------
/**
* Constructor.
*
* @param obsCollection the event source
* @param handler the handler
* @param type the event type
* @param preSize the size before the change
* @param index the index that changed
* @param object the value that changed
* @param repeat the number of repeats
* @param previous the previous value being removed/replaced
* @param view the view collection, null if event from main collection
* @param viewOffset the offset within the main collection of the view, -1 if unknown
*/
public StandardPreModificationEvent(
final ObservableCollection obsCollection,
final ModificationHandler handler,
final int type,
final int preSize,
final int index,
final Object object,
final int repeat,
final Object previous,
final ObservableCollection view,
final int viewOffset) {
super(obsCollection, handler, type, preSize, index,
object, repeat, previous, view, viewOffset);
}
}

View File

@ -1,87 +0,0 @@
/*
* $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.3 2003/11/27 22:55:16 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.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.
*
* @deprecated TO BE REMOVED BEFORE v3.0
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/11/27 22:55:16 $
*
* @author Stephen Colebourne
*/
public interface StandardPreModificationListener extends ModificationListener {
/**
* A collection modification is occurring.
* <p>
* To veto the change, throw <code>ModicationVetoedException</code>.
* <p>
* This method should be processed quickly, as with all event handling.
* It should also avoid modifying the event source (the collection).
*
* @param event the event detail
* @throws ModicationVetoedException to veto
*/
public void modificationOccurring(StandardPreModificationEvent event);
}

View File

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

View File

@ -1,97 +0,0 @@
/*
* $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.4 2003/09/28 21:50:37 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.4 $ $Date: 2003/09/28 21:50:37 $
*
* @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(TestObservableBag.suite());
suite.addTest(TestObservableBuffer.suite());
suite.addTest(TestObservableCollection.suite());
suite.addTest(TestObservableList.suite());
suite.addTest(TestObservableSet.suite());
suite.addTest(TestObservableSortedBag.suite());
suite.addTest(TestObservableSortedSet.suite());
return suite;
}
}

View File

@ -1,110 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservableBag.java,v 1.5 2003/11/18 22:37:17 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.bag.AbstractTestBag;
/**
* Extension of {@link TestBag} for exercising the
* {@link ObservableBag} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/11/18 22:37:17 $
*
* @author Stephen Colebourne
*/
public class TestObservableBag extends AbstractTestBag implements ObservedTestHelper.ObservedFactory {
public TestObservableBag(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableBag.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableBag.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Bag makeBag() {
return ObservableBag.decorate(new HashBag(), ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedSet() {
ObservedTestHelper.bulkTestObservedBag(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableBag.decorate(new HashBag());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableBag.decorate(new HashBag(), listener);
}
}

View File

@ -1,129 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservableBuffer.java,v 1.5 2003/11/18 22:37:17 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.Arrays;
import java.util.Collection;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.ArrayStack;
import org.apache.commons.collections.collection.AbstractTestCollection;
/**
* Extension of {@link TestCollection} for exercising the
* {@link ObservableBuffer} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/11/18 22:37:17 $
*
* @author Stephen Colebourne
*/
public class TestObservableBuffer extends AbstractTestCollection implements ObservedTestHelper.ObservedFactory {
public TestObservableBuffer(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableBuffer.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableBuffer.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Collection makeConfirmedCollection() {
return new ArrayStack();
}
public Collection makeConfirmedFullCollection() {
ArrayStack stack = new ArrayStack();
stack.addAll(Arrays.asList(getFullElements()));
return stack;
}
public Collection makeCollection() {
return ObservableBuffer.decorate(new ArrayStack(), ObservedTestHelper.LISTENER);
}
public Collection makeFullCollection() {
List stack = new ArrayStack();
stack.addAll(Arrays.asList(getFullElements()));
return ObservableBuffer.decorate(stack, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedBuffer() {
ObservedTestHelper.bulkTestObservedBuffer(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableBuffer.decorate(new ArrayStack());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableBuffer.decorate(new ArrayStack(), listener);
}
}

View File

@ -1,166 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservableCollection.java,v 1.4 2003/11/18 22:37:17 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.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.collection.AbstractTestCollection;
/**
* Extension of {@link TestCollection} for exercising the
* {@link ObservedCollection} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/18 22:37:17 $
*
* @author Stephen Colebourne
*/
public class TestObservableCollection extends AbstractTestCollection implements ObservedTestHelper.ObservedFactory {
public TestObservableCollection(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableCollection.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableCollection.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Collection makeConfirmedCollection() {
return new ArrayList();
}
public Collection makeConfirmedFullCollection() {
List list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
public Collection makeCollection() {
return ObservableCollection.decorate(new ArrayList(), ObservedTestHelper.LISTENER);
}
public Collection makeFullCollection() {
List list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return ObservableCollection.decorate(list, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedCollection() {
ObservedTestHelper.bulkTestObservedCollection(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableCollection.decorate(new ArrayList());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableCollection.decorate(new ArrayList(), listener);
}
// public void testFactoryWithMasks() {
// ObservedCollection coll = ObservedCollection.decorate(new ArrayList(), LISTENER, -1, 0);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent != null);
// assertTrue(LISTENER.postEvent == null);
//
// coll = ObservedCollection.decorate(new ArrayList(), LISTENER, 0, -1);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent == null);
// assertTrue(LISTENER.postEvent != null);
//
// coll = ObservedCollection.decorate(new ArrayList(), LISTENER, -1, -1);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent != null);
// assertTrue(LISTENER.postEvent != null);
//
// coll = ObservedCollection.decorate(new ArrayList(), LISTENER, 0, 0);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent == null);
// assertTrue(LISTENER.postEvent == null);
//
// coll = ObservedCollection.decorate(new ArrayList(), LISTENER, ModificationEventType.ADD, ModificationEventType.ADD_ALL);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent != null);
// assertTrue(LISTENER.postEvent == null);
// }
//
}

View File

@ -1,118 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservableList.java,v 1.4 2003/11/18 22:37:17 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.ArrayList;
import java.util.Arrays;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.list.AbstractTestList;
/**
* Extension of {@link TestList} for exercising the
* {@link ObservedList} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/18 22:37:17 $
*
* @author Stephen Colebourne
*/
public class TestObservableList extends AbstractTestList implements ObservedTestHelper.ObservedFactory {
public TestObservableList(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableList.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableList.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public List makeEmptyList() {
return ObservableList.decorate(new ArrayList(), ObservedTestHelper.LISTENER);
}
public List makeFullList() {
List set = new ArrayList();
set.addAll(Arrays.asList(getFullElements()));
return ObservableList.decorate(set, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedList() {
ObservedTestHelper.bulkTestObservedList(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableList.decorate(new ArrayList());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableList.decorate(new ArrayList(), listener);
}
}

View File

@ -1,118 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservableSet.java,v 1.4 2003/11/18 22:37:17 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.Arrays;
import java.util.HashSet;
import java.util.Set;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.set.AbstractTestSet;
/**
* Extension of {@link TestSet} for exercising the
* {@link ObservedSet} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.4 $ $Date: 2003/11/18 22:37:17 $
*
* @author Stephen Colebourne
*/
public class TestObservableSet extends AbstractTestSet implements ObservedTestHelper.ObservedFactory {
public TestObservableSet(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableSet.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableSet.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Set makeEmptySet() {
return ObservableSet.decorate(new HashSet(), ObservedTestHelper.LISTENER);
}
public Set makeFullSet() {
Set set = new HashSet();
set.addAll(Arrays.asList(getFullElements()));
return ObservableSet.decorate(set, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedSet() {
ObservedTestHelper.bulkTestObservedSet(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableSet.decorate(new HashSet());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableSet.decorate(new HashSet(), listener);
}
}

View File

@ -1,110 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservableSortedBag.java,v 1.5 2003/11/18 22:37:17 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.TreeBag;
import org.apache.commons.collections.bag.AbstractTestSortedBag;
/**
* Extension of {@link TestSortedBag} for exercising the
* {@link ObservedSortedBag} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/11/18 22:37:17 $
*
* @author Stephen Colebourne
*/
public class TestObservableSortedBag extends AbstractTestSortedBag implements ObservedTestHelper.ObservedFactory {
public TestObservableSortedBag(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableSortedBag.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableSortedBag.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Bag makeBag() {
return ObservableSortedBag.decorate(new TreeBag(), ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedSortedBag() {
ObservedTestHelper.bulkTestObservedSortedBag(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableSortedBag.decorate(new TreeBag());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableSortedBag.decorate(new TreeBag(), listener);
}
}

View File

@ -1,119 +0,0 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/TestObservableSortedSet.java,v 1.7 2003/11/18 22:37:17 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.Arrays;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import junit.framework.Test;
import org.apache.commons.collections.BulkTest;
import org.apache.commons.collections.set.AbstractTestSortedSet;
/**
* Extension of {@link TestSortedSet} for exercising the
* {@link ObservedSortedSet} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.7 $ $Date: 2003/11/18 22:37:17 $
*
* @author Stephen Colebourne
*/
public class TestObservableSortedSet extends AbstractTestSortedSet implements ObservedTestHelper.ObservedFactory {
public TestObservableSortedSet(String testName) {
super(testName);
}
public static Test suite() {
return BulkTest.makeSuite(TestObservableSortedSet.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableSortedSet.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Set makeEmptySet() {
return ObservableSortedSet.decorate(new TreeSet(), ObservedTestHelper.LISTENER);
}
public Set makeFullSet() {
SortedSet set = new TreeSet();
set.addAll(Arrays.asList(getFullElements()));
return ObservableSortedSet.decorate(set, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedSortedSet() {
ObservedTestHelper.bulkTestObservedSortedSet(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableSortedSet.decorate(new TreeSet());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableSortedSet.decorate(new TreeSet(), listener);
}
}