You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/09/21 22:01:53 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/observed ObservableSortedSet.java ModificationHandler.java
scolebourne 2003/09/21 13:01:53
Modified: collections/src/test/org/apache/commons/collections/observed
TestAll.java ObservedTestHelper.java
collections/src/java/org/apache/commons/collections/observed
ModificationHandler.java
Added: collections/src/test/org/apache/commons/collections/observed
TestObservableSet.java TestObservableSortedSet.java
TestObservableList.java TestObservableBuffer.java
TestObservableBag.java
TestObservableCollection.java
collections/src/java/org/apache/commons/collections/observed
ObservableSortedSet.java
Removed: collections/src/test/org/apache/commons/collections/observed
TestObservedBuffer.java TestObservedBag.java
TestObservedCollection.java TestObservedSet.java
TestObservedList.java
Log:
Add ObservableSortedSet
Rename range to view
Revision Changes Path
1.3 +8 -7 jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestAll.java
Index: TestAll.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestAll.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestAll.java 7 Sep 2003 16:50:59 -0000 1.2
+++ TestAll.java 21 Sep 2003 20:01:53 -0000 1.3
@@ -83,11 +83,12 @@
public static Test suite() {
TestSuite suite = new TestSuite();
- suite.addTest(TestObservedBag.suite());
- suite.addTest(TestObservedBuffer.suite());
- suite.addTest(TestObservedCollection.suite());
- suite.addTest(TestObservedList.suite());
- suite.addTest(TestObservedSet.suite());
+ suite.addTest(TestObservableBag.suite());
+ suite.addTest(TestObservableBuffer.suite());
+ suite.addTest(TestObservableCollection.suite());
+ suite.addTest(TestObservableList.suite());
+ suite.addTest(TestObservableSet.suite());
+ suite.addTest(TestObservableSortedSet.suite());
return suite;
}
1.9 +113 -101 jakarta-commons/collections/src/test/org/apache/commons/collections/observed/ObservedTestHelper.java
Index: ObservedTestHelper.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/observed/ObservedTestHelper.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ObservedTestHelper.java 21 Sep 2003 16:00:55 -0000 1.8
+++ ObservedTestHelper.java 21 Sep 2003 20:01:53 -0000 1.9
@@ -61,6 +61,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import java.util.SortedSet;
import junit.framework.Assert;
@@ -164,6 +165,15 @@
bulkTestObservedCollection(factory);
}
+ public static void bulkTestObservedSortedSet(ObservedFactory factory) {
+ Assert.assertTrue(factory.createObservedCollection() instanceof ObservableSortedSet);
+ Assert.assertTrue(factory.createObservedCollection(LISTENER) instanceof ObservableSortedSet);
+ Assert.assertTrue(factory.createObservedCollection(new StandardModificationHandler()) instanceof ObservableSortedSet);
+
+ bulkTestObservedCollection(factory);
+ // TODO: subSet...
+ }
+
public static void bulkTestObservedList(ObservedFactory factory) {
Assert.assertTrue(factory.createObservedCollection() instanceof ObservableList);
Assert.assertTrue(factory.createObservedCollection(LISTENER) instanceof ObservableList);
@@ -378,9 +388,9 @@
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -420,36 +430,38 @@
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- LISTENER.preEvent = null;
- LISTENER.postEvent = null;
- Assert.assertEquals(2, coll.size());
- coll.add(SIX_SEVEN_LIST);
- Assert.assertEquals(3, coll.size());
- // pre
- Assert.assertSame(coll, LISTENER.preEvent.getObservedCollection());
- Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
- Assert.assertEquals(ModificationEventType.ADD, LISTENER.preEvent.getType());
- Assert.assertEquals(-1, LISTENER.preEvent.getChangeIndex());
- Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeObject());
- 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.getPrevious());
- Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
- // post
- Assert.assertSame(coll, LISTENER.postEvent.getObservedCollection());
- Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
- Assert.assertEquals(ModificationEventType.ADD, LISTENER.postEvent.getType());
- Assert.assertEquals(-1, LISTENER.postEvent.getChangeIndex());
- Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeObject());
- 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(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());
+ if (coll instanceof SortedSet == false) {
+ LISTENER.preEvent = null;
+ LISTENER.postEvent = null;
+ Assert.assertEquals(2, coll.size());
+ coll.add(SIX_SEVEN_LIST);
+ Assert.assertEquals(3, coll.size());
+ // pre
+ Assert.assertSame(coll, LISTENER.preEvent.getObservedCollection());
+ Assert.assertSame(coll.getHandler(), LISTENER.preEvent.getHandler());
+ Assert.assertEquals(ModificationEventType.ADD, LISTENER.preEvent.getType());
+ Assert.assertEquals(-1, LISTENER.preEvent.getChangeIndex());
+ Assert.assertSame(SIX_SEVEN_LIST, LISTENER.preEvent.getChangeObject());
+ 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.getPrevious());
+ Assert.assertEquals(2, LISTENER.preEvent.getPreSize());
+ // post
+ Assert.assertSame(coll, LISTENER.postEvent.getObservedCollection());
+ Assert.assertSame(coll.getHandler(), LISTENER.postEvent.getHandler());
+ Assert.assertEquals(ModificationEventType.ADD, LISTENER.postEvent.getType());
+ Assert.assertEquals(-1, LISTENER.postEvent.getChangeIndex());
+ Assert.assertSame(SIX_SEVEN_LIST, LISTENER.postEvent.getChangeObject());
+ 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(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());
+ }
}
//-----------------------------------------------------------------------
@@ -488,9 +500,9 @@
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -533,9 +545,9 @@
Assert.assertEquals(3, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -580,9 +592,9 @@
Assert.assertEquals(1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -622,9 +634,9 @@
Assert.assertEquals(2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -665,9 +677,9 @@
Assert.assertEquals(2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(true, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -708,9 +720,9 @@
Assert.assertEquals(-2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -761,9 +773,9 @@
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -812,9 +824,9 @@
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -858,9 +870,9 @@
Assert.assertEquals(-3, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -903,9 +915,9 @@
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -951,9 +963,9 @@
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -1006,9 +1018,9 @@
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -1058,9 +1070,9 @@
Assert.assertEquals(-2, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -1110,9 +1122,9 @@
Assert.assertEquals(-1, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(true, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(true, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(false, LISTENER.postEvent.isTypeChange());
@@ -1163,9 +1175,9 @@
Assert.assertEquals(0, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(true, LISTENER.postEvent.isTypeChange());
@@ -1211,9 +1223,9 @@
Assert.assertEquals(0, LISTENER.postEvent.getSizeChange());
Assert.assertEquals(false, LISTENER.postEvent.isSizeChanged());
- Assert.assertEquals(false, LISTENER.postEvent.isRange());
- Assert.assertEquals(-1, LISTENER.postEvent.getRangeOffset());
- Assert.assertEquals(null, LISTENER.postEvent.getRange());
+ Assert.assertEquals(false, LISTENER.postEvent.isView());
+ Assert.assertEquals(-1, LISTENER.postEvent.getViewOffset());
+ Assert.assertEquals(null, LISTENER.postEvent.getView());
Assert.assertEquals(false, LISTENER.postEvent.isTypeAdd());
Assert.assertEquals(false, LISTENER.postEvent.isTypeReduce());
Assert.assertEquals(true, LISTENER.postEvent.isTypeChange());
@@ -1242,9 +1254,9 @@
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(5, LISTENER.postEvent.getPreSize());
Assert.assertEquals(6, LISTENER.postEvent.getPostSize());
- Assert.assertEquals(true, LISTENER.postEvent.isRange());
- Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
- Assert.assertSame(subList, LISTENER.postEvent.getRange());
+ Assert.assertEquals(true, LISTENER.postEvent.isView());
+ Assert.assertEquals(1, LISTENER.postEvent.getViewOffset());
+ Assert.assertSame(subList, LISTENER.postEvent.getView());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
@@ -1259,9 +1271,9 @@
Assert.assertSame(EIGHT, LISTENER.postEvent.getChangeObject());
Assert.assertEquals(6, LISTENER.postEvent.getPreSize());
Assert.assertEquals(7, LISTENER.postEvent.getPostSize());
- Assert.assertEquals(true, LISTENER.postEvent.isRange());
- Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
- Assert.assertSame(subList, LISTENER.postEvent.getRange());
+ Assert.assertEquals(true, LISTENER.postEvent.isView());
+ Assert.assertEquals(1, LISTENER.postEvent.getViewOffset());
+ Assert.assertSame(subList, LISTENER.postEvent.getView());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
@@ -1277,9 +1289,9 @@
Assert.assertSame(SIX, LISTENER.postEvent.getPrevious());
Assert.assertEquals(7, LISTENER.postEvent.getPreSize());
Assert.assertEquals(7, LISTENER.postEvent.getPostSize());
- Assert.assertEquals(true, LISTENER.postEvent.isRange());
- Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
- Assert.assertSame(subList, LISTENER.postEvent.getRange());
+ Assert.assertEquals(true, LISTENER.postEvent.isView());
+ Assert.assertEquals(1, LISTENER.postEvent.getViewOffset());
+ Assert.assertSame(subList, LISTENER.postEvent.getView());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
@@ -1297,9 +1309,9 @@
Assert.assertSame(SEVEN, LISTENER.postEvent.getPrevious());
Assert.assertEquals(7, LISTENER.postEvent.getPreSize());
Assert.assertEquals(6, LISTENER.postEvent.getPostSize());
- Assert.assertEquals(true, LISTENER.postEvent.isRange());
- Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
- Assert.assertSame(subList, LISTENER.postEvent.getRange());
+ Assert.assertEquals(true, LISTENER.postEvent.isView());
+ Assert.assertEquals(1, LISTENER.postEvent.getViewOffset());
+ Assert.assertSame(subList, LISTENER.postEvent.getView());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
@@ -1319,9 +1331,9 @@
Assert.assertSame(SEVEN, LISTENER.postEvent.getPrevious());
Assert.assertEquals(6, LISTENER.postEvent.getPreSize());
Assert.assertEquals(6, LISTENER.postEvent.getPostSize());
- Assert.assertEquals(true, LISTENER.postEvent.isRange());
- Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
- Assert.assertSame(subList, LISTENER.postEvent.getRange());
+ Assert.assertEquals(true, LISTENER.postEvent.isView());
+ Assert.assertEquals(1, LISTENER.postEvent.getViewOffset());
+ Assert.assertSame(subList, LISTENER.postEvent.getView());
LISTENER.preEvent = null;
LISTENER.postEvent = null;
@@ -1337,9 +1349,9 @@
Assert.assertSame(null, LISTENER.postEvent.getPrevious());
Assert.assertEquals(6, LISTENER.postEvent.getPreSize());
Assert.assertEquals(2, LISTENER.postEvent.getPostSize());
- Assert.assertEquals(true, LISTENER.postEvent.isRange());
- Assert.assertEquals(1, LISTENER.postEvent.getRangeOffset());
- Assert.assertSame(subList, LISTENER.postEvent.getRange());
+ Assert.assertEquals(true, LISTENER.postEvent.isView());
+ Assert.assertEquals(1, LISTENER.postEvent.getViewOffset());
+ Assert.assertSame(subList, LISTENER.postEvent.getView());
}
}
1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableSet.java
Index: TestObservableSet.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableSet.java,v 1.1 2003/09/21 20:01:53 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.observed;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.TestSet;
/**
* Extension of {@link TestSet} for exercising the
* {@link ObservedSet} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/21 20:01:53 $
*
* @author Stephen Colebourne
*/
public class TestObservableSet extends TestSet implements ObservedTestHelper.ObservedFactory {
public TestObservableSet(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableSet.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableSet.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Set makeEmptySet() {
return ObservableSet.decorate(new HashSet(), ObservedTestHelper.LISTENER);
}
protected Set makeFullSet() {
Set set = new HashSet();
set.addAll(Arrays.asList(getFullElements()));
return ObservableSet.decorate(set, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedSet() {
ObservedTestHelper.bulkTestObservedSet(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableSet.decorate(new HashSet());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableSet.decorate(new HashSet(), listener);
}
}
1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableSortedSet.java
Index: TestObservableSortedSet.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableSortedSet.java,v 1.1 2003/09/21 20:01:53 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.observed;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.TestSortedSet;
/**
* Extension of {@link TestSet} for exercising the
* {@link ObservedSet} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/21 20:01:53 $
*
* @author Stephen Colebourne
*/
public class TestObservableSortedSet extends TestSortedSet implements ObservedTestHelper.ObservedFactory {
public TestObservableSortedSet(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableSortedSet.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableSortedSet.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Set makeEmptySet() {
return ObservableSortedSet.decorate(new TreeSet(), ObservedTestHelper.LISTENER);
}
protected Set makeFullSet() {
Set set = new TreeSet();
set.addAll(Arrays.asList(getFullElements()));
return ObservableSortedSet.decorate(set, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedSortedSet() {
ObservedTestHelper.bulkTestObservedSortedSet(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableSortedSet.decorate(new TreeSet());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableSortedSet.decorate(new TreeSet(), listener);
}
}
1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableList.java
Index: TestObservableList.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableList.java,v 1.1 2003/09/21 20:01:53 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.observed;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.TestList;
/**
* Extension of {@link TestList} for exercising the
* {@link ObservedList} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/21 20:01:53 $
*
* @author Stephen Colebourne
*/
public class TestObservableList extends TestList implements ObservedTestHelper.ObservedFactory {
public TestObservableList(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableList.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableList.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public List makeEmptyList() {
return ObservableList.decorate(new ArrayList(), ObservedTestHelper.LISTENER);
}
protected List makeFullList() {
List set = new ArrayList();
set.addAll(Arrays.asList(getFullElements()));
return ObservableList.decorate(set, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedList() {
ObservedTestHelper.bulkTestObservedList(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableList.decorate(new ArrayList());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableList.decorate(new ArrayList(), listener);
}
}
1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableBuffer.java
Index: TestObservableBuffer.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableBuffer.java,v 1.1 2003/09/21 20:01:53 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.observed;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.ArrayStack;
import org.apache.commons.collections.TestCollection;
/**
* Extension of {@link TestCollection} for exercising the
* {@link ObservableBuffer} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/21 20:01:53 $
*
* @author Stephen Colebourne
*/
public class TestObservableBuffer extends TestCollection implements ObservedTestHelper.ObservedFactory {
public TestObservableBuffer(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableBuffer.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableBuffer.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Collection makeConfirmedCollection() {
return new ArrayStack();
}
protected Collection makeConfirmedFullCollection() {
ArrayStack stack = new ArrayStack();
stack.addAll(Arrays.asList(getFullElements()));
return stack;
}
public Collection makeCollection() {
return ObservableBuffer.decorate(new ArrayStack(), ObservedTestHelper.LISTENER);
}
protected Collection makeFullCollection() {
List stack = new ArrayStack();
stack.addAll(Arrays.asList(getFullElements()));
return ObservableBuffer.decorate(stack, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedBuffer() {
ObservedTestHelper.bulkTestObservedBuffer(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableBuffer.decorate(new ArrayStack());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableBuffer.decorate(new ArrayStack(), listener);
}
}
1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableBag.java
Index: TestObservableBag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableBag.java,v 1.1 2003/09/21 20:01:53 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.observed;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.Bag;
import org.apache.commons.collections.HashBag;
import org.apache.commons.collections.TestBag;
/**
* Extension of {@link TestBag} for exercising the
* {@link ObservableBag} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/21 20:01:53 $
*
* @author Stephen Colebourne
*/
public class TestObservableBag extends TestBag implements ObservedTestHelper.ObservedFactory {
public TestObservableBag(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableBag.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableBag.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Bag makeBag() {
return ObservableBag.decorate(new HashBag(), ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedSet() {
ObservedTestHelper.bulkTestObservedBag(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableBag.decorate(new HashBag());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableBag.decorate(new HashBag(), listener);
}
}
1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableCollection.java
Index: TestObservableCollection.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/observed/TestObservableCollection.java,v 1.1 2003/09/21 20:01:53 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.observed;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.TestCollection;
/**
* Extension of {@link TestCollection} for exercising the
* {@link ObservedCollection} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/21 20:01:53 $
*
* @author Stephen Colebourne
*/
public class TestObservableCollection extends TestCollection implements ObservedTestHelper.ObservedFactory {
public TestObservableCollection(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestObservableCollection.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestObservableCollection.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Collection makeConfirmedCollection() {
return new ArrayList();
}
protected Collection makeConfirmedFullCollection() {
List list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
public Collection makeCollection() {
return ObservableCollection.decorate(new ArrayList(), ObservedTestHelper.LISTENER);
}
protected Collection makeFullCollection() {
List list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return ObservableCollection.decorate(list, ObservedTestHelper.LISTENER);
}
//-----------------------------------------------------------------------
public void testObservedCollection() {
ObservedTestHelper.bulkTestObservedCollection(this);
}
//-----------------------------------------------------------------------
public ObservableCollection createObservedCollection() {
return ObservableCollection.decorate(new ArrayList());
}
public ObservableCollection createObservedCollection(Object listener) {
return ObservableCollection.decorate(new ArrayList(), listener);
}
// public void testFactoryWithMasks() {
// ObservedCollection coll = ObservedCollection.decorate(new ArrayList(), LISTENER, -1, 0);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent != null);
// assertTrue(LISTENER.postEvent == null);
//
// coll = ObservedCollection.decorate(new ArrayList(), LISTENER, 0, -1);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent == null);
// assertTrue(LISTENER.postEvent != null);
//
// coll = ObservedCollection.decorate(new ArrayList(), LISTENER, -1, -1);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent != null);
// assertTrue(LISTENER.postEvent != null);
//
// coll = ObservedCollection.decorate(new ArrayList(), LISTENER, 0, 0);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent == null);
// assertTrue(LISTENER.postEvent == null);
//
// coll = ObservedCollection.decorate(new ArrayList(), LISTENER, ModificationEventType.ADD, ModificationEventType.ADD_ALL);
// LISTENER.preEvent = null;
// LISTENER.postEvent = null;
// coll.add(SIX);
// assertTrue(LISTENER.preEvent != null);
// assertTrue(LISTENER.postEvent == null);
// }
//
}
1.7 +120 -44 jakarta-commons/collections/src/java/org/apache/commons/collections/observed/ModificationHandler.java
Index: ModificationHandler.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/observed/ModificationHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ModificationHandler.java 21 Sep 2003 16:00:28 -0000 1.6
+++ ModificationHandler.java 21 Sep 2003 20:01:53 -0000 1.7
@@ -91,8 +91,8 @@
private Collection baseCollection = null;
/** The root handler */
private final ModificationHandler rootHandler;
- /** The range offset, 0 if not a range */
- private final int rangeOffset;
+ /** The view offset, 0 if not a view */
+ private final int viewOffset;
// Constructors
//-----------------------------------------------------------------------
@@ -102,19 +102,19 @@
protected ModificationHandler() {
super();
this.rootHandler = this;
- this.rangeOffset = 0;
+ this.viewOffset = 0;
}
/**
* Constructor.
*
* @param rootHandler the base underlying handler
- * @param rangeOffset the offset on the base collection
+ * @param viewOffset the offset on the base collection
*/
- protected ModificationHandler(ModificationHandler rootHandler, int rangeOffset) {
+ protected ModificationHandler(ModificationHandler rootHandler, int viewOffset) {
super();
this.rootHandler = rootHandler;
- this.rangeOffset = rangeOffset;
+ this.viewOffset = viewOffset;
}
/**
@@ -173,12 +173,12 @@
}
/**
- * Gets the range offset.
+ * Gets the view offset.
*
- * @return the range offset
+ * @return the view offset
*/
- protected int getRangeOffset() {
- return rangeOffset;
+ protected int getViewOffset() {
+ return viewOffset;
}
// PreListeners
@@ -291,12 +291,12 @@
* @param object the object that will be added/removed/set, the method param or derived
* @param repeat the number of repeats of the add/remove, the method param or derived
* @param previous the previous value that will be removed/replaced, must exist in coll
- * @param range the range collection, null if no range
- * @param rangeOffset the offset of the range, -1 if unknown
+ * @param view the view collection that the change was actioned on, null if no view
+ * @param viewOffset the offset of the subList view, -1 if unknown
*/
protected boolean preEvent(
int type, int index, Object object, int repeat,
- Object previous, ObservableCollection range, int rangeOffset) {
+ Object previous, ObservableCollection view, int viewOffset) {
return true;
}
@@ -311,12 +311,12 @@
* @param object the object that was added/removed/set, the method param or derived
* @param repeat the number of repeats of the add/remove, the method param or derived
* @param previous the previous value that was removed/replace, must have existed in coll
- * @param range the range collection, null if no range
- * @param rangeOffset the offset of the range, -1 if unknown
+ * @param view the view collection that the change was actioned on, null if no view
+ * @param viewOffset the offset of the subList view, -1 if unknown
*/
protected void postEvent(
boolean modified, int type, int index, Object object, int repeat,
- Object previous, ObservableCollection range, int rangeOffset) {
+ Object previous, ObservableCollection view, int viewOffset) {
}
// Event handling
@@ -358,7 +358,7 @@
* @return true to process modification
*/
protected boolean preAddIndexed(int index, Object object) {
- return preEvent(ModificationEventType.ADD_INDEXED, index + rangeOffset, object, 1, null, null, -1);
+ return preEvent(ModificationEventType.ADD_INDEXED, index + viewOffset, object, 1, null, null, -1);
}
/**
@@ -370,7 +370,7 @@
* @param object the object being added
*/
protected void postAddIndexed(int index, Object object) {
- postEvent(true, ModificationEventType.ADD_INDEXED, index + rangeOffset, object, 1, null, null, -1);
+ postEvent(true, ModificationEventType.ADD_INDEXED, index + viewOffset, object, 1, null, null, -1);
}
//-----------------------------------------------------------------------
@@ -413,7 +413,7 @@
* @return true to process modification
*/
protected boolean preAddIterated(int index, Object object) {
- return preEvent(ModificationEventType.ADD_ITERATED, index + rangeOffset, object, 1, null, null, -1);
+ return preEvent(ModificationEventType.ADD_ITERATED, index + viewOffset, object, 1, null, null, -1);
}
/**
@@ -426,7 +426,7 @@
*/
protected void postAddIterated(int index, Object object) {
// assume collection changed
- postEvent(true, ModificationEventType.ADD_ITERATED, index + rangeOffset, object, 1, null, null, -1);
+ postEvent(true, ModificationEventType.ADD_ITERATED, index + viewOffset, object, 1, null, null, -1);
}
//-----------------------------------------------------------------------
@@ -465,7 +465,7 @@
* @return true to process modification
*/
protected boolean preAddAllIndexed(int index, Collection coll) {
- return preEvent(ModificationEventType.ADD_ALL_INDEXED, index + rangeOffset, coll, 1, null, null, -1);
+ return preEvent(ModificationEventType.ADD_ALL_INDEXED, index + viewOffset, coll, 1, null, null, -1);
}
/**
@@ -478,7 +478,7 @@
* @param collChanged the result from the addAll method
*/
protected void postAddAllIndexed(int index, Collection coll, boolean collChanged) {
- postEvent(collChanged, ModificationEventType.ADD_ALL_INDEXED, index + rangeOffset, coll, 1, null, null, -1);
+ postEvent(collChanged, ModificationEventType.ADD_ALL_INDEXED, index + viewOffset, coll, 1, null, null, -1);
}
//-----------------------------------------------------------------------
@@ -540,7 +540,7 @@
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 + rangeOffset, null, 1, null, null, -1);
+ return preEvent(ModificationEventType.REMOVE_INDEXED, index + viewOffset, null, 1, null, null, -1);
}
/**
@@ -552,7 +552,7 @@
* @param previousValue the result from the remove method
*/
protected void postRemoveIndexed(int index, Object previousValue) {
- postEvent(true, ModificationEventType.REMOVE_INDEXED, index + rangeOffset, null, 1, previousValue, null, -1);
+ postEvent(true, ModificationEventType.REMOVE_INDEXED, index + viewOffset, null, 1, previousValue, null, -1);
}
//-----------------------------------------------------------------------
@@ -617,7 +617,7 @@
* @return true to process modification
*/
protected boolean preRemoveIterated(int index, Object removedValue) {
- return preEvent(ModificationEventType.REMOVE_ITERATED, index + rangeOffset, removedValue, 1, removedValue, null, -1);
+ return preEvent(ModificationEventType.REMOVE_ITERATED, index + viewOffset, removedValue, 1, removedValue, null, -1);
}
/**
@@ -630,7 +630,7 @@
*/
protected void postRemoveIterated(int index, Object removedValue) {
// assume collection changed
- postEvent(true, ModificationEventType.REMOVE_ITERATED, index + rangeOffset, removedValue, 1, removedValue, null, -1);
+ postEvent(true, ModificationEventType.REMOVE_ITERATED, index + viewOffset, removedValue, 1, removedValue, null, -1);
}
//-----------------------------------------------------------------------
@@ -696,7 +696,7 @@
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 + rangeOffset, object, 1, null, null, -1);
+ return preEvent(ModificationEventType.SET_INDEXED, index + viewOffset, object, 1, null, null, -1);
}
/**
@@ -710,7 +710,7 @@
*/
protected void postSetIndexed(int index, Object object, Object previousValue) {
// reference check for modification, in case equals() has issues (eg. performance)
- postEvent((object != previousValue), ModificationEventType.SET_INDEXED, index + rangeOffset, object, 1, previousValue, null, -1);
+ postEvent((object != previousValue), ModificationEventType.SET_INDEXED, index + viewOffset, object, 1, previousValue, null, -1);
}
//-----------------------------------------------------------------------
@@ -725,7 +725,7 @@
* @return true to process modification
*/
protected boolean preSetIterated(int index, Object object, Object previousValue) {
- return preEvent(ModificationEventType.SET_ITERATED, index + rangeOffset, object, 1, previousValue, null, -1);
+ return preEvent(ModificationEventType.SET_ITERATED, index + viewOffset, object, 1, previousValue, null, -1);
}
/**
@@ -739,10 +739,83 @@
*/
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 + rangeOffset, object, 1, previousValue, null, -1);
+ postEvent((object != previousValue), ModificationEventType.SET_ITERATED, index + viewOffset, object, 1, previousValue, null, -1);
}
- // Views
+ // SortedSet Views
+ //-----------------------------------------------------------------------
+ /**
+ * Creates a new handler for SortedSet subSet.
+ *
+ * @param fromElement the from element
+ * @param toElement the to element
+ */
+ protected ModificationHandler createSubSetHandler(Object fromElement, Object toElement) {
+ return new SetViewHandler(rootHandler);
+ }
+
+ /**
+ * Creates a new handler for SortedSet headSet.
+ *
+ * @param toElement the to element
+ */
+ protected ModificationHandler createHeadSetHandler(Object toElement) {
+ return new SetViewHandler(rootHandler);
+ }
+
+ /**
+ * Creates a new handler for SortedSet tailSet.
+ *
+ * @param fromElement the from element
+ */
+ protected ModificationHandler createTailSetHandler(Object fromElement) {
+ return new SetViewHandler(rootHandler);
+ }
+
+ /**
+ * Inner class for views.
+ */
+ protected static class SetViewHandler extends ModificationHandler {
+
+ /**
+ * Constructor.
+ *
+ * @param rootHandler the base underlying handler
+ */
+ protected SetViewHandler(ModificationHandler rootHandler) {
+ super(rootHandler, 0);
+ }
+
+ /**
+ * Override the preEvent method to forward all events to the
+ * underlying handler. This method also inserts details of the view
+ * that caused the event.
+ */
+ protected boolean preEvent(
+ int type, int index, Object object, int repeat,
+ Object previous, ObservableCollection ignoredView, int offset) {
+
+ return getRootHandler().preEvent(
+ type, index, object, repeat,
+ previous, getObservedCollection(), offset);
+ }
+
+ /**
+ * Override the postEvent method to forward all events to the
+ * underlying handler. This method also inserts details of the view
+ * that caused the event.
+ */
+ protected void postEvent(
+ boolean modified, int type, int index, Object object, int repeat,
+ Object previous, ObservableCollection ignoredView, int offset) {
+
+ getRootHandler().postEvent(
+ modified, type, index, object, repeat,
+ previous, getObservedCollection(), offset);
+ }
+ }
+
+ // List View
//-----------------------------------------------------------------------
/**
* Creates a new handler for subLists that is aware of the offset.
@@ -751,47 +824,50 @@
* @param toIndex the sublist toIndex (exclusive)
*/
protected ModificationHandler createSubListHandler(int fromIndex, int toIndex) {
- return new SubListHandler(rootHandler, fromIndex + rangeOffset);
+ return new SubListHandler(rootHandler, fromIndex + viewOffset);
}
-
+
+ /**
+ * Inner class for subLists.
+ */
protected static class SubListHandler extends ModificationHandler {
/**
* Constructor.
*
* @param rootHandler the base underlying handler
- * @param rangeOffset the offset on the base collection
+ * @param viewOffset the offset on the base collection
*/
- protected SubListHandler(ModificationHandler rootHandler, int rangeOffset) {
- super(rootHandler, rangeOffset);
+ protected SubListHandler(ModificationHandler rootHandler, int viewOffset) {
+ super(rootHandler, viewOffset);
}
/**
* Override the preEvent method to forward all events to the
- * underlying handler. This method also inserts details of the range
+ * underlying handler. This method also inserts details of the view
* that caused the event.
*/
protected boolean preEvent(
int type, int index, Object object, int repeat,
- Object previous, ObservableCollection ignoredRange, int ignoredOffset) {
+ Object previous, ObservableCollection ignoredView, int ignoredOffset) {
return getRootHandler().preEvent(
type, index, object, repeat,
- previous, getObservedCollection(), getRangeOffset());
+ previous, getObservedCollection(), getViewOffset());
}
/**
* Override the postEvent method to forward all events to the
- * underlying handler. This method also inserts details of the range
+ * underlying handler. This method also inserts details of the view
* that caused the event.
*/
protected void postEvent(
boolean modified, int type, int index, Object object, int repeat,
- Object previous, ObservableCollection ignoredRange, int ignoredOffset) {
+ Object previous, ObservableCollection ignoredView, int ignoredOffset) {
getRootHandler().postEvent(
modified, type, index, object, repeat,
- previous, getObservedCollection(), getRangeOffset());
+ previous, getObservedCollection(), getViewOffset());
}
}
1.1 jakarta-commons/collections/src/java/org/apache/commons/collections/observed/ObservableSortedSet.java
Index: ObservableSortedSet.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/observed/ObservableSortedSet.java,v 1.1 2003/09/21 20:01:53 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.collections.observed;
import java.util.Comparator;
import java.util.SortedSet;
/**
* Decorates a <code>SortedSet</code> implementation to observe modifications.
* <p>
* Each modifying method call made on this <code>SortedSet</code> is forwarded to a
* {@link ModificationHandler}.
* The handler manages the event, notifying listeners and optionally vetoing changes.
* The default handler is {@link StandardModificationHandler}.
* See this class for details of configuration available.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/09/21 20:01:53 $
*
* @author Stephen Colebourne
*/
public class ObservableSortedSet extends ObservableSet implements SortedSet {
// Factories
//-----------------------------------------------------------------------
/**
* Factory method to create an observable set.
* <p>
* A {@link StandardModificationHandler} will be created.
* This can be accessed by {@link #getHandler()} to add listeners.
*
* @param set the set to decorate, must not be null
* @return the observed Set
* @throws IllegalArgumentException if the collection is null
*/
public static ObservableSortedSet decorate(final SortedSet set) {
return new ObservableSortedSet(set, null);
}
/**
* Factory method to create an observable set using a listener or a handler.
* <p>
* A lot of functionality is available through this method.
* If you don't need the extra functionality, simply implement the
* {@link org.apache.commons.collections.observed.standard.StandardModificationListener}
* interface and pass it in as the second parameter.
* <p>
* Internally, an <code>ObservableSet</code> relies on a {@link ModificationHandler}.
* The handler receives all the events and processes them, typically by
* calling listeners. Different handler implementations can be plugged in
* to provide a flexible event system.
* <p>
* The handler implementation is determined by the listener parameter via
* the registered factories. The listener may be a manually configured
* <code>ModificationHandler</code> instance.
* <p>
* The listener is defined as an Object for maximum flexibility.
* It does not have to be a listener in the classic JavaBean sense.
* It is entirely up to the factory and handler as to how the parameter
* is interpretted. An IllegalArgumentException is thrown if no suitable
* handler can be found for this listener.
* <p>
* A <code>null</code> listener will create a {@link StandardModificationHandler}.
*
* @param set the set to decorate, must not be null
* @param listener set listener, may be null
* @return the observed set
* @throws IllegalArgumentException if the set is null
* @throws IllegalArgumentException if there is no valid handler for the listener
*/
public static ObservableSortedSet decorate(
final SortedSet set,
final Object listener) {
if (set == null) {
throw new IllegalArgumentException("Set must not be null");
}
return new ObservableSortedSet(set, listener);
}
// Constructors
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies) and takes a handler.
* <p>
* The handler implementation is determined by the listener parameter via
* the registered factories. The listener may be a manually configured
* <code>ModificationHandler</code> instance.
*
* @param set the set to decorate, must not be null
* @param listener the listener, may be null
* @throws IllegalArgumentException if the set is null
*/
protected ObservableSortedSet(
final SortedSet set,
final Object listener) {
super(set, listener);
}
/**
* Typecast the collection to a SortedSet.
*
* @return the wrapped collection as a SortedSet
*/
private SortedSet getSortedSet() {
return (SortedSet) getCollection();
}
// SortedSet API
//-----------------------------------------------------------------------
public Comparator comparator() {
return getSortedSet().comparator();
}
public Object first() {
return getSortedSet().first();
}
public Object last() {
return getSortedSet().last();
}
//-----------------------------------------------------------------------
public SortedSet subSet(Object fromElement, Object toElement) {
SortedSet subSet = getSortedSet().subSet(fromElement, toElement);
return new ObservableSortedSet(subSet, getHandler().createSubSetHandler(fromElement, toElement));
}
public SortedSet headSet(Object toElement) {
SortedSet headSet = getSortedSet().headSet(toElement);
return new ObservableSortedSet(headSet, getHandler().createHeadSetHandler(toElement));
}
public SortedSet tailSet(Object fromElement) {
SortedSet tailSet = getSortedSet().tailSet(fromElement);
return new ObservableSortedSet(tailSet, getHandler().createTailSetHandler(fromElement));
}
}