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/12/03 12:19:10 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/set UnmodifiableSet.java UnmodifiableSortedSet.java
scolebourne 2003/12/03 03:19:10
Modified: collections/src/test/org/apache/commons/collections/list
TestUnmodifiableList.java
collections/src/java/org/apache/commons/collections/list
UnmodifiableList.java
collections/src/test/org/apache/commons/collections/set
AbstractTestSortedSet.java
TestUnmodifiableSortedSet.java TestAll.java
collections/src/test/org/apache/commons/collections/collection
TestAll.java
collections/src/java/org/apache/commons/collections/buffer
UnmodifiablePriorityQueue.java
UnmodifiableBuffer.java
collections/src/java/org/apache/commons/collections/bag
UnmodifiableSortedBag.java UnmodifiableBag.java
AbstractMapBag.java
collections/src/java/org/apache/commons/collections/collection
UnmodifiableCollection.java
collections/src/java/org/apache/commons/collections/set
UnmodifiableSet.java UnmodifiableSortedSet.java
Added: collections/src/test/org/apache/commons/collections/set
TestUnmodifiableSet.java
collections/src/test/org/apache/commons/collections/collection
TestUnmodifiableCollection.java
Log:
Update and make consistent the Unmodifiable decorators
Revision Changes Path
1.4 +10 -11 jakarta-commons/collections/src/test/org/apache/commons/collections/list/TestUnmodifiableList.java
Index: TestUnmodifiableList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/list/TestUnmodifiableList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestUnmodifiableList.java 18 Nov 2003 22:37:14 -0000 1.3
+++ TestUnmodifiableList.java 3 Dec 2003 11:19:10 -0000 1.4
@@ -65,8 +65,6 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.commons.collections.map.TestPredicatedSortedMap;
-
/**
* Extension of {@link AbstractTestList} for exercising the
* {@link UnmodifiableList} implementation.
@@ -76,7 +74,7 @@
*
* @author Phil Steitz
*/
-public class TestUnmodifiableList extends AbstractTestList{
+public class TestUnmodifiableList extends AbstractTestList {
public TestUnmodifiableList(String testName) {
super(testName);
@@ -87,11 +85,11 @@
}
public static void main(String args[]) {
- String[] testCaseName = { TestPredicatedSortedMap.class.getName()};
+ String[] testCaseName = { TestUnmodifiableList.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
-
- //-------------------------------------------------------------------
+
+ //-----------------------------------------------------------------------
public List makeEmptyList() {
return UnmodifiableList.decorate(new ArrayList());
}
@@ -112,8 +110,9 @@
public boolean isRemoveSupported() {
return false;
- }
-//--------------------------------------------------------------------
+ }
+
+ //-----------------------------------------------------------------------
protected UnmodifiableList list = null;
protected ArrayList array = null;
@@ -209,4 +208,4 @@
// expected
}
}
-}
\ No newline at end of file
+}
1.2 +39 -9 jakarta-commons/collections/src/java/org/apache/commons/collections/list/UnmodifiableList.java
Index: UnmodifiableList.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/list/UnmodifiableList.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnmodifiableList.java 16 Nov 2003 00:05:47 -0000 1.1
+++ UnmodifiableList.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -58,12 +58,13 @@
package org.apache.commons.collections.list;
import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
-import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.Unmodifiable;
-import org.apache.commons.collections.collection.UnmodifiableCollection;
+import org.apache.commons.collections.iterators.UnmodifiableIterator;
+import org.apache.commons.collections.iterators.UnmodifiableListIterator;
/**
* Decorates another <code>List</code> to ensure it can't be altered.
@@ -73,7 +74,7 @@
*
* @author Stephen Colebourne
*/
-public class UnmodifiableList extends UnmodifiableCollection implements List {
+public class UnmodifiableList extends AbstractListDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable list.
@@ -109,14 +110,35 @@
}
//-----------------------------------------------------------------------
- public void add(int index, Object object) {
+ public Iterator iterator() {
+ return UnmodifiableIterator.decorate(getCollection().iterator());
+ }
+
+ public boolean add(Object object) {
throw new UnsupportedOperationException();
}
- public boolean addAll(int index, Collection coll) {
+ public boolean addAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection coll) {
throw new UnsupportedOperationException();
}
+ public boolean retainAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ //-----------------------------------------------------------------------
public Object get(int index) {
return getList().get(index);
}
@@ -130,11 +152,19 @@
}
public ListIterator listIterator() {
- return IteratorUtils.unmodifiableListIterator(getList().listIterator());
+ return UnmodifiableListIterator.decorate(getList().listIterator());
}
public ListIterator listIterator(int index) {
- return IteratorUtils.unmodifiableListIterator(getList().listIterator(index));
+ return UnmodifiableListIterator.decorate(getList().listIterator(index));
+ }
+
+ public void add(int index, Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(int index, Collection coll) {
+ throw new UnsupportedOperationException();
}
public Object remove(int index) {
1.3 +21 -32 jakarta-commons/collections/src/test/org/apache/commons/collections/set/AbstractTestSortedSet.java
Index: AbstractTestSortedSet.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/set/AbstractTestSortedSet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractTestSortedSet.java 18 Nov 2003 22:37:17 -0000 1.2
+++ AbstractTestSortedSet.java 3 Dec 2003 11:19:10 -0000 1.3
@@ -281,17 +281,24 @@
//System.out.println(new TreeSet(Arrays.asList(m_FullElements)));
//System.out.println(new TreeSet(Arrays.asList(m_OtherElements)));
- } //TestSortedSetSubSet
+ }
public boolean isNullSupported() {
return AbstractTestSortedSet.this.isNullSupported();
- } //useNullValue
+ }
+ public boolean isAddSupported() {
+ return AbstractTestSortedSet.this.isAddSupported();
+ }
+ public boolean isRemoveSupported() {
+ return AbstractTestSortedSet.this.isRemoveSupported();
+ }
+ public boolean isFailFastSupported() {
+ return AbstractTestSortedSet.this.isFailFastSupported();
+ }
public Object[] getFullElements() {
- //System.out.println("getFullElements()");
return m_FullElements;
}
-
public Object[] getOtherElements() {
return m_OtherElements;
}
@@ -308,44 +315,26 @@
default :
return null;
}
- } //getSubSet
+ }
public Set makeEmptySet() {
- SortedSet s = (SortedSet) AbstractTestSortedSet.this.makeFullSet();
- s = getSubSet(s);
- s.clear();
- return s;
- } //makeEmptySet
+ SortedSet s = (SortedSet) AbstractTestSortedSet.this.makeEmptySet();
+ return getSubSet(s);
+ }
public Set makeFullSet() {
SortedSet s = (SortedSet) AbstractTestSortedSet.this.makeFullCollection();
return getSubSet(s);
- } //makeFullSet
-
- public void resetFull() {
- AbstractTestSortedSet.this.resetFull();
- TestSortedSetSubSet.this.confirmed = getSubSet((SortedSet) AbstractTestSortedSet.this.confirmed);
- TestSortedSetSubSet.this.collection = getSubSet((SortedSet) AbstractTestSortedSet.this.collection);
- }
-
- public void resetEmpty() {
- TestSortedSetSubSet.this.resetFull();
- TestSortedSetSubSet.this.confirmed.clear();
- TestSortedSetSubSet.this.collection.clear();
}
public BulkTest bulkTestSortedSetSubSet() {
- //Override returning null to prevent endless
- //loop of bulk tests
- return null;
- } //bulkTestSortedSetSubSet
-
+ return null; // prevent infinite recursion
+ }
public BulkTest bulkTestSortedSetHeadSet() {
- return null;
+ return null; // prevent infinite recursion
}
-
public BulkTest bulkTestSortedSetTailSet() {
- return null;
+ return null; // prevent infinite recursion
}
static final int TYPE_SUBSET = 0;
1.4 +5 -5 jakarta-commons/collections/src/test/org/apache/commons/collections/set/TestUnmodifiableSortedSet.java
Index: TestUnmodifiableSortedSet.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/set/TestUnmodifiableSortedSet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestUnmodifiableSortedSet.java 18 Nov 2003 22:37:17 -0000 1.3
+++ TestUnmodifiableSortedSet.java 3 Dec 2003 11:19:10 -0000 1.4
@@ -64,7 +64,8 @@
import java.util.TreeSet;
import junit.framework.Test;
-import junit.framework.TestSuite;
+
+import org.apache.commons.collections.BulkTest;
/**
* Extension of {@link AbstractTestSortedSet} for exercising the
@@ -82,8 +83,7 @@
}
public static Test suite() {
- // Can't run bulk tests in AbstractTestSet -- subset tests modify set
- return new TestSuite(TestUnmodifiableSortedSet.class);
+ return BulkTest.makeSuite(TestUnmodifiableSortedSet.class);
}
public static void main(String args[]) {
1.2 +3 -2 jakarta-commons/collections/src/test/org/apache/commons/collections/set/TestAll.java
Index: TestAll.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/set/TestAll.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestAll.java 16 Nov 2003 00:05:46 -0000 1.1
+++ TestAll.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -89,6 +89,7 @@
suite.addTest(TestTransformedSet.suite());
suite.addTest(TestTransformedSortedSet.suite());
suite.addTest(TestTypedSortedSet.suite());
+ suite.addTest(TestUnmodifiableSet.suite());
suite.addTest(TestUnmodifiableSortedSet.suite());
return suite;
1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/set/TestUnmodifiableSet.java
Index: TestUnmodifiableSet.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/set/TestUnmodifiableSet.java,v 1.1 2003/12/03 11:19:10 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.set;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import junit.framework.Test;
import org.apache.commons.collections.BulkTest;
/**
* Extension of {@link AbstractTestSet} for exercising the
* {@link UnmodifiableSet} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/12/03 11:19:10 $
*
* @author Phil Steitz
*/
public class TestUnmodifiableSet extends AbstractTestSet{
public TestUnmodifiableSet(String testName) {
super(testName);
}
public static Test suite() {
return BulkTest.makeSuite(TestUnmodifiableSet.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestUnmodifiableSet.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-------------------------------------------------------------------
public Set makeEmptySet() {
return UnmodifiableSet.decorate(new HashSet());
}
public Set makeFullSet() {
HashSet set = new HashSet();
set.addAll(Arrays.asList(getFullElements()));
return UnmodifiableSet.decorate(set);
}
public boolean isAddSupported() {
return false;
}
public boolean isRemoveSupported() {
return false;
}
}
1.2 +3 -2 jakarta-commons/collections/src/test/org/apache/commons/collections/collection/TestAll.java
Index: TestAll.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/collection/TestAll.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestAll.java 16 Nov 2003 00:05:47 -0000 1.1
+++ TestAll.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -86,6 +86,7 @@
suite.addTest(TestCompositeCollection.suite());
suite.addTest(TestPredicatedCollection.suite());
suite.addTest(TestTransformedCollection.suite());
+ suite.addTest(TestUnmodifiableCollection.suite());
return suite;
}
1.1 jakarta-commons/collections/src/test/org/apache/commons/collections/collection/TestUnmodifiableCollection.java
Index: TestUnmodifiableCollection.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/collection/TestUnmodifiableCollection.java,v 1.1 2003/12/03 11:19:10 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.collection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Extension of {@link AbstractTestCollection} for exercising the
* {@link UnmodifiableCollection} implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/12/03 11:19:10 $
*
* @author Phil Steitz
* @author Stephen Colebourne
*/
public class TestUnmodifiableCollection extends AbstractTestCollection {
public TestUnmodifiableCollection(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestUnmodifiableCollection.class);
}
public static void main(String args[]) {
String[] testCaseName = { TestUnmodifiableCollection.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}
//-----------------------------------------------------------------------
public Collection makeCollection() {
return UnmodifiableCollection.decorate(new ArrayList());
}
public Collection makeFullCollection() {
List list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return UnmodifiableCollection.decorate(list);
}
public Collection makeConfirmedCollection() {
ArrayList list = new ArrayList();
return list;
}
public Collection makeConfirmedFullCollection() {
ArrayList list = new ArrayList();
list.addAll(Arrays.asList(getFullElements()));
return list;
}
public boolean isAddSupported() {
return false;
}
public boolean isRemoveSupported() {
return false;
}
}
1.2 +9 -3 jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/UnmodifiablePriorityQueue.java
Index: UnmodifiablePriorityQueue.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/UnmodifiablePriorityQueue.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnmodifiablePriorityQueue.java 16 Nov 2003 00:05:44 -0000 1.1
+++ UnmodifiablePriorityQueue.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -60,6 +60,7 @@
import java.util.NoSuchElementException;
import org.apache.commons.collections.PriorityQueue;
+import org.apache.commons.collections.Unmodifiable;
/**
* <code>UnmodifiablePriorityQueue</code> decorates another <code>PriorityQueue</code>
@@ -70,7 +71,7 @@
*
* @author Stephen Colebourne
*/
-public class UnmodifiablePriorityQueue implements PriorityQueue {
+public class UnmodifiablePriorityQueue implements PriorityQueue, Unmodifiable {
/** The priority queue to decorate */
protected final PriorityQueue priorityQueue;
@@ -82,9 +83,13 @@
* @throws IllegalArgumentException if priority queue is null
*/
public static PriorityQueue decorate(PriorityQueue priorityQueue) {
+ if (priorityQueue instanceof Unmodifiable) {
+ return priorityQueue;
+ }
return new UnmodifiablePriorityQueue(priorityQueue);
}
+ //-----------------------------------------------------------------------
/**
* Constructs a new synchronized priority queue.
*
@@ -97,6 +102,7 @@
this.priorityQueue = priorityQueue;
}
+ //-----------------------------------------------------------------------
/**
* Clear all elements from queue - Unsupported as unmodifiable.
*/
1.2 +33 -14 jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/UnmodifiableBuffer.java
Index: UnmodifiableBuffer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/UnmodifiableBuffer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnmodifiableBuffer.java 16 Nov 2003 00:05:44 -0000 1.1
+++ UnmodifiableBuffer.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -57,9 +57,12 @@
*/
package org.apache.commons.collections.buffer;
+import java.util.Collection;
+import java.util.Iterator;
+
import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.Unmodifiable;
-import org.apache.commons.collections.collection.UnmodifiableCollection;
+import org.apache.commons.collections.iterators.UnmodifiableIterator;
/**
* Decorates another <code>Buffer</code> to ensure it can't be altered.
@@ -69,7 +72,7 @@
*
* @author Stephen Colebourne
*/
-public class UnmodifiableBuffer extends UnmodifiableCollection implements Buffer {
+public class UnmodifiableBuffer extends AbstractBufferDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable buffer.
@@ -95,20 +98,36 @@
super(buffer);
}
- /**
- * Gets the buffer being decorated.
- *
- * @return the decorated buffer
- */
- protected Buffer getBuffer() {
- return (Buffer) getCollection();
+ //-----------------------------------------------------------------------
+ public Iterator iterator() {
+ return UnmodifiableIterator.decorate(getCollection().iterator());
}
- //-----------------------------------------------------------------------
- public Object get() {
- return getBuffer().get();
+ public boolean add(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection coll) {
+ throw new UnsupportedOperationException();
}
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ //-----------------------------------------------------------------------
public Object remove() {
throw new UnsupportedOperationException();
}
1.2 +27 -18 jakarta-commons/collections/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java
Index: UnmodifiableSortedBag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnmodifiableSortedBag.java 16 Nov 2003 00:05:43 -0000 1.1
+++ UnmodifiableSortedBag.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -57,10 +57,12 @@
*/
package org.apache.commons.collections.bag;
-import java.util.Comparator;
+import java.util.Collection;
+import java.util.Iterator;
import org.apache.commons.collections.SortedBag;
import org.apache.commons.collections.Unmodifiable;
+import org.apache.commons.collections.iterators.UnmodifiableIterator;
/**
* Decorates another <code>SortedBag</code> to ensure it can't be altered.
@@ -70,7 +72,7 @@
*
* @author Stephen Colebourne
*/
-public class UnmodifiableSortedBag extends UnmodifiableBag implements SortedBag {
+public class UnmodifiableSortedBag extends AbstractSortedBagDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable bag.
@@ -96,26 +98,33 @@
super(bag);
}
- /**
- * Gets the bag being decorated.
- *
- * @return the decorated bag
- */
- protected SortedBag getSortedBag() {
- return (SortedBag) getCollection();
+ //-----------------------------------------------------------------------
+ public Iterator iterator() {
+ return UnmodifiableIterator.decorate(getCollection().iterator());
}
- //-----------------------------------------------------------------------
- public Object first() {
- return getSortedBag().first();
+ public boolean add(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object object) {
+ throw new UnsupportedOperationException();
}
- public Object last() {
- return getSortedBag().last();
+ public boolean removeAll(Collection coll) {
+ throw new UnsupportedOperationException();
}
- public Comparator comparator() {
- return getSortedBag().comparator();
+ public boolean retainAll(Collection coll) {
+ throw new UnsupportedOperationException();
}
}
1.2 +35 -17 jakarta-commons/collections/src/java/org/apache/commons/collections/bag/UnmodifiableBag.java
Index: UnmodifiableBag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bag/UnmodifiableBag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnmodifiableBag.java 16 Nov 2003 00:05:43 -0000 1.1
+++ UnmodifiableBag.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -57,11 +57,13 @@
*/
package org.apache.commons.collections.bag;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.Set;
import org.apache.commons.collections.Bag;
import org.apache.commons.collections.Unmodifiable;
-import org.apache.commons.collections.collection.UnmodifiableCollection;
+import org.apache.commons.collections.iterators.UnmodifiableIterator;
import org.apache.commons.collections.set.UnmodifiableSet;
/**
@@ -72,7 +74,7 @@
*
* @author Stephen Colebourne
*/
-public class UnmodifiableBag extends UnmodifiableCollection implements Bag {
+public class UnmodifiableBag extends AbstractBagDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable bag.
@@ -98,21 +100,41 @@
super(bag);
}
- /**
- * Gets the bag being decorated.
- *
- * @return the decorated bag
- */
- protected Bag getBag() {
- return (Bag) getCollection();
+ //-----------------------------------------------------------------------
+ public Iterator iterator() {
+ return UnmodifiableIterator.decorate(getCollection().iterator());
+ }
+
+ public boolean add(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection coll) {
+ throw new UnsupportedOperationException();
}
//-----------------------------------------------------------------------
- public boolean add(Object o, int count) {
+ public boolean add(Object object, int count) {
throw new UnsupportedOperationException();
}
- public boolean remove(Object o, int count) {
+ public boolean remove(Object object, int count) {
throw new UnsupportedOperationException();
}
@@ -121,8 +143,4 @@
return UnmodifiableSet.decorate(set);
}
- public int getCount(Object o) {
- return getBag().getCount(o);
- }
-
}
1.4 +4 -4 jakarta-commons/collections/src/java/org/apache/commons/collections/bag/AbstractMapBag.java
Index: AbstractMapBag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/bag/AbstractMapBag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractMapBag.java 3 Dec 2003 01:02:32 -0000 1.3
+++ AbstractMapBag.java 3 Dec 2003 11:19:10 -0000 1.4
@@ -62,13 +62,13 @@
import java.io.ObjectOutputStream;
import java.lang.reflect.Array;
import java.util.Collection;
-import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.Bag;
+import org.apache.commons.collections.set.UnmodifiableSet;
/**
* Abstract implementation of the {@link Bag} interface to simplify the creation
@@ -544,7 +544,7 @@
*/
public Set uniqueSet() {
if (uniqueSet == null) {
- uniqueSet = Collections.unmodifiableSet(map.keySet());
+ uniqueSet = UnmodifiableSet.decorate(map.keySet());
}
return uniqueSet;
}
1.2 +7 -36 jakarta-commons/collections/src/java/org/apache/commons/collections/collection/UnmodifiableCollection.java
Index: UnmodifiableCollection.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/collection/UnmodifiableCollection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnmodifiableCollection.java 16 Nov 2003 00:05:47 -0000 1.1
+++ UnmodifiableCollection.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -60,8 +60,8 @@
import java.util.Collection;
import java.util.Iterator;
-import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.Unmodifiable;
+import org.apache.commons.collections.iterators.UnmodifiableIterator;
/**
* Decorates another <code>Collection</code> to ensure it can't be altered.
@@ -98,59 +98,30 @@
}
//-----------------------------------------------------------------------
- /**
- * Override as method unsupported.
- * @throws UnsupportedOperationException
- */
+ public Iterator iterator() {
+ return UnmodifiableIterator.decorate(getCollection().iterator());
+ }
+
public boolean add(Object object) {
throw new UnsupportedOperationException();
}
- /**
- * Override as method unsupported.
- * @throws UnsupportedOperationException
- */
public boolean addAll(Collection coll) {
throw new UnsupportedOperationException();
}
- /**
- * Override as method unsupported.
- * @throws UnsupportedOperationException
- */
public void clear() {
throw new UnsupportedOperationException();
}
- /**
- * Override to return an unmodifiable iterator.
- *
- * @return unmodifiable iterator
- */
- public Iterator iterator() {
- return IteratorUtils.unmodifiableIterator(getCollection().iterator());
- }
-
- /**
- * Override as method unsupported.
- * @throws UnsupportedOperationException
- */
public boolean remove(Object object) {
throw new UnsupportedOperationException();
}
- /**
- * Override as method unsupported.
- * @throws UnsupportedOperationException
- */
public boolean removeAll(Collection coll) {
throw new UnsupportedOperationException();
}
- /**
- * Override as method unsupported.
- * @throws UnsupportedOperationException
- */
public boolean retainAll(Collection coll) {
throw new UnsupportedOperationException();
}
1.2 +33 -11 jakarta-commons/collections/src/java/org/apache/commons/collections/set/UnmodifiableSet.java
Index: UnmodifiableSet.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/set/UnmodifiableSet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnmodifiableSet.java 16 Nov 2003 00:05:45 -0000 1.1
+++ UnmodifiableSet.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -57,10 +57,12 @@
*/
package org.apache.commons.collections.set;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.Set;
import org.apache.commons.collections.Unmodifiable;
-import org.apache.commons.collections.collection.UnmodifiableCollection;
+import org.apache.commons.collections.iterators.UnmodifiableIterator;
/**
* Decorates another <code>Set</code> to ensure it can't be altered.
@@ -70,7 +72,7 @@
*
* @author Stephen Colebourne
*/
-public class UnmodifiableSet extends UnmodifiableCollection implements Set {
+public class UnmodifiableSet extends AbstractSetDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable set.
@@ -96,13 +98,33 @@
super(set);
}
- /**
- * Gets the set being decorated.
- *
- * @return the decorated set
- */
- protected Set getSet() {
- return (Set) getCollection();
+ //-----------------------------------------------------------------------
+ public Iterator iterator() {
+ return UnmodifiableIterator.decorate(getCollection().iterator());
+ }
+
+ public boolean add(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection coll) {
+ throw new UnsupportedOperationException();
}
}
1.2 +33 -23 jakarta-commons/collections/src/java/org/apache/commons/collections/set/UnmodifiableSortedSet.java
Index: UnmodifiableSortedSet.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/set/UnmodifiableSortedSet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnmodifiableSortedSet.java 16 Nov 2003 00:05:45 -0000 1.1
+++ UnmodifiableSortedSet.java 3 Dec 2003 11:19:10 -0000 1.2
@@ -57,10 +57,12 @@
*/
package org.apache.commons.collections.set;
-import java.util.Comparator;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.SortedSet;
import org.apache.commons.collections.Unmodifiable;
+import org.apache.commons.collections.iterators.UnmodifiableIterator;
/**
* Decorates another <code>SortedSet</code> to ensure it can't be altered.
@@ -70,7 +72,7 @@
*
* @author Stephen Colebourne
*/
-public class UnmodifiableSortedSet extends UnmodifiableSet implements SortedSet {
+public class UnmodifiableSortedSet extends AbstractSortedSetDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable set.
@@ -96,13 +98,33 @@
super(set);
}
- /**
- * Gets the set being decorated.
- *
- * @return the decorated set
- */
- protected SortedSet getSortedSet() {
- return (SortedSet) getCollection();
+ //-----------------------------------------------------------------------
+ public Iterator iterator() {
+ return UnmodifiableIterator.decorate(getCollection().iterator());
+ }
+
+ public boolean add(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection coll) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection coll) {
+ throw new UnsupportedOperationException();
}
//-----------------------------------------------------------------------
@@ -119,18 +141,6 @@
public SortedSet tailSet(Object fromElement) {
SortedSet sub = getSortedSet().tailSet(fromElement);
return new UnmodifiableSortedSet(sub);
- }
-
- public Object first() {
- return getSortedSet().first();
- }
-
- public Object last() {
- return getSortedSet().last();
- }
-
- public Comparator comparator() {
- return getSortedSet().comparator();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org