Add support for event reporting from SubList view

Hopefully other views should also be supported


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131139 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-09-07 00:51:32 +00:00
parent dff90a587e
commit 6abe8f4e94
8 changed files with 518 additions and 98 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ModificationHandler.java,v 1.2 2003/09/06 18:59:09 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ModificationHandler.java,v 1.3 2003/09/07 00:51:31 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -59,7 +59,6 @@ package org.apache.commons.collections.observed;
import java.util.Collection; import java.util.Collection;
/** /**
* Defines a handler for collection modification events. * Defines a handler for collection modification events.
* <p> * <p>
@ -73,7 +72,7 @@ import java.util.Collection;
* later collections release. * later collections release.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $ * @version $Revision: 1.3 $ $Date: 2003/09/07 00:51:31 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -84,6 +83,10 @@ public abstract class ModificationHandler {
/** The collection being observed */ /** The collection being observed */
private ObservedCollection collection = null; private ObservedCollection collection = null;
/** The root handler */
protected final ModificationHandler rootHandler;
/** The range offset, 0 if not a range */
protected final int rangeOffset;
// Constructors // Constructors
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -92,6 +95,20 @@ public abstract class ModificationHandler {
*/ */
protected ModificationHandler() { protected ModificationHandler() {
super(); super();
this.rootHandler = this;
this.rangeOffset = 0;
}
/**
* Constructor.
*
* @param rootHandler the base underlying handler
* @param rangeOffset the offset on the base collection
*/
protected ModificationHandler(ModificationHandler rootHandler, int rangeOffset) {
super();
this.rootHandler = rootHandler;
this.rangeOffset = rangeOffset;
} }
/** /**
@ -122,7 +139,7 @@ public abstract class ModificationHandler {
* *
* @return the observed collection * @return the observed collection
*/ */
public Collection getCollection() { public ObservedCollection getCollection() {
return collection; return collection;
} }
@ -234,8 +251,12 @@ public abstract class ModificationHandler {
* @param object the object that will be added/removed/set, 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 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 previous the previous value that will be removed/replaced, must exist in coll
* @param range the range collection, null if no range
* @param rangeOffset the offset of the range, -1 if unknown
*/ */
protected abstract boolean preEvent(int type, int index, Object object, int repeat, Object previous); protected abstract boolean preEvent(
int type, int index, Object object, int repeat,
Object previous, ObservedCollection range, int rangeOffset);
/** /**
* Handles the post event. * Handles the post event.
@ -246,81 +267,85 @@ public abstract class ModificationHandler {
* @param object the object that was added/removed/set, 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 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 previous the previous value that was removed/replace, must have existed in coll
* @param range the range collection, null if no range
* @param rangeOffset the offset of the range, -1 if unknown
*/ */
protected abstract void postEvent(boolean modified, int type, int index, Object object, int repeat, Object previous); protected abstract void postEvent(
boolean modified, int type, int index, Object object, int repeat,
Object previous, ObservedCollection range, int rangeOffset);
// Event handling // Event handling
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before add(obj) is called. * Store data and send event before add(obj) is called.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* It does not set the index for List implementations. * It does not set the index for List implementations.
* *
* @param object the object being added * @param object the object being added
* @return true to process modification * @return true to process modification
*/ */
protected boolean preAdd(Object object) { protected boolean preAdd(Object object) {
return preEvent(ModificationEventType.ADD, -1, object, 1, null); return preEvent(ModificationEventType.ADD, -1, object, 1, null, null, -1);
} }
/** /**
* Send an event after add(obj) is called. * Send an event after add(obj) is called.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* It does not set the index for List implementations. * It does not set the index for List implementations.
* *
* @param object the object being added * @param object the object being added
* @param result the result from the add method * @param result the result from the add method
*/ */
protected void postAdd(Object object, boolean result) { protected void postAdd(Object object, boolean result) {
postEvent(result, ModificationEventType.ADD, -1, object, 1, null); postEvent(result, ModificationEventType.ADD, -1, object, 1, null, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before add(int,obj) is called on a List. * Store data and send event before add(int,obj) is called on a List.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to add at * @param index the index to add at
* @param object the object being added * @param object the object being added
* @return true to process modification * @return true to process modification
*/ */
protected boolean preAddIndexed(int index, Object object) { protected boolean preAddIndexed(int index, Object object) {
return preEvent(ModificationEventType.ADD_INDEXED, index, object, 1, null); return preEvent(ModificationEventType.ADD_INDEXED, index + rangeOffset, object, 1, null, null, -1);
} }
/** /**
* Send an event after add(int,obj) is called on a List. * Send an event after add(int,obj) is called on a List.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to add at * @param index the index to add at
* @param object the object being added * @param object the object being added
*/ */
protected void postAddIndexed(int index, Object object) { protected void postAddIndexed(int index, Object object) {
postEvent(true, ModificationEventType.ADD_INDEXED, index, object, 1, null); postEvent(true, ModificationEventType.ADD_INDEXED, index + rangeOffset, object, 1, null, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before add(obj,int) is called on a Bag. * Store data and send event before add(obj,int) is called on a Bag.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param object the object being added * @param object the object being added
* @param nCopies the number of copies being added * @param nCopies the number of copies being added
* @return true to process modification * @return true to process modification
*/ */
protected boolean preAddNCopies(Object object, int nCopies) { protected boolean preAddNCopies(Object object, int nCopies) {
return preEvent(ModificationEventType.ADD_NCOPIES, -1, object, nCopies, null); return preEvent(ModificationEventType.ADD_NCOPIES, -1, object, nCopies, null, null, -1);
} }
/** /**
* Send an event after add(obj,int) is called on a Bag. * Send an event after add(obj,int) is called on a Bag.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* The method result is not used by this implementation (Bag violates the * The method result is not used by this implementation (Bag violates the
* Collection contract) * Collection contract)
* *
@ -329,86 +354,86 @@ public abstract class ModificationHandler {
* @param result the method result * @param result the method result
*/ */
protected void postAddNCopies(Object object, int nCopies, boolean result) { protected void postAddNCopies(Object object, int nCopies, boolean result) {
postEvent(true, ModificationEventType.ADD_NCOPIES, -1, object, nCopies, null); postEvent(true, ModificationEventType.ADD_NCOPIES, -1, object, nCopies, null, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before add(obj) is called on a ListIterator. * Store data and send event before add(obj) is called on a ListIterator.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param index the index of the iterator * @param index the index of the iterator
* @param object the object being added * @param object the object being added
* @return true to process modification * @return true to process modification
*/ */
protected boolean preAddIterated(int index, Object object) { protected boolean preAddIterated(int index, Object object) {
return preEvent(ModificationEventType.ADD_ITERATED, index, object, 1, null); return preEvent(ModificationEventType.ADD_ITERATED, index + rangeOffset, object, 1, null, null, -1);
} }
/** /**
* Send an event after add(obj) is called on a ListIterator. * Send an event after add(obj) is called on a ListIterator.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param index the index of the iterator * @param index the index of the iterator
* @param object the object being added * @param object the object being added
*/ */
protected void postAddIterated(int index, Object object) { protected void postAddIterated(int index, Object object) {
// assume collection changed // assume collection changed
postEvent(true, ModificationEventType.ADD_ITERATED, index, object, 1, null); postEvent(true, ModificationEventType.ADD_ITERATED, index + rangeOffset, object, 1, null, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before addAll(coll) is called. * Store data and send event before addAll(coll) is called.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param coll the collection being added * @param coll the collection being added
* @return true to process modification * @return true to process modification
*/ */
protected boolean preAddAll(Collection coll) { protected boolean preAddAll(Collection coll) {
return preEvent(ModificationEventType.ADD_ALL, -1, coll, 1, null); return preEvent(ModificationEventType.ADD_ALL, -1, coll, 1, null, null, -1);
} }
/** /**
* Send an event after addAll(coll) is called. * Send an event after addAll(coll) is called.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param coll the collection being added * @param coll the collection being added
* @param collChanged the result from the addAll method * @param collChanged the result from the addAll method
*/ */
protected void postAddAll(Collection coll, boolean collChanged) { protected void postAddAll(Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.ADD_ALL, -1, coll, 1, null); 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. * Store data and send event before addAll(int,coll) is called on a List.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to addAll at * @param index the index to addAll at
* @param coll the collection being added * @param coll the collection being added
* @return true to process modification * @return true to process modification
*/ */
protected boolean preAddAllIndexed(int index, Collection coll) { protected boolean preAddAllIndexed(int index, Collection coll) {
return preEvent(ModificationEventType.ADD_ALL_INDEXED, index, coll, 1, null); return preEvent(ModificationEventType.ADD_ALL_INDEXED, index + rangeOffset, coll, 1, null, null, -1);
} }
/** /**
* Send an event after addAll(int,coll) is called on a List. * Send an event after addAll(int,coll) is called on a List.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to addAll at * @param index the index to addAll at
* @param coll the collection being added * @param coll the collection being added
* @param collChanged the result from the addAll method * @param collChanged the result from the addAll method
*/ */
protected void postAddAllIndexed(int index, Collection coll, boolean collChanged) { protected void postAddAllIndexed(int index, Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.ADD_ALL_INDEXED, index, coll, 1, null); postEvent(collChanged, ModificationEventType.ADD_ALL_INDEXED, index + rangeOffset, coll, 1, null, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -420,7 +445,7 @@ public abstract class ModificationHandler {
* @return true to process modification * @return true to process modification
*/ */
protected boolean preClear() { protected boolean preClear() {
return preEvent(ModificationEventType.CLEAR, -1, null, 1, null); return preEvent(ModificationEventType.CLEAR, -1, null, 1, null, null, -1);
} }
/** /**
@ -430,39 +455,39 @@ public abstract class ModificationHandler {
*/ */
protected void postClear() { protected void postClear() {
// assumes a modification occurred // assumes a modification occurred
postEvent(true, ModificationEventType.CLEAR, -1, null, 1, null); postEvent(true, ModificationEventType.CLEAR, -1, null, 1, null, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before remove(obj) is called. * Store data and send event before remove(obj) is called.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param object the object being removed * @param object the object being removed
* @return true to process modification * @return true to process modification
*/ */
protected boolean preRemove(Object object) { protected boolean preRemove(Object object) {
return preEvent(ModificationEventType.REMOVE, -1, object, 1, null); return preEvent(ModificationEventType.REMOVE, -1, object, 1, null, null, -1);
} }
/** /**
* Send an event after remove(obj) is called. * Send an event after remove(obj) is called.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param object the object being removed * @param object the object being removed
* @param collChanged the result from the remove method * @param collChanged the result from the remove method
*/ */
protected void postRemove(Object object, boolean collChanged) { protected void postRemove(Object object, boolean collChanged) {
postEvent(collChanged, ModificationEventType.REMOVE, -1, object, 1, (collChanged ? object : null)); 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. * Store data and send event before remove(int) is called on a List.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to remove at * @param index the index to remove at
* @return true to process modification * @return true to process modification
@ -470,130 +495,130 @@ public abstract class ModificationHandler {
protected boolean preRemoveIndexed(int index) { protected boolean preRemoveIndexed(int index) {
// could do a get(index) to determine previousValue // could do a get(index) to determine previousValue
// we don't for performance, but subclass may override // we don't for performance, but subclass may override
return preEvent(ModificationEventType.REMOVE_INDEXED, index, null, 1, null); return preEvent(ModificationEventType.REMOVE_INDEXED, index + rangeOffset, null, 1, null, null, -1);
} }
/** /**
* Send an event after remove(int) is called on a List. * Send an event after remove(int) is called on a List.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to remove at * @param index the index to remove at
* @param previousValue the result from the remove method * @param previousValue the result from the remove method
*/ */
protected void postRemoveIndexed(int index, Object previousValue) { protected void postRemoveIndexed(int index, Object previousValue) {
postEvent(true, ModificationEventType.REMOVE_INDEXED, index, null, 1, previousValue); postEvent(true, ModificationEventType.REMOVE_INDEXED, index + rangeOffset, null, 1, previousValue, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before remove(obj,int) is called on a Bag. * Store data and send event before remove(obj,int) is called on a Bag.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param object the object being removed * @param object the object being removed
* @param nCopies the number of copies being removed * @param nCopies the number of copies being removed
* @return true to process modification * @return true to process modification
*/ */
protected boolean preRemoveNCopies(Object object, int nCopies) { protected boolean preRemoveNCopies(Object object, int nCopies) {
return preEvent(ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies, null); return preEvent(ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies, null, null, -1);
} }
/** /**
* Send an event after remove(obj,int) is called on a Bag. * Send an event after remove(obj,int) is called on a Bag.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param object the object being removed * @param object the object being removed
* @param nCopies the number of copies being removed * @param nCopies the number of copies being removed
* @param collChanged the result from the remove method * @param collChanged the result from the remove method
*/ */
protected void postRemoveNCopies(Object object, int nCopies, boolean collChanged) { protected void postRemoveNCopies(Object object, int nCopies, boolean collChanged) {
postEvent(collChanged, ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies, (collChanged ? object : null)); postEvent(collChanged, ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies, (collChanged ? object : null), null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before remove(obj) is called on an Iterator. * Store data and send event before remove(obj) is called on an Iterator.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param index the index of the iterator * @param index the index of the iterator
* @param removedValue the object being removed * @param removedValue the object being removed
* @return true to process modification * @return true to process modification
*/ */
protected boolean preRemoveIterated(int index, Object removedValue) { protected boolean preRemoveIterated(int index, Object removedValue) {
return preEvent(ModificationEventType.REMOVE_ITERATED, index, removedValue, 1, removedValue); return preEvent(ModificationEventType.REMOVE_ITERATED, index + rangeOffset, removedValue, 1, removedValue, null, -1);
} }
/** /**
* Send an event after remove(obj) is called on an Iterator. * Send an event after remove(obj) is called on an Iterator.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param index the index of the iterator * @param index the index of the iterator
* @param removedValue the previous value at this index * @param removedValue the previous value at this index
*/ */
protected void postRemoveIterated(int index, Object removedValue) { protected void postRemoveIterated(int index, Object removedValue) {
// assume collection changed // assume collection changed
postEvent(true, ModificationEventType.REMOVE_ITERATED, index, removedValue, 1, removedValue); postEvent(true, ModificationEventType.REMOVE_ITERATED, index + rangeOffset, removedValue, 1, removedValue, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before removeAll(coll) is called. * Store data and send event before removeAll(coll) is called.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param coll the collection being removed * @param coll the collection being removed
* @return true to process modification * @return true to process modification
*/ */
protected boolean preRemoveAll(Collection coll) { protected boolean preRemoveAll(Collection coll) {
return preEvent(ModificationEventType.REMOVE_ALL, -1, coll, 1, null); return preEvent(ModificationEventType.REMOVE_ALL, -1, coll, 1, null, null, -1);
} }
/** /**
* Send an event after removeAll(coll) is called. * Send an event after removeAll(coll) is called.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param coll the collection being removed * @param coll the collection being removed
* @param collChanged the result from the removeAll method * @param collChanged the result from the removeAll method
*/ */
protected void postRemoveAll(Collection coll, boolean collChanged) { protected void postRemoveAll(Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.REMOVE_ALL, -1, coll, 1, null); postEvent(collChanged, ModificationEventType.REMOVE_ALL, -1, coll, 1, null, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before retainAll(coll) is called. * Store data and send event before retainAll(coll) is called.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param coll the collection being retained * @param coll the collection being retained
* @return true to process modification * @return true to process modification
*/ */
protected boolean preRetainAll(Collection coll) { protected boolean preRetainAll(Collection coll) {
return preEvent(ModificationEventType.RETAIN_ALL, -1, coll, 1, null); return preEvent(ModificationEventType.RETAIN_ALL, -1, coll, 1, null, null, -1);
} }
/** /**
* Send an event after retainAll(coll) is called. * Send an event after retainAll(coll) is called.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param coll the collection being retained * @param coll the collection being retained
* @param collChanged the result from the retainAll method * @param collChanged the result from the retainAll method
*/ */
protected void postRetainAll(Collection coll, boolean collChanged) { protected void postRetainAll(Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.RETAIN_ALL, -1, coll, 1, null); 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. * Store data and send event before set(int,obj) is called on a List.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to add at * @param index the index to add at
* @param object the object being added * @param object the object being added
@ -602,13 +627,13 @@ public abstract class ModificationHandler {
protected boolean preSetIndexed(int index, Object object) { protected boolean preSetIndexed(int index, Object object) {
// could do a get(index) to determine previousValue // could do a get(index) to determine previousValue
// we don't for performance, but subclass may override // we don't for performance, but subclass may override
return preEvent(ModificationEventType.SET_INDEXED, index, object, 1, null); return preEvent(ModificationEventType.SET_INDEXED, index + rangeOffset, object, 1, null, null, -1);
} }
/** /**
* Send an event after set(int,obj) is called on a List. * Send an event after set(int,obj) is called on a List.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to add at * @param index the index to add at
* @param object the object being added * @param object the object being added
@ -616,14 +641,14 @@ public abstract class ModificationHandler {
*/ */
protected void postSetIndexed(int index, Object object, Object previousValue) { protected void postSetIndexed(int index, Object object, Object previousValue) {
// reference check for modification, in case equals() has issues (eg. performance) // reference check for modification, in case equals() has issues (eg. performance)
postEvent((object != previousValue), ModificationEventType.SET_INDEXED, index, object, 1, previousValue); postEvent((object != previousValue), ModificationEventType.SET_INDEXED, index + rangeOffset, object, 1, previousValue, null, -1);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Store data and send event before set(obj) is called on a ListIterator. * Store data and send event before set(obj) is called on a ListIterator.
* <p> * <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}. * This implementation forwards to {@link #preEvent(int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to set at * @param index the index to set at
* @param object the object being added * @param object the object being added
@ -631,13 +656,13 @@ public abstract class ModificationHandler {
* @return true to process modification * @return true to process modification
*/ */
protected boolean preSetIterated(int index, Object object, Object previousValue) { protected boolean preSetIterated(int index, Object object, Object previousValue) {
return preEvent(ModificationEventType.SET_ITERATED, index, object, 1, previousValue); return preEvent(ModificationEventType.SET_ITERATED, index + rangeOffset, object, 1, previousValue, null, -1);
} }
/** /**
* Send an event after set(obj) is called on a ListIterator. * Send an event after set(obj) is called on a ListIterator.
* <p> * <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}. * This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object, Object, int)}.
* *
* @param index the index to set at * @param index the index to set at
* @param object the object being added * @param object the object being added
@ -645,7 +670,60 @@ public abstract class ModificationHandler {
*/ */
protected void postSetIterated(int index, Object object, Object previousValue) { protected void postSetIterated(int index, Object object, Object previousValue) {
// reference check for modification, in case equals() has issues (eg. performance) // reference check for modification, in case equals() has issues (eg. performance)
postEvent((object != previousValue), ModificationEventType.SET_ITERATED, index, object, 1, previousValue); postEvent((object != previousValue), ModificationEventType.SET_ITERATED, index + rangeOffset, object, 1, previousValue, null, -1);
}
// Views
//-----------------------------------------------------------------------
/**
* 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 + rangeOffset);
}
protected class SubListHandler extends ModificationHandler {
/**
* Constructor.
*
* @param rootHandler the base underlying handler
* @param rangeOffset the offset on the base collection
*/
protected SubListHandler(ModificationHandler rootHandler, int rangeOffset) {
super(rootHandler, rangeOffset);
}
/**
* Override the preEvent method to forward all events to the
* underlying handler. This method also inserts details of the range
* that caused the event.
*/
protected boolean preEvent(
int type, int index, Object object, int repeat,
Object previous, ObservedCollection ignoredRange, int ignoredOffset) {
return rootHandler.preEvent(
type, index, object, repeat,
previous, getCollection(), this.rangeOffset);
}
/**
* Override the postEvent method to forward all events to the
* underlying handler. This method also inserts details of the range
* that caused the event.
*/
protected void postEvent(
boolean modified, int type, int index, Object object, int repeat,
Object previous, ObservedCollection ignoredRange, int ignoredOffset) {
rootHandler.postEvent(
modified, type, index, object, repeat,
previous, getCollection(), this.rangeOffset);
}
} }
// toString // toString

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedCollection.java,v 1.2 2003/09/06 18:59:09 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedCollection.java,v 1.3 2003/09/07 00:51:31 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -74,7 +74,7 @@ import org.apache.commons.collections.observed.standard.StandardModificationHand
* See this class for details of configuration available. * See this class for details of configuration available.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $ * @version $Revision: 1.3 $ $Date: 2003/09/07 00:51:31 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -196,6 +196,20 @@ public class ObservedCollection extends AbstractCollectionDecorator {
this.handler.init(this); this.handler.init(this);
} }
/**
* 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 ObservedCollection(
final ModificationHandler handler,
final Collection coll) {
super(coll);
this.handler = handler;
}
/** /**
* Creates a handler subclass based on the specified listener. * Creates a handler subclass based on the specified listener.
* <p> * <p>

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedList.java,v 1.2 2003/09/06 18:59:09 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedList.java,v 1.3 2003/09/07 00:51:31 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -58,6 +58,7 @@
package org.apache.commons.collections.observed; package org.apache.commons.collections.observed;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
@ -71,9 +72,12 @@ import org.apache.commons.collections.decorators.AbstractListIteratorDecorator;
* The handler manages the event, notifying listeners and optionally vetoing changes. * The handler manages the event, notifying listeners and optionally vetoing changes.
* The default handler is {@link StandardModificationHandler}. * The default handler is {@link StandardModificationHandler}.
* See this class for details of configuration available. * 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>.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $ * @version $Revision: 1.3 $ $Date: 2003/09/07 00:51:31 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -154,6 +158,19 @@ public class ObservedList extends ObservedCollection implements List {
super(list, 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 ObservedList(
final ModificationHandler handler,
final List list) {
super(handler, list);
}
/** /**
* Typecast the collection to a List. * Typecast the collection to a List.
* *
@ -220,9 +237,19 @@ public class ObservedList extends ObservedCollection implements List {
return new ObservedListIterator(getList().listIterator(index)); return new ObservedListIterator(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) { public List subList(int fromIndex, int toIndex) {
// TODO: This list needs to be a special impl, as the index is offset List subList = getList().subList(fromIndex, toIndex);
throw new UnsupportedOperationException(); return new ObservedList(subList, getHandler().createSubListHandler(fromIndex, toIndex));
} }
// ListIterator // ListIterator

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardModificationEvent.java,v 1.3 2003/09/06 18:59:09 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardModificationEvent.java,v 1.4 2003/09/07 00:51:31 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -67,6 +67,7 @@ import org.apache.commons.collections.Bag;
import org.apache.commons.collections.observed.ModificationEvent; import org.apache.commons.collections.observed.ModificationEvent;
import org.apache.commons.collections.observed.ModificationEventType; import org.apache.commons.collections.observed.ModificationEventType;
import org.apache.commons.collections.observed.ModificationHandler; import org.apache.commons.collections.observed.ModificationHandler;
import org.apache.commons.collections.observed.ObservedCollection;
/** /**
* Event class that encapsulates the event information for a * Event class that encapsulates the event information for a
@ -79,7 +80,7 @@ import org.apache.commons.collections.observed.ModificationHandler;
* All objects used are the real objects from the method calls, not clones. * All objects used are the real objects from the method calls, not clones.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/09/06 18:59:09 $ * @version $Revision: 1.4 $ $Date: 2003/09/07 00:51:31 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -95,6 +96,10 @@ public class StandardModificationEvent extends ModificationEvent {
protected final int repeat; protected final int repeat;
/** The result of the method call */ /** The result of the method call */
protected final Object previous; protected final Object previous;
/** The range that the event came from, null if none */
protected final ObservedCollection range;
/** The offset of the range that the event came from, -1 if none */
protected final int rangeOffset;
// Constructor // Constructor
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -109,6 +114,8 @@ public class StandardModificationEvent extends ModificationEvent {
* @param object the value that changed * @param object the value that changed
* @param repeat the number of repeats * @param repeat the number of repeats
* @param previous the previous value being removed/replaced * @param previous the previous value being removed/replaced
* @param range the range collection, null if no range
* @param rangeOffset the offset of the range, -1 if unknown
*/ */
public StandardModificationEvent( public StandardModificationEvent(
final Collection collection, final Collection collection,
@ -118,7 +125,9 @@ public class StandardModificationEvent extends ModificationEvent {
final int index, final int index,
final Object object, final Object object,
final int repeat, final int repeat,
final Object previous) { final Object previous,
final ObservedCollection range,
final int rangeOffset) {
super(collection, handler, type); super(collection, handler, type);
this.preSize = preSize; this.preSize = preSize;
@ -126,6 +135,8 @@ public class StandardModificationEvent extends ModificationEvent {
this.object = object; this.object = object;
this.repeat = repeat; this.repeat = repeat;
this.previous = previous; this.previous = previous;
this.range = range;
this.rangeOffset = rangeOffset;
} }
// Change info // Change info
@ -212,6 +223,35 @@ public class StandardModificationEvent extends ModificationEvent {
return preSize; return preSize;
} }
// Range info
//-----------------------------------------------------------------------
/**
* Gets the range, <code>null</code> if none.
*
* @return the range
*/
public ObservedCollection getRange() {
return range;
}
/**
* Checks whether the event originated from a range.
*
* @return the range
*/
public boolean isRange() {
return (range != null);
}
/**
* Gets the range offset, <code>-1</code> if no range or unknown offset.
*
* @return the range offset
*/
public int getRangeOffset() {
return rangeOffset;
}
// Event type // Event type
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardModificationHandler.java,v 1.2 2003/09/06 18:59:09 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardModificationHandler.java,v 1.3 2003/09/07 00:51:31 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -62,6 +62,7 @@ import java.util.Collection;
import org.apache.commons.collections.observed.ModificationEventType; import org.apache.commons.collections.observed.ModificationEventType;
import org.apache.commons.collections.observed.ModificationHandler; import org.apache.commons.collections.observed.ModificationHandler;
import org.apache.commons.collections.observed.ModificationHandlerFactory; import org.apache.commons.collections.observed.ModificationHandlerFactory;
import org.apache.commons.collections.observed.ObservedCollection;
/** /**
* The standard implementation of a <code>ModificationHandler</code> that * The standard implementation of a <code>ModificationHandler</code> that
@ -76,7 +77,7 @@ import org.apache.commons.collections.observed.ModificationHandlerFactory;
* modification events. * modification events.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $ * @version $Revision: 1.3 $ $Date: 2003/09/07 00:51:31 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -428,11 +429,16 @@ public class StandardModificationHandler extends ModificationHandler {
* @param object the object that will be added/removed/set, 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 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 previous the previous value that will be removed/replaced, must exist in coll
* @param range the range collection, null if no range
* @param rangeOffset the offset of the range, -1 if unknown
* @return true to call the decorated collection * @return true to call the decorated collection
*/ */
protected boolean preEvent(int type, int index, Object object, int repeat, Object previous) { protected boolean preEvent(
int type, int index, Object object,
int repeat, Object previous, ObservedCollection range, int rangeOffset) {
preSize = getCollection().size(); preSize = getCollection().size();
return firePreEvent(type, index, object, repeat, previous); return firePreEvent(type, index, object, repeat, previous, range, rangeOffset);
} }
/** /**
@ -443,9 +449,14 @@ public class StandardModificationHandler extends ModificationHandler {
* @param object the object that will be added/removed/set, 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 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 previous the previous value that will be removed/replaced, must exist in coll
* @param range the range collection, null if no range
* @param rangeOffset the offset of the range, -1 if unknown
* @return true to call the decorated collection * @return true to call the decorated collection
*/ */
protected boolean firePreEvent(int type, int index, Object object, int repeat, Object previous) { protected boolean firePreEvent(
int type, int index, Object object, int repeat,
Object previous, ObservedCollection range, int rangeOffset) {
if ((preMask & type) > 0) { if ((preMask & type) > 0) {
StandardPreModificationEvent event = null; StandardPreModificationEvent event = null;
synchronized (this) { synchronized (this) {
@ -454,7 +465,8 @@ public class StandardModificationHandler extends ModificationHandler {
if ((holder.mask & type) > 0) { if ((holder.mask & type) > 0) {
if (event == null) { if (event == null) {
event = new StandardPreModificationEvent( event = new StandardPreModificationEvent(
getCollection(), this, type, preSize, index, object, repeat, previous); getCollection(), this, type, preSize, index, object,
repeat, previous, range, rangeOffset);
} }
holder.listener.modificationOccurring(event); holder.listener.modificationOccurring(event);
} }
@ -469,16 +481,21 @@ public class StandardModificationHandler extends ModificationHandler {
/** /**
* Handles the post event. * Handles the post event.
* *
* @param success true if the method succeeded in changing the collection * @param modified true if the method succeeded in changing the collection
* @param type the event type to send * @param type the event type to send
* @param index the index where the change starts, the method param or derived * @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 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 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 previous the previous value that will be removed/replaced, must exist in coll
* @param range the range collection, null if no range
* @param rangeOffset the offset of the range, -1 if unknown
*/ */
protected void postEvent(boolean success, int type, int index, Object object, int repeat, Object previous) { protected void postEvent(
if (success) { boolean modified, int type, int index, Object object,
firePostEvent(type, index, object, repeat, previous); int repeat, Object previous, ObservedCollection range, int rangeOffset) {
if (modified) {
firePostEvent(type, index, object, repeat, previous, range, rangeOffset);
} }
} }
@ -490,8 +507,13 @@ public class StandardModificationHandler extends ModificationHandler {
* @param object the object that will be added/removed/set, 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 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 previous the previous value that will be removed/replaced, must exist in coll
* @param range the range collection, null if no range
* @param rangeOffset the offset of the range, -1 if unknown
*/ */
protected void firePostEvent(int type, int index, Object object, int repeat, Object previous) { protected void firePostEvent(
int type, int index, Object object, int repeat,
Object previous, ObservedCollection range, int rangeOffset) {
if ((postMask & type) > 0) { if ((postMask & type) > 0) {
StandardPostModificationEvent event = null; StandardPostModificationEvent event = null;
synchronized (this) { synchronized (this) {
@ -500,7 +522,8 @@ public class StandardModificationHandler extends ModificationHandler {
if ((holder.mask & type) > 0) { if ((holder.mask & type) > 0) {
if (event == null) { if (event == null) {
event = new StandardPostModificationEvent( event = new StandardPostModificationEvent(
getCollection(), this, type, preSize, index, object, repeat, previous); getCollection(), this, type, preSize, index,
object, repeat, previous, range, rangeOffset);
} }
holder.listener.modificationOccurred(event); holder.listener.modificationOccurred(event);
} }
@ -516,8 +539,8 @@ public class StandardModificationHandler extends ModificationHandler {
* <p> * <p>
* Override to only send event if something actually cleared. * Override to only send event if something actually cleared.
*/ */
public void postClear() { protected void postClear() {
postEvent(preSize > 0, ModificationEventType.CLEAR, -1, null, 1, null); postEvent(preSize > 0, ModificationEventType.CLEAR, -1, null, 1, null, null, -1);
} }
// Factory // Factory

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardPostModificationEvent.java,v 1.1 2003/09/06 18:59:09 scolebourne Exp $ * $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.2 2003/09/07 00:51:31 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -60,6 +60,7 @@ package org.apache.commons.collections.observed.standard;
import java.util.Collection; import java.util.Collection;
import org.apache.commons.collections.observed.ModificationHandler; import org.apache.commons.collections.observed.ModificationHandler;
import org.apache.commons.collections.observed.ObservedCollection;
/** /**
* Event class that encapsulates all the event information for a * Event class that encapsulates all the event information for a
@ -71,7 +72,7 @@ import org.apache.commons.collections.observed.ModificationHandler;
* All objects used are the real objects from the method calls, not clones. * All objects used are the real objects from the method calls, not clones.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/06 18:59:09 $ * @version $Revision: 1.2 $ $Date: 2003/09/07 00:51:31 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -93,6 +94,8 @@ public class StandardPostModificationEvent extends StandardModificationEvent {
* @param object the value that changed * @param object the value that changed
* @param repeat the number of repeats * @param repeat the number of repeats
* @param previous the previous value being removed/replaced * @param previous the previous value being removed/replaced
* @param range the range collection, null if no range
* @param rangeOffset the offset of the range, -1 if unknown
*/ */
public StandardPostModificationEvent( public StandardPostModificationEvent(
final Collection collection, final Collection collection,
@ -102,9 +105,11 @@ public class StandardPostModificationEvent extends StandardModificationEvent {
final int index, final int index,
final Object object, final Object object,
final int repeat, final int repeat,
final Object previous) { final Object previous,
final ObservedCollection range,
final int rangeOffset) {
super(collection, handler, type, preSize, index, object, repeat, previous); super(collection, handler, type, preSize, index, object, repeat, previous, range, rangeOffset);
postSize = collection.size(); postSize = collection.size();
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardPreModificationEvent.java,v 1.1 2003/09/06 18:59:09 scolebourne Exp $ * $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.2 2003/09/07 00:51:31 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -60,6 +60,7 @@ package org.apache.commons.collections.observed.standard;
import java.util.Collection; import java.util.Collection;
import org.apache.commons.collections.observed.ModificationHandler; import org.apache.commons.collections.observed.ModificationHandler;
import org.apache.commons.collections.observed.ObservedCollection;
/** /**
* Event class that encapsulates all the event information for a * Event class that encapsulates all the event information for a
@ -71,7 +72,7 @@ import org.apache.commons.collections.observed.ModificationHandler;
* All objects used are the real objects from the method calls, not clones. * All objects used are the real objects from the method calls, not clones.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/06 18:59:09 $ * @version $Revision: 1.2 $ $Date: 2003/09/07 00:51:31 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -99,9 +100,11 @@ public class StandardPreModificationEvent extends StandardModificationEvent {
final int index, final int index,
final Object object, final Object object,
final int repeat, final int repeat,
final Object previous) { final Object previous,
final ObservedCollection range,
final int rangeOffset) {
super(collection, handler, type, preSize, index, object, repeat, previous); super(collection, handler, type, preSize, index, object, repeat, previous, range, rangeOffset);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/ObservedTestHelper.java,v 1.3 2003/09/06 18:59:09 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/observed/Attic/ObservedTestHelper.java,v 1.4 2003/09/07 00:51:32 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -76,7 +76,7 @@ import org.apache.commons.collections.observed.standard.StandardPreModificationL
* {@link ObservedCollection} implementations. * {@link ObservedCollection} implementations.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/09/06 18:59:09 $ * @version $Revision: 1.4 $ $Date: 2003/09/07 00:51:32 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -176,6 +176,8 @@ public class ObservedTestHelper {
doTestSetIndexed(factory); doTestSetIndexed(factory);
doTestAddIterated(factory); doTestAddIterated(factory);
doTestSetIterated(factory); doTestSetIterated(factory);
doTestRemoveListIterated(factory);
doTestSubList(factory);
} }
public static void bulkTestObservedBag(ObservedFactory factory) { public static void bulkTestObservedBag(ObservedFactory factory) {
@ -192,6 +194,7 @@ public class ObservedTestHelper {
public static void doTestFactoryPlain(ObservedFactory factory) { public static void doTestFactoryPlain(ObservedFactory factory) {
ObservedCollection coll = factory.createObservedCollection(); ObservedCollection coll = factory.createObservedCollection();
Assert.assertNotNull(coll.getHandler());
Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass()); Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass());
Assert.assertEquals(0, coll.getHandler().getPreModificationListeners().length); Assert.assertEquals(0, coll.getHandler().getPreModificationListeners().length);
Assert.assertEquals(0, coll.getHandler().getPostModificationListeners().length); Assert.assertEquals(0, coll.getHandler().getPostModificationListeners().length);
@ -200,6 +203,7 @@ public class ObservedTestHelper {
public static void doTestFactoryWithPreListener(ObservedFactory factory) { public static void doTestFactoryWithPreListener(ObservedFactory factory) {
ObservedCollection coll = factory.createObservedCollection(PRE_LISTENER); ObservedCollection coll = factory.createObservedCollection(PRE_LISTENER);
Assert.assertNotNull(coll.getHandler());
Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass()); Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass());
Assert.assertEquals(1, coll.getHandler().getPreModificationListeners().length); Assert.assertEquals(1, coll.getHandler().getPreModificationListeners().length);
Assert.assertEquals(0, coll.getHandler().getPostModificationListeners().length); Assert.assertEquals(0, coll.getHandler().getPostModificationListeners().length);
@ -213,6 +217,7 @@ public class ObservedTestHelper {
public static void doTestFactoryWithPostListener(ObservedFactory factory) { public static void doTestFactoryWithPostListener(ObservedFactory factory) {
ObservedCollection coll = factory.createObservedCollection(POST_LISTENER); ObservedCollection coll = factory.createObservedCollection(POST_LISTENER);
Assert.assertNotNull(coll.getHandler());
Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass()); Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass());
Assert.assertEquals(0, coll.getHandler().getPreModificationListeners().length); Assert.assertEquals(0, coll.getHandler().getPreModificationListeners().length);
Assert.assertEquals(1, coll.getHandler().getPostModificationListeners().length); Assert.assertEquals(1, coll.getHandler().getPostModificationListeners().length);
@ -226,6 +231,7 @@ public class ObservedTestHelper {
public static void doTestFactoryWithListener(ObservedFactory factory) { public static void doTestFactoryWithListener(ObservedFactory factory) {
ObservedCollection coll = factory.createObservedCollection(LISTENER); ObservedCollection coll = factory.createObservedCollection(LISTENER);
Assert.assertNotNull(coll.getHandler());
Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass()); Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass());
Assert.assertEquals(1, coll.getHandler().getPreModificationListeners().length); Assert.assertEquals(1, coll.getHandler().getPreModificationListeners().length);
Assert.assertEquals(1, coll.getHandler().getPostModificationListeners().length); Assert.assertEquals(1, coll.getHandler().getPostModificationListeners().length);
@ -243,6 +249,7 @@ public class ObservedTestHelper {
StandardModificationHandler handler = new StandardModificationHandler(); StandardModificationHandler handler = new StandardModificationHandler();
ObservedCollection coll = factory.createObservedCollection(handler); ObservedCollection coll = factory.createObservedCollection(handler);
Assert.assertNotNull(coll.getHandler());
Assert.assertSame(handler, coll.getHandler()); Assert.assertSame(handler, coll.getHandler());
Assert.assertEquals(0, coll.getHandler().getPreModificationListeners().length); Assert.assertEquals(0, coll.getHandler().getPreModificationListeners().length);
Assert.assertEquals(0, coll.getHandler().getPostModificationListeners().length); Assert.assertEquals(0, coll.getHandler().getPostModificationListeners().length);
@ -258,6 +265,7 @@ public class ObservedTestHelper {
public static void doTestFactoryWithNull(ObservedFactory factory) { public static void doTestFactoryWithNull(ObservedFactory factory) {
ObservedCollection coll = factory.createObservedCollection(null); ObservedCollection coll = factory.createObservedCollection(null);
Assert.assertNotNull(coll.getHandler());
Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass()); Assert.assertEquals(StandardModificationHandler.class, coll.getHandler().getClass());
Assert.assertEquals(0, coll.getHandler().getPreModificationListeners().length); Assert.assertEquals(0, coll.getHandler().getPreModificationListeners().length);
Assert.assertEquals(0, coll.getHandler().getPostModificationListeners().length); Assert.assertEquals(0, coll.getHandler().getPostModificationListeners().length);
@ -361,6 +369,9 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -465,6 +476,9 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -507,6 +521,9 @@ public class ObservedTestHelper {
Assert.assertEquals(3, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(3, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -551,6 +568,9 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -590,6 +610,9 @@ public class ObservedTestHelper {
Assert.assertEquals(2, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -630,6 +653,9 @@ public class ObservedTestHelper {
Assert.assertEquals(2, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -670,6 +696,9 @@ public class ObservedTestHelper {
Assert.assertEquals(-2, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(-2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -720,6 +749,9 @@ public class ObservedTestHelper {
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -768,6 +800,9 @@ public class ObservedTestHelper {
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -811,6 +846,9 @@ public class ObservedTestHelper {
Assert.assertEquals(-3, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(-3, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -856,6 +894,64 @@ public class ObservedTestHelper {
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(1, coll.size());
coll.remove(SEVEN); // already removed
Assert.assertEquals(1, coll.size());
Assert.assertTrue(LISTENER.preEvent != null);
Assert.assertTrue(LISTENER.postEvent == null);
}
public static void doTestRemoveListIterated(ObservedFactory factory) {
ObservedList coll = (ObservedList) factory.createObservedCollection(LISTENER);
coll.addAll(SIX_SEVEN_LIST);
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(2, coll.size());
ListIterator it = coll.listIterator();
it.next();
it.next();
it.remove();
Assert.assertEquals(1, coll.size());
// pre
Assert.assertSame(coll, LISTENER.preEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE_ITERATED, LISTENER.preEvent.getType());
Assert.assertEquals(1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.preEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(SEVEN, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE_ITERATED, LISTENER.postEvent.getType());
Assert.assertEquals(1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(SEVEN, LISTENER.postEvent.getPrevious());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(1, LISTENER.postEvent.getPostSize());
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -905,6 +1001,9 @@ public class ObservedTestHelper {
Assert.assertEquals(-2, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(-2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -954,6 +1053,9 @@ public class ObservedTestHelper {
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@ -1004,6 +1106,9 @@ public class ObservedTestHelper {
Assert.assertEquals(0, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(0, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(false, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(true, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(true, LISTENER.postEvent.isTypeChange());
@ -1049,10 +1154,135 @@ public class ObservedTestHelper {
Assert.assertEquals(0, LISTENER.postEvent.getSizeChange()); Assert.assertEquals(0, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.postEvent.isSizeChanged()); Assert.assertEquals(false, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isRange());
Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
Assert.assertEquals(null, LISTENER.postEvent.getRange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd()); Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce()); Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(true, LISTENER.postEvent.isTypeChange()); Assert.assertEquals(true, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk()); Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk());
} }
//-----------------------------------------------------------------------
public static void doTestSubList(ObservedFactory factory) {
ObservedList coll = (ObservedList) factory.createObservedCollection(LISTENER);
coll.addAll(SIX_SEVEN_LIST);
coll.add(EIGHT);
coll.addAll(SIX_SEVEN_LIST);
List subList = coll.subList(1, 4);
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(3, subList.size());
subList.add(EIGHT);
Assert.assertEquals(4, subList.size());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.ADD, LISTENER.postEvent.getType());
Assert.assertEquals(-1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(5, LISTENER.postEvent.getPreSize());
Assert.assertEquals(6, LISTENER.postEvent.getPostSize());
Assert.assertEquals(true, LISTENER.postEvent.isRange());
Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
Assert.assertSame(subList, LISTENER.postEvent.getRange());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(4, subList.size());
subList.add(1, EIGHT);
Assert.assertEquals(5, subList.size());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.ADD_INDEXED, LISTENER.postEvent.getType());
Assert.assertEquals(2, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(6, LISTENER.postEvent.getPreSize());
Assert.assertEquals(7, LISTENER.postEvent.getPostSize());
Assert.assertEquals(true, LISTENER.postEvent.isRange());
Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
Assert.assertSame(subList, LISTENER.postEvent.getRange());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(5, subList.size());
subList.set(3, SEVEN);
Assert.assertEquals(5, subList.size());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.SET_INDEXED, LISTENER.postEvent.getType());
Assert.assertEquals(4, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SIX, LISTENER.postEvent.getPrevious());
Assert.assertEquals(7, LISTENER.postEvent.getPreSize());
Assert.assertEquals(7, LISTENER.postEvent.getPostSize());
Assert.assertEquals(true, LISTENER.postEvent.isRange());
Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
Assert.assertSame(subList, LISTENER.postEvent.getRange());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(5, subList.size());
ListIterator it = subList.listIterator();
it.next();
it.remove();
Assert.assertEquals(4, subList.size());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE_ITERATED, LISTENER.postEvent.getType());
Assert.assertEquals(1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SEVEN, LISTENER.postEvent.getPrevious());
Assert.assertEquals(7, LISTENER.postEvent.getPreSize());
Assert.assertEquals(6, LISTENER.postEvent.getPostSize());
Assert.assertEquals(true, LISTENER.postEvent.isRange());
Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
Assert.assertSame(subList, LISTENER.postEvent.getRange());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(4, subList.size());
it = subList.listIterator();
it.next();
it.next();
it.next();
it.set(EIGHT);
Assert.assertEquals(4, subList.size());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.SET_ITERATED, LISTENER.postEvent.getType());
Assert.assertEquals(3, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SEVEN, LISTENER.postEvent.getPrevious());
Assert.assertEquals(6, LISTENER.postEvent.getPreSize());
Assert.assertEquals(6, LISTENER.postEvent.getPostSize());
Assert.assertEquals(true, LISTENER.postEvent.isRange());
Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
Assert.assertSame(subList, LISTENER.postEvent.getRange());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(4, subList.size());
subList.clear();
Assert.assertEquals(0, subList.size());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.CLEAR, LISTENER.postEvent.getType());
Assert.assertEquals(-1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(null, LISTENER.postEvent.getChangeObject());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(6, LISTENER.postEvent.getPreSize());
Assert.assertEquals(2, LISTENER.postEvent.getPostSize());
Assert.assertEquals(true, LISTENER.postEvent.isRange());
Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
Assert.assertSame(subList, LISTENER.postEvent.getRange());
}
} }