Separated iterators to own events

Separate pre and post event classes
Clarify meaning of result event parameter
Fix tests that weren't working, and fixed problems revealed


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131137 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-09-06 18:59:09 +00:00
parent 8c3f191d5b
commit 9547b0caa6
12 changed files with 756 additions and 408 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/ModificationEventType.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ModificationEventType.java,v 1.2 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -74,7 +74,7 @@ package org.apache.commons.collections.observed;
* They may negated using the bitwise NOT, <code>~</code>.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -86,6 +86,8 @@ public class ModificationEventType {
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;
@ -98,6 +100,8 @@ public class ModificationEventType {
public static final int REMOVE_INDEXED =0x00000200;
/** The method remove(Object,int) */
public static final int REMOVE_NCOPIES =0x00000400;
/** The method iterator.remove() */
public static final int REMOVE_ITERATED=0x00000800;
/** The method removeAll(Collection) */
public static final int REMOVE_ALL = 0x00001000;
@ -108,33 +112,32 @@ public class ModificationEventType {
/** 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_ALL | ADD_ALL_INDEXED;
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;
public static final int GROUP_CHANGE = SET_INDEXED | SET_ITERATED;
/** All remove methods */
public static final int GROUP_REMOVE = REMOVE | REMOVE_NCOPIES | REMOVE_INDEXED | REMOVE_ALL;
public static final int GROUP_REMOVE = REMOVE | REMOVE_NCOPIES | REMOVE_ITERATED | REMOVE_INDEXED | 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 non indexed methods */
public static final int GROUP_NON_INDEXED = ADD | ADD_NCOPIES | ADD_ALL | REMOVE | REMOVE_NCOPIES | REMOVE_ALL | RETAIN_ALL | CLEAR;
/** All bulk methods (xxxAll, clear, Bag nCopies) */
public static final int GROUP_BULK = ADD_NCOPIES | ADD_ALL | ADD_ALL_INDEXED | REMOVE_NCOPIES | REMOVE_ALL | RETAIN_ALL | CLEAR;
/** All non bulk methods */
public static final int GROUP_NON_BULK = ADD | ADD_INDEXED | REMOVE | REMOVE_INDEXED | SET_INDEXED;
/** All 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 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 =
ADD | ADD_NCOPIES | ADD_INDEXED | ADD_ALL | ADD_ALL_INDEXED | REMOVE | REMOVE_NCOPIES | REMOVE_INDEXED | REMOVE_ALL | RETAIN_ALL | CLEAR;
/** All non structure modifying methods */
public static final int GROUP_NON_STRUCTURE_MODIFIED = SET_INDEXED;
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;
@ -171,6 +174,8 @@ public class ModificationEventType {
return "AddIndexed";
case ADD_NCOPIES:
return "AddNCopies";
case ADD_ITERATED:
return "AddIterated";
case ADD_ALL:
return "AddAll";
case ADD_ALL_INDEXED:
@ -181,6 +186,8 @@ public class ModificationEventType {
return "RemoveNCopies";
case REMOVE_INDEXED:
return "RemoveIndexed";
case REMOVE_ITERATED:
return "RemoveIterated";
case REMOVE_ALL:
return "RemoveAll";
case RETAIN_ALL:
@ -189,6 +196,8 @@ public class ModificationEventType {
return "Clear";
case SET_INDEXED:
return "SetIndexed";
case SET_ITERATED:
return "SetIterated";
default:
return "Unknown";
}

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.1 2003/09/03 23:54:26 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.2 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -73,7 +73,7 @@ import java.util.Collection;
* later collections release.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -230,73 +230,65 @@ public abstract class ModificationHandler {
* Handles the pre event.
*
* @param type the event type to send
* @param index the index where the change starts
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
* @param 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
*/
protected abstract boolean preEvent(int type, int index, Object object, int repeat);
protected abstract boolean preEvent(int type, int index, Object object, int repeat, Object previous);
/**
* Handles the post event where the collections method returns boolean for success.
* 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
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
* @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
*/
protected abstract void postEvent(boolean modified, int type, int index, Object object, int repeat);
/**
* Handles the post event where the collections method has a return value.
*
* @param modified true if the method succeeded in changing the collection
* @param type the event type to send
* @param index the index where the change starts
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
* @param result the result of the method
*/
protected abstract void postEvent(boolean modified, int type, int index, Object object, int repeat, Object result);
protected abstract void postEvent(boolean modified, int type, int index, Object object, int repeat, Object previous);
// Event handling
//-----------------------------------------------------------------------
/**
* Store data and send event before add(obj) is called.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
* 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);
return preEvent(ModificationEventType.ADD, -1, object, 1, null);
}
/**
* Send an event after add(obj) is called.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int)}.
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
* 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);
postEvent(result, ModificationEventType.ADD, -1, object, 1, null);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before add(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param index the index to add at
* @param object the object being added
* @return true to process modification
*/
protected boolean preAdd(int index, Object object) {
return preEvent(ModificationEventType.ADD_INDEXED, index, object, 1);
protected boolean preAddIndexed(int index, Object object) {
return preEvent(ModificationEventType.ADD_INDEXED, index, object, 1, null);
}
/**
@ -307,7 +299,7 @@ public abstract class ModificationHandler {
* @param index the index to add at
* @param object the object being added
*/
protected void postAdd(int index, Object object) {
protected void postAddIndexed(int index, Object object) {
postEvent(true, ModificationEventType.ADD_INDEXED, index, object, 1, null);
}
@ -315,78 +307,108 @@ public abstract class ModificationHandler {
/**
* Store data and send event before add(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param object the object being added
* @param nCopies the number of copies being added
* @return true to process modification
*/
protected boolean preAdd(Object object, int nCopies) {
return preEvent(ModificationEventType.ADD_NCOPIES, -1, object, nCopies);
protected boolean preAddNCopies(Object object, int nCopies) {
return preEvent(ModificationEventType.ADD_NCOPIES, -1, object, nCopies, null);
}
/**
* Send an event after add(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
* 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 postAdd(Object object, int nCopies, boolean result) {
postEvent(true, ModificationEventType.ADD_NCOPIES, -1, object, nCopies, (result ? Boolean.TRUE : Boolean.FALSE));
protected void postAddNCopies(Object object, int nCopies, boolean result) {
postEvent(true, ModificationEventType.ADD_NCOPIES, -1, object, nCopies, null);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before add(obj) is called on a ListIterator.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @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, object, 1, null);
}
/**
* Send an event after add(obj) is called on a ListIterator.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @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, object, 1, null);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before addAll(coll) is called.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param coll the collection being added
* @return true to process modification
*/
protected boolean preAddAll(Collection coll) {
return preEvent(ModificationEventType.ADD_ALL, -1, coll, 1);
return preEvent(ModificationEventType.ADD_ALL, -1, coll, 1, null);
}
/**
* Send an event after addAll(coll) is called.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int)}.
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param coll the collection being added
* @param result the result from the addAll method
* @param collChanged the result from the addAll method
*/
protected void postAddAll(Collection coll, boolean result) {
postEvent(result, ModificationEventType.ADD_ALL, -1, coll, 1);
protected void postAddAll(Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.ADD_ALL, -1, coll, 1, null);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before addAll(int,coll) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param index the index to addAll at
* @param coll the collection being added
* @return true to process modification
*/
protected boolean preAddAll(int index, Collection coll) {
return preEvent(ModificationEventType.ADD_ALL_INDEXED, index, coll, 1);
protected boolean preAddAllIndexed(int index, Collection coll) {
return preEvent(ModificationEventType.ADD_ALL_INDEXED, index, coll, 1, null);
}
/**
* Send an event after addAll(int,coll) is called on a List.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int)}.
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param index the index to addAll at
* @param coll the collection being added
* @param result the result from the addAll method
* @param collChanged the result from the addAll method
*/
protected void postAddAll(int index, Collection coll, boolean result) {
postEvent(result, ModificationEventType.ADD_ALL_INDEXED, index, coll, 1);
protected void postAddAllIndexed(int index, Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.ADD_ALL_INDEXED, index, coll, 1, null);
}
//-----------------------------------------------------------------------
@ -398,7 +420,7 @@ public abstract class ModificationHandler {
* @return true to process modification
*/
protected boolean preClear() {
return preEvent(ModificationEventType.CLEAR, -1, null, 1);
return preEvent(ModificationEventType.CLEAR, -1, null, 1, null);
}
/**
@ -415,38 +437,40 @@ public abstract class ModificationHandler {
/**
* Store data and send event before remove(obj) is called.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param object the object being removed
* @return true to process modification
*/
protected boolean preRemove(Object object) {
return preEvent(ModificationEventType.REMOVE, -1, object, 1);
return preEvent(ModificationEventType.REMOVE, -1, object, 1, null);
}
/**
* Send an event after remove(obj) is called.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int)}.
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param object the object being removed
* @param result the result from the remove method
* @param collChanged the result from the remove method
*/
protected void postRemove(Object object, boolean result) {
postEvent(result, ModificationEventType.REMOVE, -1, object, 1);
protected void postRemove(Object object, boolean collChanged) {
postEvent(collChanged, ModificationEventType.REMOVE, -1, object, 1, (collChanged ? object : null));
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove(int) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param index the index to remove at
* @return true to process modification
*/
protected boolean preRemove(int index) {
return preEvent(ModificationEventType.REMOVE_INDEXED, index, null, 1);
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, null, 1, null);
}
/**
@ -455,24 +479,24 @@ public abstract class ModificationHandler {
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param index the index to remove at
* @param result the result from the remove method
* @param previousValue the result from the remove method
*/
protected void postRemove(int index, Object result) {
postEvent(true, ModificationEventType.REMOVE_INDEXED, index, null, 1, result);
protected void postRemoveIndexed(int index, Object previousValue) {
postEvent(true, ModificationEventType.REMOVE_INDEXED, index, null, 1, previousValue);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove(obj,int) is called on a Bag.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param object the object being removed
* @param nCopies the number of copies being removed
* @return true to process modification
*/
protected boolean preRemove(Object object, int nCopies) {
return preEvent(ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies);
protected boolean preRemoveNCopies(Object object, int nCopies) {
return preEvent(ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies, null);
}
/**
@ -482,73 +506,103 @@ public abstract class ModificationHandler {
*
* @param object the object being removed
* @param nCopies the number of copies being removed
* @param collChanged the result from the remove method
*/
protected void postRemove(Object object, int nCopies, boolean result) {
postEvent(result, ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies);
protected void postRemoveNCopies(Object object, int nCopies, boolean collChanged) {
postEvent(collChanged, ModificationEventType.REMOVE_NCOPIES, -1, object, nCopies, (collChanged ? object : null));
}
//-----------------------------------------------------------------------
/**
* Store data and send event before remove(obj) is called on an Iterator.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @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, removedValue, 1, removedValue);
}
/**
* Send an event after remove(obj) is called on an Iterator.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @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, removedValue, 1, removedValue);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before removeAll(coll) is called.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param coll the collection being removed
* @return true to process modification
*/
protected boolean preRemoveAll(Collection coll) {
return preEvent(ModificationEventType.REMOVE_ALL, -1, coll, 1);
return preEvent(ModificationEventType.REMOVE_ALL, -1, coll, 1, null);
}
/**
* Send an event after removeAll(coll) is called.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int)}.
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param coll the collection being removed
* @param result the result from the removeAll method
* @param collChanged the result from the removeAll method
*/
protected void postRemoveAll(Collection coll, boolean result) {
postEvent(result, ModificationEventType.REMOVE_ALL, -1, coll, 1);
protected void postRemoveAll(Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.REMOVE_ALL, -1, coll, 1, null);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before retainAll(coll) is called.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param coll the collection being retained
* @return true to process modification
*/
protected boolean preRetainAll(Collection coll) {
return preEvent(ModificationEventType.RETAIN_ALL, -1, coll, 1);
return preEvent(ModificationEventType.RETAIN_ALL, -1, coll, 1, null);
}
/**
* Send an event after retainAll(coll) is called.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int)}.
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @param coll the collection being retained
* @param result the result from the retainAll method
* @param collChanged the result from the retainAll method
*/
protected void postRetainAll(Collection coll, boolean result) {
postEvent(result, ModificationEventType.RETAIN_ALL, -1, coll, 1);
protected void postRetainAll(Collection coll, boolean collChanged) {
postEvent(collChanged, ModificationEventType.RETAIN_ALL, -1, coll, 1, null);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before set(int,obj) is called on a List.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int)}.
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @param index the index to add at
* @param object the object being added
* @return true to process modification
*/
protected boolean preSet(int index, Object object) {
return preEvent(ModificationEventType.SET_INDEXED, index, object, 1);
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, object, 1, null);
}
/**
@ -558,11 +612,40 @@ public abstract class ModificationHandler {
*
* @param index the index to add at
* @param object the object being added
* @param result the result from the set method
* @param previousValue the result from the set method
*/
protected void postSet(int index, Object object, Object result) {
protected void postSetIndexed(int index, Object object, Object previousValue) {
// reference check for modification, in case equals() has issues (eg. performance)
postEvent((object != result), ModificationEventType.SET_INDEXED, index, object, 1, result);
postEvent((object != previousValue), ModificationEventType.SET_INDEXED, index, object, 1, previousValue);
}
//-----------------------------------------------------------------------
/**
* Store data and send event before set(obj) is called on a ListIterator.
* <p>
* This implementation forwards to {@link #preEvent(int, int, Object, int, Object)}.
*
* @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, object, 1, previousValue);
}
/**
* Send an event after set(obj) is called on a ListIterator.
* <p>
* This implementation forwards to {@link #postEvent(boolean, int, int, Object, int, Object)}.
*
* @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, object, 1, previousValue);
}
// 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/ObservedBag.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedBag.java,v 1.2 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -74,7 +74,7 @@ import org.apache.commons.collections.Bag;
* NOT observed. This is because the set should be unmodifiable.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -184,18 +184,18 @@ public class ObservedBag extends ObservedCollection implements Bag {
public boolean add(Object object, int nCopies) {
boolean result = false;
if (handler.preAdd(object, nCopies)) {
if (handler.preAddNCopies(object, nCopies)) {
result = getBag().add(object, nCopies);
handler.postAdd(object, nCopies, result);
handler.postAddNCopies(object, nCopies, result);
}
return result;
}
public boolean remove(Object object, int nCopies) {
boolean result = false;
if (handler.preRemove(object, nCopies)) {
if (handler.preRemoveNCopies(object, nCopies)) {
result = getBag().remove(object, nCopies);
handler.postRemove(object, nCopies, result);
handler.postRemoveNCopies(object, nCopies, result);
}
return result;
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/Attic/ObservedCollection.java,v 1.1 2003/09/03 23:54:26 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.2 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* 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.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -297,6 +297,7 @@ public class ObservedCollection extends AbstractCollectionDecorator {
*/
protected class ObservedIterator extends AbstractIteratorDecorator {
protected int lastIndex = -1;
protected Object last;
protected ObservedIterator(Iterator iterator) {
@ -305,13 +306,15 @@ public class ObservedCollection extends AbstractCollectionDecorator {
public Object next() {
last = super.next();
lastIndex++;
return last;
}
public void remove() {
if (handler.preRemove(last)) {
if (handler.preRemoveIterated(lastIndex, last)) {
iterator.remove();
handler.postRemove(last, true);
handler.postRemoveIterated(lastIndex, last);
lastIndex--;
}
}
}

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.1 2003/09/03 23:54:26 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.2 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -73,7 +73,7 @@ import org.apache.commons.collections.decorators.AbstractListIteratorDecorator;
* See this class for details of configuration available.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -179,35 +179,35 @@ public class ObservedList extends ObservedCollection implements List {
//-----------------------------------------------------------------------
public void add(int index, Object object) {
if (handler.preAdd(index, object)) {
if (handler.preAddIndexed(index, object)) {
getList().add(index, object);
handler.postAdd(index, object);
handler.postAddIndexed(index, object);
}
}
public boolean addAll(int index, Collection coll) {
boolean result = false;
if (handler.preAddAll(index, coll)) {
if (handler.preAddAllIndexed(index, coll)) {
result = getList().addAll(index, coll);
handler.postAddAll(index, coll, result);
handler.postAddAllIndexed(index, coll, result);
}
return result;
}
public Object remove(int index) {
Object result = null;
if (handler.preRemove(index)) {
if (handler.preRemoveIndexed(index)) {
result = getList().remove(index);
handler.postRemove(index, result);
handler.postRemoveIndexed(index, result);
}
return result;
}
public Object set(int index, Object object) {
Object result = null;
if (handler.preSet(index, object)) {
if (handler.preSetIndexed(index, object)) {
result = getList().set(index, object);
handler.postSet(index, object, result);
handler.postSetIndexed(index, object, result);
}
return result;
}
@ -250,25 +250,25 @@ public class ObservedList extends ObservedCollection implements List {
public void remove() {
int index = iterator.previousIndex();
if (handler.preRemove(index)) {
if (handler.preRemoveIterated(index, last)) {
iterator.remove();
handler.postRemove(index, last);
handler.postRemoveIterated(index, last);
}
}
public void add(Object object) {
int index = iterator.nextIndex();
if (handler.preAdd(index, object)) {
if (handler.preAddIterated(index, object)) {
iterator.add(object);
handler.postAdd(index, object);
handler.postAddIterated(index, object);
}
}
public void set(Object object) {
int index = iterator.previousIndex();
if (handler.preSet(index, object)) {
if (handler.preSetIterated(index, object, last)) {
iterator.set(object);
handler.postSet(index, object, last);
handler.postSetIterated(index, object, last);
}
}
}

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.2 2003/09/06 16:53:23 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.3 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -69,8 +69,9 @@ import org.apache.commons.collections.observed.ModificationEventType;
import org.apache.commons.collections.observed.ModificationHandler;
/**
* Event class that encapsulates all the event information for a
* standard collection event.
* 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.
@ -78,7 +79,7 @@ import org.apache.commons.collections.observed.ModificationHandler;
* All objects used are the real objects from the method calls, not clones.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/09/06 16:53:23 $
* @version $Revision: 1.3 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -86,8 +87,6 @@ public class StandardModificationEvent extends ModificationEvent {
/** The size before the event */
protected final int preSize;
/** The size after the event */
protected final int postSize;
/** The index of the change */
protected final int index;
/** The object of the change */
@ -95,7 +94,7 @@ public class StandardModificationEvent extends ModificationEvent {
/** The number of changes */
protected final int repeat;
/** The result of the method call */
protected final Object result;
protected final Object previous;
// Constructor
//-----------------------------------------------------------------------
@ -109,7 +108,7 @@ public class StandardModificationEvent extends ModificationEvent {
* @param index the index that changed
* @param object the value that changed
* @param repeat the number of repeats
* @param result the method result
* @param previous the previous value being removed/replaced
*/
public StandardModificationEvent(
final Collection collection,
@ -119,15 +118,14 @@ public class StandardModificationEvent extends ModificationEvent {
final int index,
final Object object,
final int repeat,
final Object result) {
final Object previous) {
super(collection, handler, type);
this.preSize = preSize;
this.postSize = collection.size();
this.index = index;
this.object = object;
this.repeat = repeat;
this.result = result;
this.previous = previous;
}
// Change info
@ -167,8 +165,6 @@ public class StandardModificationEvent extends ModificationEvent {
public Collection getChangeCollection() {
if (object == null) {
return Collections.EMPTY_LIST;
} else if (type == ModificationEventType.ADD_NCOPIES || type == ModificationEventType.REMOVE_NCOPIES) {
return Collections.singletonList(object);
} else if (isType(ModificationEventType.GROUP_BULK)) {
if (object instanceof Collection) {
return (Collection) object;
@ -194,19 +190,15 @@ public class StandardModificationEvent extends ModificationEvent {
}
/**
* Gets the result of the method call.
* Gets the previous value that is being replaced or removed.
* <p>
* For set(int) and remove(int) this will be the previous value
* being replaced.
* <p>
* If there is no result yet, <code>null</code> will be returned.
* If the result was a <code>boolean</code>, a <code>Boolean</code> is returned.
* If the result was void, <code>null</code> will be returned.
* This is only returned if the value definitely was previously in the
* collection. Bulk operatons will not return this.
*
* @return the repeat
* @return the previous value that was removed/replaced
*/
public Object getResult() {
return result;
public Object getPrevious() {
return previous;
}
// Size info
@ -220,46 +212,48 @@ public class StandardModificationEvent extends ModificationEvent {
return preSize;
}
/**
* Gets the size after the change.
* <p>
* This method will return the same as <code>getPreSzie</code> if
* called when handling a pre event.
*
* @return the size before the change
*/
public int getPostSize() {
return postSize;
}
/**
* Gets the size change, negative for remove/clear.
* <p>
* This method will return <code>zero</code> if called when handling a pre event.
*
* @return the size before the change
*/
public int getSizeChange() {
return postSize - preSize;
}
/**
* Returns true if the size of the collection changed.
* <p>
* This method will return <code>false</code> if called when handling a pre event.
*
* @return true is the size changed
*/
public boolean isSizeChanged() {
return (preSize != postSize);
}
// 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 ObservedEventType}.
* This is any combination of constants from {@link ModificationEventType}.
*
* @param eventType an event type constant
* @return true if of the specified 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.1 2003/09/03 23:54:26 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.2 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -76,7 +76,7 @@ import org.apache.commons.collections.observed.ModificationHandlerFactory;
* modification events.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -424,35 +424,37 @@ public class StandardModificationHandler extends ModificationHandler {
* Handles the pre event.
*
* @param type the event type to send
* @param index the index where the change starts
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
* @param 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
* @return true to call the decorated collection
*/
protected boolean preEvent(int type, int index, Object object, int repeat) {
protected boolean preEvent(int type, int index, Object object, int repeat, Object previous) {
preSize = getCollection().size();
return firePreEvent(type, index, object, repeat);
return firePreEvent(type, index, object, repeat, previous);
}
/**
* Sends the pre event to the listeners.
*
* @param type the event type to send
* @param index the index where the change starts
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
* @param 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
* @return true to call the decorated collection
*/
protected boolean firePreEvent(int type, int index, Object object, int repeat) {
protected boolean firePreEvent(int type, int index, Object object, int repeat, Object previous) {
if ((preMask & type) > 0) {
StandardModificationEvent event = null;
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 StandardModificationEvent(
getCollection(), this, type, preSize, index, object, repeat, null);
event = new StandardPreModificationEvent(
getCollection(), this, type, preSize, index, object, repeat, previous);
}
holder.listener.modificationOccurring(event);
}
@ -469,29 +471,14 @@ public class StandardModificationHandler extends ModificationHandler {
*
* @param success true if the method succeeded in changing the collection
* @param type the event type to send
* @param index the index where the change starts
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
* @param 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
*/
protected void postEvent(boolean success, int type, int index, Object object, int repeat) {
protected void postEvent(boolean success, int type, int index, Object object, int repeat, Object previous) {
if (success) {
firePostEvent(type, index, object, repeat, (success ? Boolean.TRUE : Boolean.FALSE));
}
}
/**
* Handles the post event.
*
* @param success true if the method succeeded in changing the collection
* @param type the event type to send
* @param index the index where the change starts
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
* @param result the method result
*/
protected void postEvent(boolean success, int type, int index, Object object, int repeat, Object result) {
if (success) {
firePostEvent(type, index, object, repeat, result);
firePostEvent(type, index, object, repeat, previous);
}
}
@ -499,21 +486,21 @@ public class StandardModificationHandler extends ModificationHandler {
* Sends the post event to the listeners.
*
* @param type the event type to send
* @param index the index where the change starts
* @param object the object that was added/removed
* @param repeat the number of repeats of the add/remove
* @param result the method result
* @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
*/
protected void firePostEvent(int type, int index, Object object, int repeat, Object result) {
protected void firePostEvent(int type, int index, Object object, int repeat, Object previous) {
if ((postMask & type) > 0) {
StandardModificationEvent event = null;
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 StandardModificationEvent(
getCollection(), this, type, preSize, index, object, repeat, result);
event = new StandardPostModificationEvent(
getCollection(), this, type, preSize, index, object, repeat, previous);
}
holder.listener.modificationOccurred(event);
}

View File

@ -0,0 +1,140 @@
/*
* $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 $
* ====================================================================
*
* 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.ModificationHandler;
/**
* 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.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
public class StandardPostModificationEvent extends StandardModificationEvent {
/** The size after the event */
protected final int postSize;
// Constructor
//-----------------------------------------------------------------------
/**
* Constructor.
*
* @param collection 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
*/
public StandardPostModificationEvent(
final Collection collection,
final ModificationHandler handler,
final int type,
final int preSize,
final int index,
final Object object,
final int repeat,
final Object previous) {
super(collection, handler, type, preSize, index, object, repeat, previous);
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,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/StandardPostModificationListener.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardPostModificationListener.java,v 1.2 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -64,7 +64,7 @@ import org.apache.commons.collections.observed.ModificationListener;
* when a collection has been changed.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -79,6 +79,6 @@ public interface StandardPostModificationListener extends ModificationListener {
*
* @param event the event detail
*/
public void modificationOccurred(StandardModificationEvent event);
public void modificationOccurred(StandardPostModificationEvent event);
}

View File

@ -0,0 +1,107 @@
/*
* $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 $
* ====================================================================
*
* 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.ModificationHandler;
/**
* 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.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
public class StandardPreModificationEvent extends StandardModificationEvent {
// Constructor
//-----------------------------------------------------------------------
/**
* Constructor.
*
* @param collection 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
*/
public StandardPreModificationEvent(
final Collection collection,
final ModificationHandler handler,
final int type,
final int preSize,
final int index,
final Object object,
final int repeat,
final Object previous) {
super(collection, handler, type, preSize, index, object, repeat, previous);
}
}

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/StandardPreModificationListener.java,v 1.1 2003/09/03 23:54:26 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/observed/standard/Attic/StandardPreModificationListener.java,v 1.2 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -64,7 +64,7 @@ import org.apache.commons.collections.observed.ModificationListener;
* when a collection is about to be modified.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/03 23:54:26 $
* @version $Revision: 1.2 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -81,6 +81,6 @@ public interface StandardPreModificationListener extends ModificationListener {
* @param event the event detail
* @throws ModicationVetoedException to veto
*/
public void modificationOccurring(StandardModificationEvent event);
public void modificationOccurring(StandardPreModificationEvent event);
}

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.2 2003/09/06 16:53:23 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.3 2003/09/06 18:59:09 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -64,10 +64,11 @@ import java.util.ListIterator;
import junit.framework.Assert;
import org.apache.commons.collections.observed.standard.StandardModificationEvent;
import org.apache.commons.collections.observed.standard.StandardModificationHandler;
import org.apache.commons.collections.observed.standard.StandardModificationListener;
import org.apache.commons.collections.observed.standard.StandardPostModificationEvent;
import org.apache.commons.collections.observed.standard.StandardPostModificationListener;
import org.apache.commons.collections.observed.standard.StandardPreModificationEvent;
import org.apache.commons.collections.observed.standard.StandardPreModificationListener;
/**
@ -75,7 +76,7 @@ import org.apache.commons.collections.observed.standard.StandardPreModificationL
* {@link ObservedCollection} implementations.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/09/06 16:53:23 $
* @version $Revision: 1.3 $ $Date: 2003/09/06 18:59:09 $
*
* @author Stephen Colebourne
*/
@ -91,30 +92,30 @@ public class ObservedTestHelper {
}
public static class Listener implements StandardModificationListener {
public StandardModificationEvent preEvent = null;
public StandardModificationEvent postEvent = null;
public StandardPreModificationEvent preEvent = null;
public StandardPostModificationEvent postEvent = null;
public void modificationOccurring(StandardModificationEvent event) {
public void modificationOccurring(StandardPreModificationEvent event) {
this.preEvent = event;
}
public void modificationOccurred(StandardModificationEvent event) {
public void modificationOccurred(StandardPostModificationEvent event) {
this.postEvent = event;
}
}
public static class PreListener implements StandardPreModificationListener {
public StandardModificationEvent preEvent = null;
public StandardPreModificationEvent preEvent = null;
public void modificationOccurring(StandardModificationEvent event) {
public void modificationOccurring(StandardPreModificationEvent event) {
this.preEvent = event;
}
}
public static class PostListener implements StandardPostModificationListener {
public StandardModificationEvent postEvent = null;
public StandardPostModificationEvent postEvent = null;
public void modificationOccurred(StandardModificationEvent event) {
public void modificationOccurred(StandardPostModificationEvent event) {
this.postEvent = event;
}
}
@ -152,7 +153,7 @@ public class ObservedTestHelper {
doTestRemove(factory);
doTestRemoveAll(factory);
doTestRetainAll(factory);
doTestIteratorRemove(factory);
doTestRemoveIterated(factory);
}
public static void bulkTestObservedSet(ObservedFactory factory) {
@ -173,8 +174,8 @@ public class ObservedTestHelper {
doTestAddAllIndexed(factory);
doTestRemoveIndexed(factory);
doTestSetIndexed(factory);
doTestIteratorAdd(factory);
doTestIteratorSet(factory);
doTestAddIterated(factory);
doTestSetIterated(factory);
}
public static void bulkTestObservedBag(ObservedFactory factory) {
@ -343,11 +344,8 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(SIX, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(0, LISTENER.preEvent.getPreSize());
Assert.assertEquals(0, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
@ -357,12 +355,17 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(SIX, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(0, LISTENER.postEvent.getPreSize());
Assert.assertEquals(1, LISTENER.postEvent.getPostSize());
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, 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());
@ -377,11 +380,8 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(1, LISTENER.preEvent.getPreSize());
Assert.assertEquals(1, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
@ -391,7 +391,7 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(1, LISTENER.postEvent.getPreSize());
Assert.assertEquals(2, LISTENER.postEvent.getPostSize());
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
@ -411,11 +411,8 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
@ -425,7 +422,7 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(3, LISTENER.postEvent.getPostSize());
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
@ -451,11 +448,8 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
@ -465,11 +459,16 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(3, LISTENER.postEvent.getPostSize());
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk());
}
//-----------------------------------------------------------------------
@ -491,11 +490,8 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(3, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
@ -505,15 +501,20 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(3, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(5, LISTENER.postEvent.getPostSize());
Assert.assertEquals(3, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk());
}
//-----------------------------------------------------------------------
public static void doTestIteratorAdd(ObservedFactory factory) {
public static void doTestAddIterated(ObservedFactory factory) {
ObservedList coll = (ObservedList) factory.createObservedCollection(LISTENER);
coll.addAll(SIX_SEVEN_LIST);
@ -527,31 +528,33 @@ public class ObservedTestHelper {
// pre
Assert.assertSame(coll, LISTENER.preEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.ADD_INDEXED, LISTENER.preEvent.getType());
Assert.assertEquals(ModificationEventType.ADD_ITERATED, LISTENER.preEvent.getType());
Assert.assertEquals(1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(EIGHT, LISTENER.preEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.ADD_INDEXED, LISTENER.postEvent.getType());
Assert.assertEquals(ModificationEventType.ADD_ITERATED, LISTENER.postEvent.getType());
Assert.assertEquals(1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(3, LISTENER.postEvent.getPostSize());
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk());
}
//-----------------------------------------------------------------------
@ -571,24 +574,26 @@ public class ObservedTestHelper {
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeCollection());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(0, LISTENER.preEvent.getPreSize());
Assert.assertEquals(0, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.ADD_ALL, LISTENER.postEvent.getType());
Assert.assertEquals(-1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeCollection());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeCollection());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(0, LISTENER.postEvent.getPreSize());
Assert.assertEquals(2, LISTENER.postEvent.getPostSize());
Assert.assertEquals(2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeBulk());
}
//-----------------------------------------------------------------------
@ -608,12 +613,9 @@ public class ObservedTestHelper {
Assert.assertEquals(1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeCollection());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
@ -622,11 +624,16 @@ public class ObservedTestHelper {
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeCollection());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(4, LISTENER.postEvent.getPostSize());
Assert.assertEquals(2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeBulk());
}
//-----------------------------------------------------------------------
@ -644,27 +651,29 @@ public class ObservedTestHelper {
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.CLEAR, LISTENER.preEvent.getType());
Assert.assertEquals(-1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(null, LISTENER.postEvent.getChangeObject());
Assert.assertSame(null, LISTENER.preEvent.getChangeObject());
Assert.assertEquals(0, LISTENER.preEvent.getChangeCollection().size());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// 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.assertEquals(0, LISTENER.preEvent.getChangeCollection().size());
Assert.assertEquals(0, LISTENER.postEvent.getChangeCollection().size());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(0, LISTENER.postEvent.getPostSize());
Assert.assertEquals(-2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeBulk());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
@ -690,29 +699,31 @@ public class ObservedTestHelper {
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE, LISTENER.preEvent.getType());
Assert.assertEquals(-1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeObject());
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(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE, LISTENER.postEvent.getType());
Assert.assertEquals(-1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
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.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;
@ -738,27 +749,29 @@ public class ObservedTestHelper {
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE_INDEXED, LISTENER.preEvent.getType());
Assert.assertEquals(0, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(null, LISTENER.postEvent.getChangeObject());
Assert.assertSame(null, LISTENER.preEvent.getChangeObject());
Assert.assertEquals(0, LISTENER.preEvent.getChangeCollection().size());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE_INDEXED, LISTENER.postEvent.getType());
Assert.assertEquals(0, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(null, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(0, LISTENER.preEvent.getChangeCollection().size());
Assert.assertEquals(0, LISTENER.postEvent.getChangeCollection().size());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(SIX, LISTENER.postEvent.getResult());
Assert.assertSame(SIX, 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.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk());
}
//-----------------------------------------------------------------------
@ -777,29 +790,84 @@ public class ObservedTestHelper {
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE_NCOPIES, LISTENER.preEvent.getType());
Assert.assertEquals(-1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SEVEN, LISTENER.preEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(3, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(SEVEN, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(3, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(13, LISTENER.preEvent.getPreSize());
Assert.assertEquals(13, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE_NCOPIES, LISTENER.postEvent.getType());
Assert.assertEquals(-1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(3, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertSame(SEVEN, LISTENER.postEvent.getPrevious());
Assert.assertEquals(13, LISTENER.postEvent.getPreSize());
Assert.assertEquals(10, LISTENER.postEvent.getPostSize());
Assert.assertEquals(-3, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk());
}
//-----------------------------------------------------------------------
public static void doTestRemoveIterated(ObservedFactory factory) {
ObservedCollection coll = factory.createObservedCollection(LISTENER);
coll.addAll(SIX_SEVEN_LIST);
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(2, coll.size());
Iterator it = coll.iterator();
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.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);
}
//-----------------------------------------------------------------------
@ -818,14 +886,11 @@ public class ObservedTestHelper {
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE_ALL, LISTENER.preEvent.getType());
Assert.assertEquals(-1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeCollection());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeCollection());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(3, LISTENER.preEvent.getPreSize());
Assert.assertEquals(3, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
@ -834,11 +899,16 @@ public class ObservedTestHelper {
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeCollection());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(3, LISTENER.postEvent.getPreSize());
Assert.assertEquals(1, LISTENER.postEvent.getPostSize());
Assert.assertEquals(-2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeBulk());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
@ -865,14 +935,11 @@ public class ObservedTestHelper {
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.RETAIN_ALL, LISTENER.preEvent.getType());
Assert.assertEquals(-1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeCollection());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeCollection());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(3, LISTENER.preEvent.getPreSize());
Assert.assertEquals(3, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
@ -881,11 +948,16 @@ public class ObservedTestHelper {
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeObject());
Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeCollection());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(3, LISTENER.postEvent.getPreSize());
Assert.assertEquals(2, LISTENER.postEvent.getPostSize());
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(true, LISTENER.postEvent.isTypeBulk());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
@ -896,57 +968,6 @@ public class ObservedTestHelper {
Assert.assertTrue(LISTENER.postEvent == null);
}
//-----------------------------------------------------------------------
public static void doTestIteratorRemove(ObservedFactory factory) {
ObservedCollection coll = factory.createObservedCollection(LISTENER);
coll.addAll(SIX_SEVEN_LIST);
LISTENER.preEvent = null;
LISTENER.postEvent = null;
Assert.assertEquals(2, coll.size());
Iterator it = coll.iterator();
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, LISTENER.preEvent.getType());
Assert.assertEquals(-1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.REMOVE, LISTENER.postEvent.getType());
Assert.assertEquals(-1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(SEVEN, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(SEVEN, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(Boolean.TRUE, LISTENER.postEvent.getResult());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(1, LISTENER.postEvent.getPostSize());
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
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 doTestSetIndexed(ObservedFactory factory) {
ObservedList coll = (ObservedList) factory.createObservedCollection(LISTENER);
@ -962,33 +983,35 @@ public class ObservedTestHelper {
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.SET_INDEXED, LISTENER.preEvent.getType());
Assert.assertEquals(0, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertSame(EIGHT, LISTENER.preEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertSame(EIGHT, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(null, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.SET_INDEXED, LISTENER.postEvent.getType());
Assert.assertEquals(0, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(SIX, LISTENER.postEvent.getResult());
Assert.assertSame(SIX, LISTENER.postEvent.getPrevious());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(2, LISTENER.postEvent.getPostSize());
Assert.assertEquals(0, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(true, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk());
}
//-----------------------------------------------------------------------
public static void doTestIteratorSet(ObservedFactory factory) {
public static void doTestSetIterated(ObservedFactory factory) {
ObservedList coll = (ObservedList) factory.createObservedCollection(LISTENER);
coll.addAll(SIX_SEVEN_LIST);
@ -1003,31 +1026,33 @@ public class ObservedTestHelper {
// pre
Assert.assertSame(coll, LISTENER.preEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
Assert.assertEquals(ModificationEventType.SET_INDEXED, LISTENER.preEvent.getType());
Assert.assertEquals(ModificationEventType.SET_ITERATED, LISTENER.preEvent.getType());
Assert.assertEquals(1, LISTENER.preEvent.getChangeIndex());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertSame(EIGHT, LISTENER.preEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertSame(EIGHT, LISTENER.preEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.preEvent.getChangeRepeat());
Assert.assertSame(null, LISTENER.preEvent.getResult());
Assert.assertSame(SEVEN, LISTENER.preEvent.getPrevious());
Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
Assert.assertEquals(2, LISTENER.preEvent.getPostSize());
Assert.assertEquals(0, LISTENER.preEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.preEvent.isSizeChanged());
// post
Assert.assertSame(coll, LISTENER.postEvent.getSourceCollection());
Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
Assert.assertEquals(ModificationEventType.SET_INDEXED, LISTENER.postEvent.getType());
Assert.assertEquals(ModificationEventType.SET_ITERATED, LISTENER.postEvent.getType());
Assert.assertEquals(1, LISTENER.postEvent.getChangeIndex());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(1, LISTENER.preEvent.getChangeCollection().size());
Assert.assertEquals(1, LISTENER.postEvent.getChangeCollection().size());
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeCollection().iterator().next());
Assert.assertEquals(1, LISTENER.postEvent.getChangeRepeat());
Assert.assertSame(SEVEN, LISTENER.postEvent.getResult());
Assert.assertSame(SEVEN, LISTENER.postEvent.getPrevious());
Assert.assertEquals(2, LISTENER.postEvent.getPreSize());
Assert.assertEquals(2, LISTENER.postEvent.getPostSize());
Assert.assertEquals(0, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.postEvent.isSizeChanged());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(true, LISTENER.postEvent.isTypeChange());
Assert.assertEquals(false, LISTENER.postEvent.isTypeBulk());
}
}