You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by pj...@apache.org on 2002/08/18 22:11:38 UTC
cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestBufferUtils.java TestListUtils.java TestSetUtils.java TestBoundedCollection.java
pjack 2002/08/18 13:11:38
Modified: collections/src/java/org/apache/commons/collections
BagUtils.java BufferUtils.java CollectionUtils.java
ListUtils.java MapUtils.java SetUtils.java
collections/src/test/org/apache/commons/collections
TestBufferUtils.java TestListUtils.java
TestSetUtils.java
Removed: collections/src/test/org/apache/commons/collections
TestBoundedCollection.java
Log:
Removed bounded decorators from the source. We might resurrect these
after the 2.1 release, if we can address their difficulties.
Revision Changes Path
1.5 +4 -114 jakarta-commons/collections/src/java/org/apache/commons/collections/BagUtils.java
Index: BagUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/BagUtils.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BagUtils.java 17 Aug 2002 21:10:46 -0000 1.4
+++ BagUtils.java 18 Aug 2002 20:11:37 -0000 1.5
@@ -175,58 +175,6 @@
}
- 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 @@
}
- 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.
@@ -389,23 +311,6 @@
/**
- * 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
* added to the bag.
@@ -462,21 +367,6 @@
*/
public static SortedBag synchronizedSortedBag(SortedBag b) {
return new SynchronizedSortedBag(b);
- }
-
-
- /**
- * 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);
}
1.7 +4 -36 jakarta-commons/collections/src/java/org/apache/commons/collections/BufferUtils.java
Index: BufferUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/BufferUtils.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BufferUtils.java 15 Aug 2002 20:04:31 -0000 1.6
+++ BufferUtils.java 18 Aug 2002 20:11:37 -0000 1.7
@@ -181,20 +181,6 @@
}
- /**
- * 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
@@ -251,23 +237,5 @@
}
-
- 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();
- }
-
- }
}
1.15 +4 -45 jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java
Index: CollectionUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- CollectionUtils.java 18 Aug 2002 15:26:20 -0000 1.14
+++ CollectionUtils.java 18 Aug 2002 20:11:37 -0000 1.15
@@ -877,47 +877,6 @@
}
- 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;
1.10 +3 -101 jakarta-commons/collections/src/java/org/apache/commons/collections/ListUtils.java
Index: ListUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/ListUtils.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ListUtils.java 17 Aug 2002 21:10:46 -0000 1.9
+++ ListUtils.java 18 Aug 2002 20:11:37 -0000 1.10
@@ -357,89 +357,6 @@
}
- 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 {
@@ -593,21 +510,6 @@
*/
public static List fixedSizeList(List list) {
return new FixedSizeList(list);
- }
-
-
- /**
- * 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);
}
1.11 +3 -56 jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java
Index: MapUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/MapUtils.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MapUtils.java 17 Aug 2002 21:10:46 -0000 1.10
+++ MapUtils.java 18 Aug 2002 20:11:37 -0000 1.11
@@ -859,44 +859,6 @@
}
- 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) {
@@ -1094,21 +1056,6 @@
*/
public static Map predicatedMap(Map map, Predicate keyPred, Predicate valuePred) {
return new PredicatedMap(map, keyPred, valuePred);
- }
-
-
- /**
- * 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);
}
1.5 +4 -57 jakarta-commons/collections/src/java/org/apache/commons/collections/SetUtils.java
Index: SetUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SetUtils.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SetUtils.java 17 Aug 2002 21:10:46 -0000 1.4
+++ SetUtils.java 18 Aug 2002 20:11:37 -0000 1.5
@@ -95,45 +95,6 @@
}
- 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 {
@@ -189,20 +150,6 @@
return new PredicatedSet(set, p);
}
-
- /**
- * 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);
- }
/**
1.2 +2 -34 jakarta-commons/collections/src/test/org/apache/commons/collections/TestBufferUtils.java
Index: TestBufferUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestBufferUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestBufferUtils.java 13 Aug 2002 00:26:52 -0000 1.1
+++ TestBufferUtils.java 18 Aug 2002 20:11:38 -0000 1.2
@@ -121,38 +121,6 @@
}
- 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() {
1.4 +3 -26 jakarta-commons/collections/src/test/org/apache/commons/collections/TestListUtils.java
Index: TestListUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestListUtils.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestListUtils.java 15 Aug 2002 20:09:38 -0000 1.3
+++ TestListUtils.java 18 Aug 2002 20:11:38 -0000 1.4
@@ -108,29 +108,6 @@
}
-
- 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() {
1.2 +2 -27 jakarta-commons/collections/src/test/org/apache/commons/collections/TestSetUtils.java
Index: TestSetUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestSetUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestSetUtils.java 13 Aug 2002 00:26:52 -0000 1.1
+++ TestSetUtils.java 18 Aug 2002 20:11:38 -0000 1.2
@@ -110,31 +110,6 @@
}
-
- 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);
- }
-
- };
- }
- };
- }
-
-
-
-
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>