Removed bounded decorators from the source. We might resurrect these

after the 2.1 release, if we can address their difficulties.

PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130798 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
pjack 2002-08-18 20:11:38 +00:00
parent aee5310ddd
commit 901deeeeff
10 changed files with 31 additions and 554 deletions

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BagUtils.java,v 1.4 2002/08/17 21:10:46 pjack Exp $
* $Revision: 1.4 $
* $Date: 2002/08/17 21:10:46 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BagUtils.java,v 1.5 2002/08/18 20:11:37 pjack Exp $
* $Revision: 1.5 $
* $Date: 2002/08/18 20:11:37 $
*
* ====================================================================
*
@ -71,7 +71,7 @@ import java.util.Set;
* and {@link SortedBag} instances.<P>
*
* @author Paul Jack
* @version $Id: BagUtils.java,v 1.4 2002/08/17 21:10:46 pjack Exp $
* @version $Id: BagUtils.java,v 1.5 2002/08/18 20:11:37 pjack Exp $
* @since 2.1
*/
public class BagUtils {
@ -175,58 +175,6 @@ public class BagUtils {
}
static class BoundedBag extends CollectionUtils.CollectionWrapper
implements Bag {
final protected int maxSize;
public BoundedBag(Bag bag, int maxSize) {
super(bag);
if (maxSize < 0) {
throw new IllegalArgumentException("maxSize must be nonnegative.");
}
this.maxSize = maxSize;
}
public boolean add(Object o) {
validate(1);
return collection.add(o);
}
public boolean addAll(Collection c) {
validate(c.size());
return collection.addAll(c);
}
public boolean add(Object o, int count) {
validate(count);
return getBag().add(o, count);
}
public boolean remove(Object o, int count) {
return getBag().remove(o, count);
}
public Set uniqueSet() {
return getBag().uniqueSet();
}
public int getCount(Object o) {
return getBag().getCount(o);
}
private Bag getBag() {
return (Bag)collection;
}
protected void validate(int delta) {
if (delta + size() > maxSize) {
throw new IllegalStateException("Maximum size reached.");
}
}
}
static class PredicatedSortedBag extends PredicatedBag
implements SortedBag {
@ -304,32 +252,6 @@ public class BagUtils {
}
static class BoundedSortedBag extends BoundedBag
implements SortedBag {
public BoundedSortedBag(SortedBag bag, int maxSize) {
super(bag, maxSize);
}
public Comparator comparator() {
return getSortedBag().comparator();
}
public Object first() {
return getSortedBag().first();
}
public Object last() {
return getSortedBag().last();
}
private SortedBag getSortedBag() {
return (SortedBag)collection;
}
}
/**
* Returns a predicated bag backed by the given bag. Only objects
* that pass the test in the given predicate can be added to the bag.
@ -388,23 +310,6 @@ public class BagUtils {
}
/**
* Returns a bounded bag backed by the given bag.
* New elements may only be added to the returned bag if its
* size is less than the specified maximum; otherwise, an
* {@link IllegalStateException} will be thrown.
*
* @param b the bag whose size to bind
* @param maxSize the maximum size of the returned bag
* @return a bounded bag
*/
public static Bag boundedBag(Bag b, int maxSize) {
return new BoundedBag(b, maxSize);
}
/**
* Returns a predicated sorted bag backed by the given sorted bag.
* Only objects that pass the test in the given predicate can be
@ -465,19 +370,4 @@ public class BagUtils {
}
/**
* Returns a bounded sorted bag backed by the given sorted bag.
* New elements may only be added to the returned bag if its
* size is less than the specified maximum; otherwise, an
* {@link IllegalStateException} will be thrown.
*
* @param b the bag whose size to bind
* @param maxSize the maximum size of the returned bag
* @return a bounded bag
*/
public static SortedBag boundedSortedBag(SortedBag b, int maxSize) {
return new BoundedSortedBag(b, maxSize);
}
}

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BufferUtils.java,v 1.6 2002/08/15 20:04:31 pjack Exp $
* $Revision: 1.6 $
* $Date: 2002/08/15 20:04:31 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BufferUtils.java,v 1.7 2002/08/18 20:11:37 pjack Exp $
* $Revision: 1.7 $
* $Date: 2002/08/18 20:11:37 $
*
* ====================================================================
*
@ -69,7 +69,7 @@ import java.util.Iterator;
* Contains static utility methods for operating on {@link Buffer} objects.
*
* @author Paul Jack
* @version $Id: BufferUtils.java,v 1.6 2002/08/15 20:04:31 pjack Exp $
* @version $Id: BufferUtils.java,v 1.7 2002/08/18 20:11:37 pjack Exp $
* @since 2.1
*/
public class BufferUtils {
@ -181,20 +181,6 @@ public class BufferUtils {
}
/**
* Returns a bounded buffer backed by the given buffer. New elements
* may only be added to the returned buffer if its size is less than
* the specified maximum; otherwise, an {@link IllegalStateException}
* will be thrown.
*
* @param buf the buffer whose size to bind
* @param maxSize the maximum size of the returned buffer
* @return a bounded buffer
*/
public static Buffer boundedBuffer(Buffer buf, int maxSize) {
return new BoundedBuffer(buf, maxSize);
}
private static class SynchronizedBuffer
extends CollectionUtils.SynchronizedCollection
@ -252,22 +238,4 @@ public class BufferUtils {
}
private static class BoundedBuffer
extends CollectionUtils.BoundedCollection
implements Buffer {
public BoundedBuffer(Buffer b, int maxSize) {
super(b, maxSize);
}
public Object get() {
return ((Buffer)collection).get();
}
public Object remove() {
return ((Buffer)collection).remove();
}
}
}

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.14 2002/08/18 15:26:20 scolebourne Exp $
* $Revision: 1.14 $
* $Date: 2002/08/18 15:26:20 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/CollectionUtils.java,v 1.15 2002/08/18 20:11:37 pjack Exp $
* $Revision: 1.15 $
* $Date: 2002/08/18 20:11:37 $
*
* ====================================================================
*
@ -83,7 +83,7 @@ import org.apache.commons.collections.iterators.EnumerationIterator;
* @author Rodney Waldhoff
* @author Paul Jack
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @version $Id: CollectionUtils.java,v 1.14 2002/08/18 15:26:20 scolebourne Exp $
* @version $Id: CollectionUtils.java,v 1.15 2002/08/18 20:11:37 pjack Exp $
*/
public class CollectionUtils {
@ -877,47 +877,6 @@ public class CollectionUtils {
}
static class BoundedCollection extends CollectionWrapper {
final protected int maxSize;
public BoundedCollection(Collection c, int maxSize) {
super(c);
if (maxSize < 0) {
throw new IllegalArgumentException("maxSize must be nonnegative.");
}
this.maxSize = maxSize;
}
public boolean add(Object o) {
if (!collection.contains(o)) {
validate(1);
}
return collection.add(o);
}
public boolean addAll(Collection c) {
int delta = 0;
for (Iterator iter = c.iterator(); iter.hasNext(); ) {
if (!collection.contains(iter.next())) delta++;
}
validate(delta);
return collection.addAll(c);
}
protected void validate(int delta) {
if (delta + size() > maxSize) {
throw new IllegalStateException("Maximum size reached.");
}
}
}
static class SynchronizedCollection {
final protected Collection collection;

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/ListUtils.java,v 1.9 2002/08/17 21:10:46 pjack Exp $
* $Revision: 1.9 $
* $Date: 2002/08/17 21:10:46 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/ListUtils.java,v 1.10 2002/08/18 20:11:37 pjack Exp $
* $Revision: 1.10 $
* $Date: 2002/08/18 20:11:37 $
*
* ====================================================================
*
@ -357,89 +357,6 @@ public class ListUtils
}
static class BoundedList extends CollectionUtils.CollectionWrapper
implements List {
final protected int maxSize;
public BoundedList(List list, int maxSize) {
super(list);
if (maxSize < 0) {
throw new IllegalArgumentException("maxSize must be nonnegative.");
}
this.maxSize = maxSize;
}
public boolean addAll(Collection c) {
validate(c.size());
return collection.addAll(c);
}
public boolean add(Object o) {
validate(1);
return collection.add(o);
}
public boolean addAll(int i, Collection c) {
validate(c.size());
return getList().addAll(i, c);
}
public void add(int i, Object o) {
validate(1);
getList().add(i, o);
}
public Object get(int i) {
return getList().get(i);
}
public Object set(int i, Object o) {
return getList().set(i, o);
}
public Object remove(int i) {
return getList().remove(i);
}
public int indexOf(Object o) {
return getList().indexOf(o);
}
public int lastIndexOf(Object o) {
return getList().lastIndexOf(o);
}
public ListIterator listIterator() {
return listIterator(0);
}
public ListIterator listIterator(int i) {
return new ListIteratorWrapper(getList().listIterator(i)) {
public void add(Object o) {
validate(1);
iterator.add(o);
}
};
}
public List subList(int i1, int i2) {
return getList().subList(i1, i2);
}
private List getList() {
return (List)collection;
}
private void validate(int delta) {
if (delta + size() > maxSize) {
throw new IllegalStateException("Maximum size reached.");
}
}
}
static class LazyList extends CollectionUtils.CollectionWrapper
implements List {
@ -596,19 +513,4 @@ public class ListUtils
}
/**
* Returns a bounded list backed by the given list.
* New elements may only be added to the returned list if its
* size is less than the specified maximum; otherwise, an
* {@link IllegalStateException} will be thrown.
*
* @param list the list whose size to bind
* @param maxSize the maximum size of the returned list
* @return a bounded list
*/
public static List boundedList(List list, int maxSize) {
return new BoundedList(list, maxSize);
}
}

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/MapUtils.java,v 1.10 2002/08/17 21:10:46 pjack Exp $
* $Revision: 1.10 $
* $Date: 2002/08/17 21:10:46 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/MapUtils.java,v 1.11 2002/08/18 20:11:37 pjack Exp $
* $Revision: 1.11 $
* $Date: 2002/08/18 20:11:37 $
*
* ====================================================================
*
@ -859,44 +859,6 @@ public class MapUtils {
}
static class BoundedMap extends ProxyMap {
final protected int maxSize;
public BoundedMap(Map map, int maxSize) {
super(map);
if (map == null) {
throw new IllegalArgumentException("map may not be null.");
}
if (maxSize < 0) {
throw new IllegalArgumentException("maxSize must be nonnegative.");
}
this.maxSize = maxSize;
}
public Object put(Object key, Object value) {
if (!containsKey(key)) validate(1);
return map.put(key, value);
}
public void putAll(Map m) {
int delta = 0;
for (Iterator iter = m.keySet().iterator(); iter.hasNext(); ) {
if (!map.containsKey(iter.next())) delta++;
}
validate(delta);
map.putAll(m);
}
protected void validate(int delta) {
if (map.size() + delta > maxSize) {
throw new IllegalStateException("Maximum size reached.");
}
}
}
static class FixedSizeMap extends ProxyMap {
public FixedSizeMap(Map map) {
@ -1097,21 +1059,6 @@ public class MapUtils {
}
/**
* Returns a bounded map backed by the given map.
* New pairs may only be added to the returned map if its
* size is less than the specified maximum; otherwise, an
* {@link IllegalStateException} will be thrown.
*
* @param b the map whose size to bind
* @param maxSize the maximum size of the returned map
* @return a bounded map
*/
public static Map boundedMap(Map map, int maxSize) {
return new BoundedMap(map, maxSize);
}
/**
* Returns a fixed-sized map backed by the given map.
* Elements may not be added or removed from the returned map, but

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SetUtils.java,v 1.4 2002/08/17 21:10:46 pjack Exp $
* $Revision: 1.4 $
* $Date: 2002/08/17 21:10:46 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SetUtils.java,v 1.5 2002/08/18 20:11:37 pjack Exp $
* $Revision: 1.5 $
* $Date: 2002/08/18 20:11:37 $
*
* ====================================================================
*
@ -73,7 +73,7 @@ import java.util.SortedSet;
* and {@link SortedSet} instances.
*
* @author Paul Jack
* @version $Id: SetUtils.java,v 1.4 2002/08/17 21:10:46 pjack Exp $
* @version $Id: SetUtils.java,v 1.5 2002/08/18 20:11:37 pjack Exp $
* @since 2.1
*/
public class SetUtils {
@ -95,45 +95,6 @@ public class SetUtils {
}
static class BoundedSet extends CollectionUtils.CollectionWrapper
implements Set {
final protected int maxSize;
public BoundedSet(Set set, int maxSize) {
super(set);
if (maxSize < 0) {
throw new IllegalArgumentException("maxSize must be nonnegative.");
}
this.maxSize = maxSize;
}
public boolean add(Object o) {
if (!collection.contains(o)) {
validate(1);
}
return collection.add(o);
}
public boolean addAll(Collection c) {
int delta = 0;
for (Iterator iter = c.iterator(); iter.hasNext(); ) {
if (!collection.contains(iter.next())) delta++;
}
validate(delta);
return collection.addAll(c);
}
private void validate(int delta) {
if (delta + size() > maxSize) {
throw new IllegalStateException("Maximum size reached.");
}
}
}
static class PredicatedSortedSet extends PredicatedSet
implements SortedSet {
@ -190,20 +151,6 @@ public class SetUtils {
}
/**
* Returns a bounded set backed by the given set.
* New elements may only be added to the returned set if its
* size is less than the specified maximum; otherwise, an
* {@link IllegalStateException} will be thrown.
*
* @param set the set whose size to bind
* @param maxSize the maximum size of the returned set
* @return a bounded set
*/
public static Set boundedSet(Set set, int maxSize) {
return new BoundedSet(set, maxSize);
}
/**
* Returns a predicated sorted set backed by the given sorted set.

View File

@ -1,56 +0,0 @@
package org.apache.commons.collections;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public abstract class TestBoundedCollection extends BulkTest {
public TestBoundedCollection(String name) {
super(name);
}
public abstract Collection boundedCollection();
public void testIllegalAdd() {
Collection c = boundedCollection();
Integer i = new Integer(3);
try {
c.add(i);
fail("Collection should be full.");
} catch (IllegalStateException e) {
// expected
}
assertTrue("Collection shouldn't contain illegal element",
!c.contains(i));
}
public void testIllegalAddAll() {
Collection c = boundedCollection();
List elements = new ArrayList();
elements.add("one");
elements.add("two");
elements.add(new Integer(3));
elements.add("four");
try {
c.addAll(elements);
fail("Collection should be full.");
} catch (IllegalStateException e) {
// expected
}
assertTrue("Collection shouldn't contain illegal element",
!c.contains("one"));
assertTrue("Collection shouldn't contain illegal element",
!c.contains("two"));
assertTrue("Collection shouldn't contain illegal element",
!c.contains(new Integer(3)));
assertTrue("Collection shouldn't contain illegal element",
!c.contains("four"));
}
}

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestBufferUtils.java,v 1.1 2002/08/13 00:26:52 pjack Exp $
* $Revision: 1.1 $
* $Date: 2002/08/13 00:26:52 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestBufferUtils.java,v 1.2 2002/08/18 20:11:38 pjack Exp $
* $Revision: 1.2 $
* $Date: 2002/08/18 20:11:38 $
*
* ====================================================================
*
@ -121,38 +121,6 @@ public class TestBufferUtils extends BulkTest {
}
public BulkTest bulkTestBoundedBuffer() {
return new TestBoundedCollection("") {
public Collection boundedCollection() {
return BufferUtils.boundedBuffer(new ArrayStack(), 0);
}
public BulkTest bulkTestAll() {
return new TestCollection("") {
public Collection makeCollection() {
Object[] full = getFullElements();
Object[] other = getOtherElements();
int maxSize = full.length + other.length;
return BufferUtils.boundedBuffer(new ArrayStack(), maxSize);
}
public Collection makeConfirmedCollection() {
return new ArrayStack();
}
public Collection makeConfirmedFullCollection() {
ArrayStack list = new ArrayStack();
list.addAll(java.util.Arrays.asList(getFullElements()));
return list;
}
};
}
};
}
public BulkTest bulkTestUnmodifiableBuffer() {
return new TestCollection("") {
public boolean isAddSupported() {

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestListUtils.java,v 1.3 2002/08/15 20:09:38 pjack Exp $
* $Revision: 1.3 $
* $Date: 2002/08/15 20:09:38 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestListUtils.java,v 1.4 2002/08/18 20:11:38 pjack Exp $
* $Revision: 1.4 $
* $Date: 2002/08/18 20:11:38 $
*
* ====================================================================
*
@ -108,29 +108,6 @@ public class TestListUtils extends BulkTest {
}
public BulkTest bulkTestBoundedList() {
return new TestBoundedCollection("") {
public Collection boundedCollection() {
return ListUtils.boundedList(new ArrayList(), 0);
}
public BulkTest bulkTestAll() {
return new TestList("") {
public List makeEmptyList() {
Object[] full = getFullElements();
Object[] other = getOtherElements();
int maxSize = full.length * 2; // + other.length;
return ListUtils.boundedList(new ArrayList(), maxSize);
}
};
}
};
}
public void testLazyList() {
List list = ListUtils.lazyList(new ArrayList(), new Factory() {

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestSetUtils.java,v 1.1 2002/08/13 00:26:52 pjack Exp $
* $Revision: 1.1 $
* $Date: 2002/08/13 00:26:52 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestSetUtils.java,v 1.2 2002/08/18 20:11:38 pjack Exp $
* $Revision: 1.2 $
* $Date: 2002/08/18 20:11:38 $
*
* ====================================================================
*
@ -110,31 +110,6 @@ public class TestSetUtils extends BulkTest {
}
public BulkTest bulkTestBoundedSet() {
return new TestBoundedCollection("") {
public Collection boundedCollection() {
return SetUtils.boundedSet(new HashSet(), 0);
}
public BulkTest bulkTestAll() {
return new TestSet("") {
public Set makeEmptySet() {
Object[] full = getFullElements();
Object[] other = getOtherElements();
int maxSize = full.length + other.length;
return SetUtils.boundedSet(new HashSet(), maxSize);
}
};
}
};
}
}