Update and make consistent the Unmodifiable decorators

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131399 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-12-03 12:27:37 +00:00
parent aae1dcdb92
commit 7a58d2f1b8
18 changed files with 304 additions and 196 deletions

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BeanMap.java,v 1.23 2003/12/03 11:37:44 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BeanMap.java,v 1.24 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -84,7 +84,7 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* property is considered non existent in the Map
*
* @since Commons Collections 1.0
* @version $Revision: 1.23 $ $Date: 2003/12/03 11:37:44 $
* @version $Revision: 1.24 $ $Date: 2003/12/03 12:27:37 $
*
* @author James Strachan
* @author Stephen Colebourne
@ -456,33 +456,14 @@ public class BeanMap extends AbstractMap implements Cloneable {
* @return the unmodifiable set of mappings
*/
public Set entrySet() {
return new AbstractSet() {
return UnmodifiableSet.decorate(new AbstractSet() {
public Iterator iterator() {
return new Iterator() {
Iterator methodIter =
BeanMap.this.readMethods.keySet().iterator();
public boolean hasNext() {
return methodIter.hasNext();
}
public Object next() {
Object key = (Object)methodIter.next();
return new MyMapEntry( BeanMap.this, key, get(key) );
}
public void remove() {
throw new UnsupportedOperationException
("remove() not supported from BeanMap.entrySet()");
}
};
return entryIterator();
}
public int size() {
return BeanMap.this.readMethods.size();
}
};
});
}
/**
@ -559,7 +540,7 @@ public class BeanMap extends AbstractMap implements Cloneable {
}
public Object next() {
Object key = iter.next();
Object value = get( (String) key );
Object value = get(key);
return new MyMapEntry( BeanMap.this, key, value );
}
public void remove() {

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/bag/UnmodifiableBag.java,v 1.2 2003/12/03 11:19:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/bag/UnmodifiableBag.java,v 1.3 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -70,11 +70,11 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* Decorates another <code>Bag</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/03 11:19:10 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
public class UnmodifiableBag extends AbstractBagDecorator implements Unmodifiable {
public final class UnmodifiableBag extends AbstractBagDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable bag.
@ -96,7 +96,7 @@ public class UnmodifiableBag extends AbstractBagDecorator implements Unmodifiabl
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
protected UnmodifiableBag(Bag bag) {
private UnmodifiableBag(Bag bag) {
super(bag);
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java,v 1.2 2003/12/03 11:19:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/bag/UnmodifiableSortedBag.java,v 1.3 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -68,11 +68,11 @@ import org.apache.commons.collections.iterators.UnmodifiableIterator;
* Decorates another <code>SortedBag</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/03 11:19:10 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
public class UnmodifiableSortedBag extends AbstractSortedBagDecorator implements Unmodifiable {
public final class UnmodifiableSortedBag extends AbstractSortedBagDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable bag.
@ -94,7 +94,7 @@ public class UnmodifiableSortedBag extends AbstractSortedBagDecorator implements
* @param bag the bag to decorate, must not be null
* @throws IllegalArgumentException if bag is null
*/
protected UnmodifiableSortedBag(SortedBag bag) {
private UnmodifiableSortedBag(SortedBag bag) {
super(bag);
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/buffer/UnmodifiableBuffer.java,v 1.2 2003/12/03 11:19:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/buffer/UnmodifiableBuffer.java,v 1.3 2003/12/03 12:27:36 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -68,11 +68,11 @@ import org.apache.commons.collections.iterators.UnmodifiableIterator;
* Decorates another <code>Buffer</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/03 11:19:10 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:36 $
*
* @author Stephen Colebourne
*/
public class UnmodifiableBuffer extends AbstractBufferDecorator implements Unmodifiable {
public final class UnmodifiableBuffer extends AbstractBufferDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable buffer.
@ -94,7 +94,7 @@ public class UnmodifiableBuffer extends AbstractBufferDecorator implements Unmod
* @param buffer the buffer to decorate, must not be null
* @throws IllegalArgumentException if buffer is null
*/
protected UnmodifiableBuffer(Buffer buffer) {
private UnmodifiableBuffer(Buffer buffer) {
super(buffer);
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/buffer/Attic/UnmodifiablePriorityQueue.java,v 1.2 2003/12/03 11:19:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/buffer/Attic/UnmodifiablePriorityQueue.java,v 1.3 2003/12/03 12:27:36 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -67,11 +67,11 @@ import org.apache.commons.collections.Unmodifiable;
* to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/03 11:19:10 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:36 $
*
* @author Stephen Colebourne
*/
public class UnmodifiablePriorityQueue implements PriorityQueue, Unmodifiable {
public final class UnmodifiablePriorityQueue implements PriorityQueue, Unmodifiable {
/** The priority queue to decorate */
protected final PriorityQueue priorityQueue;
@ -86,6 +86,9 @@ public class UnmodifiablePriorityQueue implements PriorityQueue, Unmodifiable {
if (priorityQueue instanceof Unmodifiable) {
return priorityQueue;
}
if (priorityQueue == null) {
throw new IllegalArgumentException("PriorityQueue must not be null");
}
return new UnmodifiablePriorityQueue(priorityQueue);
}
@ -95,10 +98,8 @@ public class UnmodifiablePriorityQueue implements PriorityQueue, Unmodifiable {
*
* @param priorityQueue the priority queue to synchronize
*/
protected UnmodifiablePriorityQueue(PriorityQueue priorityQueue) {
if (priorityQueue == null) {
throw new IllegalArgumentException("PriorityQueue must not be null");
}
private UnmodifiablePriorityQueue(PriorityQueue priorityQueue) {
super();
this.priorityQueue = priorityQueue;
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java,v 1.3 2003/11/29 18:14:20 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/collection/UnmodifiableBoundedCollection.java,v 1.4 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -58,8 +58,10 @@
package org.apache.commons.collections.collection;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.collections.BoundedCollection;
import org.apache.commons.collections.iterators.UnmodifiableIterator;
/**
* <code>UnmodifiableBoundedCollection</code> decorates another <code>BoundedCollection</code>
@ -71,11 +73,11 @@ import org.apache.commons.collections.BoundedCollection;
* examining the package scope variables.
*
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/11/29 18:14:20 $
* @version $Revision: 1.4 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
public class UnmodifiableBoundedCollection extends UnmodifiableCollection implements BoundedCollection {
public final class UnmodifiableBoundedCollection extends AbstractCollectionDecorator implements BoundedCollection {
/**
* Factory method to create an unmodifiable bounded collection.
@ -126,10 +128,39 @@ public class UnmodifiableBoundedCollection extends UnmodifiableCollection implem
* @param coll the collection to decorate, must not be null
* @throws IllegalArgumentException if coll is null
*/
protected UnmodifiableBoundedCollection(BoundedCollection coll) {
private UnmodifiableBoundedCollection(BoundedCollection coll) {
super(coll);
}
//-----------------------------------------------------------------------
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 isFull() {
return ((BoundedCollection) collection).isFull();

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/collection/UnmodifiableCollection.java,v 1.2 2003/12/03 11:19:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/collection/UnmodifiableCollection.java,v 1.3 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -67,11 +67,11 @@ import org.apache.commons.collections.iterators.UnmodifiableIterator;
* Decorates another <code>Collection</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/03 11:19:10 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
public class UnmodifiableCollection extends AbstractCollectionDecorator implements Unmodifiable {
public final class UnmodifiableCollection extends AbstractCollectionDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable collection.
@ -93,7 +93,7 @@ public class UnmodifiableCollection extends AbstractCollectionDecorator implemen
* @param coll the collection to decorate, must not be null
* @throws IllegalArgumentException if collection is null
*/
protected UnmodifiableCollection(Collection coll) {
private UnmodifiableCollection(Collection coll) {
super(coll);
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/UnmodifiableIterator.java,v 1.1 2003/11/02 17:26:36 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/UnmodifiableIterator.java,v 1.2 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -65,7 +65,7 @@ import org.apache.commons.collections.Unmodifiable;
* Decorates an iterator such that it cannot be modified.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/11/02 17:26:36 $
* @version $Revision: 1.2 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
@ -99,7 +99,7 @@ public final class UnmodifiableIterator implements Iterator, Unmodifiable {
*
* @param iterator the iterator to decoarate
*/
protected UnmodifiableIterator(Iterator iterator) {
private UnmodifiableIterator(Iterator iterator) {
super();
this.iterator = iterator;
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/UnmodifiableListIterator.java,v 1.1 2003/11/02 17:26:36 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/UnmodifiableListIterator.java,v 1.2 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -65,7 +65,7 @@ import org.apache.commons.collections.Unmodifiable;
* Decorates a list iterator such that it cannot be modified.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/11/02 17:26:36 $
* @version $Revision: 1.2 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
@ -97,7 +97,7 @@ public final class UnmodifiableListIterator implements ListIterator, Unmodifiabl
*
* @param iterator the iterator to decoarate
*/
protected UnmodifiableListIterator(ListIterator iterator) {
private UnmodifiableListIterator(ListIterator iterator) {
super();
this.iterator = iterator;
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/UnmodifiableMapIterator.java,v 1.3 2003/12/01 22:49:00 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/UnmodifiableMapIterator.java,v 1.4 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -64,7 +64,7 @@ import org.apache.commons.collections.Unmodifiable;
* Decorates a map iterator such that it cannot be modified.
*
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/12/01 22:49:00 $
* @version $Revision: 1.4 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
@ -96,7 +96,7 @@ public final class UnmodifiableMapIterator implements MapIterator, Unmodifiable
*
* @param iterator the iterator to decoarate
*/
protected UnmodifiableMapIterator(MapIterator iterator) {
private UnmodifiableMapIterator(MapIterator iterator) {
super();
this.iterator = iterator;
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/UnmodifiableOrderedMapIterator.java,v 1.2 2003/12/01 22:49:00 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/iterators/UnmodifiableOrderedMapIterator.java,v 1.3 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -64,7 +64,7 @@ import org.apache.commons.collections.Unmodifiable;
* Decorates an ordered map iterator such that it cannot be modified.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/01 22:49:00 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
@ -96,7 +96,7 @@ public final class UnmodifiableOrderedMapIterator implements OrderedMapIterator,
*
* @param iterator the iterator to decoarate
*/
protected UnmodifiableOrderedMapIterator(OrderedMapIterator iterator) {
private UnmodifiableOrderedMapIterator(OrderedMapIterator iterator) {
super();
this.iterator = iterator;
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/list/UnmodifiableList.java,v 1.2 2003/12/03 11:19:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/list/UnmodifiableList.java,v 1.3 2003/12/03 12:27:36 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -70,11 +70,11 @@ import org.apache.commons.collections.iterators.UnmodifiableListIterator;
* Decorates another <code>List</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/03 11:19:10 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:36 $
*
* @author Stephen Colebourne
*/
public class UnmodifiableList extends AbstractListDecorator implements Unmodifiable {
public final class UnmodifiableList extends AbstractListDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable list.
@ -96,19 +96,10 @@ public class UnmodifiableList extends AbstractListDecorator implements Unmodifia
* @param list the list to decorate, must not be null
* @throws IllegalArgumentException if list is null
*/
protected UnmodifiableList(List list) {
private UnmodifiableList(List list) {
super(list);
}
/**
* Gets the list being decorated.
*
* @return the list being decorated
*/
protected List getList() {
return (List) getCollection();
}
//-----------------------------------------------------------------------
public Iterator iterator() {
return UnmodifiableIterator.decorate(getCollection().iterator());
@ -139,18 +130,6 @@ public class UnmodifiableList extends AbstractListDecorator implements Unmodifia
}
//-----------------------------------------------------------------------
public Object get(int index) {
return getList().get(index);
}
public int indexOf(Object object) {
return getList().indexOf(object);
}
public int lastIndexOf(Object object) {
return getList().lastIndexOf(object);
}
public ListIterator listIterator() {
return UnmodifiableListIterator.decorate(getList().listIterator());
}

View File

@ -0,0 +1,203 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java,v 1.1 2003/12/03 12:27:36 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.map;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.Unmodifiable;
import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
import org.apache.commons.collections.pairs.AbstractMapEntryDecorator;
import org.apache.commons.collections.set.AbstractSetDecorator;
/**
* Decorates a map entry <code>Set</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/12/03 12:27:36 $
*
* @author Stephen Colebourne
*/
public final class UnmodifiableEntrySet extends AbstractSetDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable set of Map Entry objects.
*
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
public static Set decorate(Set set) {
if (set instanceof Unmodifiable) {
return set;
}
return new UnmodifiableEntrySet(set);
}
//-----------------------------------------------------------------------
/**
* Constructor that wraps (not copies).
*
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
private UnmodifiableEntrySet(Set set) {
super(set);
}
//-----------------------------------------------------------------------
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 Iterator iterator() {
return new UnmodifiableEntrySetIterator(collection.iterator());
}
public Object[] toArray() {
Object[] array = collection.toArray();
for (int i = 0; i < array.length; i++) {
array[i] = new UnmodifiableEntry((Map.Entry) array[i]);
}
return array;
}
public Object[] toArray(Object array[]) {
Object[] result = array;
if (array.length > 0) {
// we must create a new array to handle multi-threaded situations
// where another thread could access data before we decorate it
result = (Object[]) Array.newInstance(array.getClass().getComponentType(), 0);
}
result = collection.toArray(result);
for (int i = 0; i < result.length; i++) {
result[i] = new UnmodifiableEntry((Map.Entry) result[i]);
}
// check to see if result should be returned straight
if (result.length > array.length) {
return result;
}
// copy back into input array to fulfil the method contract
System.arraycopy(result, 0, array, 0, result.length);
if (array.length > result.length) {
array[result.length] = null;
}
return array;
}
//-----------------------------------------------------------------------
/**
* Implementation of an entry set iterator.
*/
final static class UnmodifiableEntrySetIterator extends AbstractIteratorDecorator {
protected UnmodifiableEntrySetIterator(Iterator iterator) {
super(iterator);
}
public Object next() {
Map.Entry entry = (Map.Entry) iterator.next();
return new UnmodifiableEntry(entry);
}
public void remove() {
throw new UnsupportedOperationException();
}
}
//-----------------------------------------------------------------------
/**
* Implementation of a map entry that is unmodifiable.
*/
final static class UnmodifiableEntry extends AbstractMapEntryDecorator {
protected UnmodifiableEntry(Map.Entry entry) {
super(entry);
}
public Object setValue(Object o) {
throw new UnsupportedOperationException();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/UnmodifiableMap.java,v 1.5 2003/12/02 23:51:50 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/UnmodifiableMap.java,v 1.6 2003/12/03 12:27:36 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -57,9 +57,7 @@
*/
package org.apache.commons.collections.map;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@ -67,17 +65,15 @@ import org.apache.commons.collections.IterableMap;
import org.apache.commons.collections.MapIterator;
import org.apache.commons.collections.Unmodifiable;
import org.apache.commons.collections.collection.UnmodifiableCollection;
import org.apache.commons.collections.iterators.AbstractIteratorDecorator;
import org.apache.commons.collections.iterators.EntrySetMapIterator;
import org.apache.commons.collections.iterators.UnmodifiableMapIterator;
import org.apache.commons.collections.pairs.AbstractMapEntryDecorator;
import org.apache.commons.collections.set.UnmodifiableSet;
/**
* Decorates another <code>Map</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2003/12/02 23:51:50 $
* @version $Revision: 1.6 $ $Date: 2003/12/03 12:27:36 $
*
* @author Stephen Colebourne
*/
@ -103,7 +99,7 @@ public final class UnmodifiableMap extends AbstractMapDecorator implements Itera
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
protected UnmodifiableMap(Map map) {
private UnmodifiableMap(Map map) {
super(map);
}
@ -136,7 +132,7 @@ public final class UnmodifiableMap extends AbstractMapDecorator implements Itera
public Set entrySet() {
Set set = super.entrySet();
return new UnmodifiableEntrySet(set);
return UnmodifiableEntrySet.decorate(set);
}
public Set keySet() {
@ -149,85 +145,4 @@ public final class UnmodifiableMap extends AbstractMapDecorator implements Itera
return UnmodifiableCollection.decorate(coll);
}
//-----------------------------------------------------------------------
/**
* Implementation of an entry set that checks (predicates) additions.
*/
protected static class UnmodifiableEntrySet extends UnmodifiableSet {
protected UnmodifiableEntrySet(Set set) {
super(set);
}
public Iterator iterator() {
return new UnmodifiableEntrySetIterator(collection.iterator());
}
public Object[] toArray() {
Object[] array = collection.toArray();
for (int i = 0; i < array.length; i++) {
array[i] = new UnmodifiableEntry((Map.Entry) array[i]);
}
return array;
}
public Object[] toArray(Object array[]) {
Object[] result = array;
if (array.length > 0) {
// we must create a new array to handle multi-threaded situations
// where another thread could access data before we decorate it
result = (Object[]) Array.newInstance(array.getClass().getComponentType(), 0);
}
result = collection.toArray(result);
for (int i = 0; i < result.length; i++) {
result[i] = new UnmodifiableEntry((Map.Entry) result[i]);
}
// check to see if result should be returned straight
if (result.length > array.length) {
return result;
}
// copy back into input array to fulfil the method contract
System.arraycopy(result, 0, array, 0, result.length);
if (array.length > result.length) {
array[result.length] = null;
}
return array;
}
}
/**
* Implementation of an entry set iterator.
*/
protected static class UnmodifiableEntrySetIterator extends AbstractIteratorDecorator {
protected UnmodifiableEntrySetIterator(Iterator iterator) {
super(iterator);
}
public Object next() {
Map.Entry entry = (Map.Entry) iterator.next();
return new UnmodifiableEntry(entry);
}
public void remove() {
throw new UnsupportedOperationException();
}
}
/**
* Implementation of a map entry that is unmodifiable.
*/
protected static class UnmodifiableEntry extends AbstractMapEntryDecorator {
protected UnmodifiableEntry(Map.Entry entry) {
super(entry);
}
public Object setValue(Object o) {
throw new UnsupportedOperationException();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/UnmodifiableOrderedMap.java,v 1.3 2003/12/01 22:48:59 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/UnmodifiableOrderedMap.java,v 1.4 2003/12/03 12:27:36 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -68,14 +68,13 @@ import org.apache.commons.collections.Unmodifiable;
import org.apache.commons.collections.collection.UnmodifiableCollection;
import org.apache.commons.collections.iterators.UnmodifiableMapIterator;
import org.apache.commons.collections.iterators.UnmodifiableOrderedMapIterator;
import org.apache.commons.collections.map.UnmodifiableMap.UnmodifiableEntrySet;
import org.apache.commons.collections.set.UnmodifiableSet;
/**
* Decorates another <code>OrderedMap</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/12/01 22:48:59 $
* @version $Revision: 1.4 $ $Date: 2003/12/03 12:27:36 $
*
* @author Stephen Colebourne
*/
@ -101,7 +100,7 @@ public final class UnmodifiableOrderedMap extends AbstractOrderedMapDecorator im
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
protected UnmodifiableOrderedMap(OrderedMap map) {
private UnmodifiableOrderedMap(OrderedMap map) {
super(map);
}
@ -134,7 +133,7 @@ public final class UnmodifiableOrderedMap extends AbstractOrderedMapDecorator im
public Set entrySet() {
Set set = super.entrySet();
return new UnmodifiableEntrySet(set);
return UnmodifiableEntrySet.decorate(set);
}
public Set keySet() {

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/UnmodifiableSortedMap.java,v 1.2 2003/11/20 22:35:50 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/UnmodifiableSortedMap.java,v 1.3 2003/12/03 12:27:36 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -65,14 +65,13 @@ import java.util.SortedMap;
import org.apache.commons.collections.Unmodifiable;
import org.apache.commons.collections.collection.UnmodifiableCollection;
import org.apache.commons.collections.map.UnmodifiableMap.UnmodifiableEntrySet;
import org.apache.commons.collections.set.UnmodifiableSet;
/**
* Decorates another <code>SortedMap</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/11/20 22:35:50 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:36 $
*
* @author Stephen Colebourne
*/
@ -98,7 +97,7 @@ public final class UnmodifiableSortedMap extends AbstractSortedMapDecorator impl
* @param map the map to decorate, must not be null
* @throws IllegalArgumentException if map is null
*/
protected UnmodifiableSortedMap(SortedMap map) {
private UnmodifiableSortedMap(SortedMap map) {
super(map);
}
@ -121,7 +120,7 @@ public final class UnmodifiableSortedMap extends AbstractSortedMapDecorator impl
public Set entrySet() {
Set set = super.entrySet();
return new UnmodifiableEntrySet(set);
return UnmodifiableEntrySet.decorate(set);
}
public Set keySet() {

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/set/UnmodifiableSet.java,v 1.2 2003/12/03 11:19:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/set/UnmodifiableSet.java,v 1.3 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -68,11 +68,11 @@ import org.apache.commons.collections.iterators.UnmodifiableIterator;
* Decorates another <code>Set</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/03 11:19:10 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
public class UnmodifiableSet extends AbstractSetDecorator implements Unmodifiable {
public final class UnmodifiableSet extends AbstractSetDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable set.
@ -94,7 +94,7 @@ public class UnmodifiableSet extends AbstractSetDecorator implements Unmodifiabl
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
protected UnmodifiableSet(Set set) {
private UnmodifiableSet(Set set) {
super(set);
}

View File

@ -1,5 +1,5 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/set/UnmodifiableSortedSet.java,v 1.2 2003/12/03 11:19:10 scolebourne Exp $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/set/UnmodifiableSortedSet.java,v 1.3 2003/12/03 12:27:37 scolebourne Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@ -68,11 +68,11 @@ import org.apache.commons.collections.iterators.UnmodifiableIterator;
* Decorates another <code>SortedSet</code> to ensure it can't be altered.
*
* @since Commons Collections 3.0
* @version $Revision: 1.2 $ $Date: 2003/12/03 11:19:10 $
* @version $Revision: 1.3 $ $Date: 2003/12/03 12:27:37 $
*
* @author Stephen Colebourne
*/
public class UnmodifiableSortedSet extends AbstractSortedSetDecorator implements Unmodifiable {
public final class UnmodifiableSortedSet extends AbstractSortedSetDecorator implements Unmodifiable {
/**
* Factory method to create an unmodifiable set.
@ -94,7 +94,7 @@ public class UnmodifiableSortedSet extends AbstractSortedSetDecorator implements
* @param set the set to decorate, must not be null
* @throws IllegalArgumentException if set is null
*/
protected UnmodifiableSortedSet(SortedSet set) {
private UnmodifiableSortedSet(SortedSet set) {
super(set);
}