diff --git a/src/java/org/apache/commons/collections/FastArrayList.java b/src/java/org/apache/commons/collections/FastArrayList.java index b585c30cf..50f5e6358 100644 --- a/src/java/org/apache/commons/collections/FastArrayList.java +++ b/src/java/org/apache/commons/collections/FastArrayList.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/FastArrayList.java,v 1.6 2002/08/10 00:49:45 pjack Exp $ - * $Revision: 1.6 $ - * $Date: 2002/08/10 00:49:45 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/FastArrayList.java,v 1.7 2002/08/13 04:34:08 pjack Exp $ + * $Revision: 1.7 $ + * $Date: 2002/08/13 04:34:08 $ * * ==================================================================== * @@ -66,6 +66,7 @@ package org.apache.commons.collections; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; +import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -107,7 +108,7 @@ import java.util.ListIterator; * * @since 1.0 * @author Craig R. McClanahan - * @version $Revision: 1.6 $ $Date: 2002/08/10 00:49:45 $ + * @version $Revision: 1.7 $ $Date: 2002/08/13 04:34:08 $ */ public class FastArrayList extends ArrayList { @@ -532,15 +533,11 @@ public class FastArrayList extends ArrayList { * failing due to concurrent modifications. */ public Iterator iterator() { - if (fast) { - return (list.iterator()); + return new ListIter(0); } else { - synchronized (list) { - return (list.iterator()); - } + return list.iterator(); } - } @@ -569,15 +566,11 @@ public class FastArrayList extends ArrayList { * See the implementation note on iterator(). */ public ListIterator listIterator() { - if (fast) { - return (list.listIterator()); + return new ListIter(0); } else { - synchronized (list) { - return (list.listIterator()); - } + return list.listIterator(); } - } @@ -591,15 +584,11 @@ public class FastArrayList extends ArrayList { * @exception IndexOutOfBoundsException if the index is out of range */ public ListIterator listIterator(int index) { - if (fast) { - return (list.listIterator(index)); + return new ListIter(index); } else { - synchronized (list) { - return (list.listIterator(index)); - } + return list.listIterator(index); } - } @@ -762,15 +751,11 @@ public class FastArrayList extends ArrayList { * @exception IndexOutOfBoundsException if an index is out of range */ public List subList(int fromIndex, int toIndex) { - if (fast) { - return (list.subList(fromIndex, toIndex)); + return new SubList(fromIndex, toIndex); } else { - synchronized (list) { - return (list.subList(fromIndex, toIndex)); - } + return list.subList(fromIndex, toIndex); } - } @@ -851,4 +836,507 @@ public class FastArrayList extends ArrayList { } + + private class SubList implements List { + + private int first; + private int last; + private List expected; + + + public SubList(int first, int last) { + this.first = first; + this.last = last; + this.expected = list; + } + + private List get(List l) { + if (list != expected) { + throw new ConcurrentModificationException(); + } + return l.subList(first, last); + } + + public void clear() { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + get(temp).clear(); + last = first; + list = temp; + expected = temp; + } + } else { + synchronized (list) { + get(expected).clear(); + } + } + } + + public boolean remove(Object o) { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + boolean r = get(temp).remove(o); + if (r) last--; + list = temp; + expected = temp; + return r; + } + } else { + synchronized (list) { + return get(expected).remove(o); + } + } + } + + public boolean removeAll(Collection o) { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + List sub = get(temp); + boolean r = sub.removeAll(o); + if (r) last = first + sub.size(); + list = temp; + expected = temp; + return r; + } + } else { + synchronized (list) { + return get(expected).removeAll(o); + } + } + } + + public boolean retainAll(Collection o) { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + List sub = get(temp); + boolean r = sub.retainAll(o); + if (r) last = first + sub.size(); + list = temp; + expected = temp; + return r; + } + } else { + synchronized (list) { + return get(expected).retainAll(o); + } + } + } + + public int size() { + if (fast) { + return get(expected).size(); + } else { + synchronized (list) { + return get(expected).size(); + } + } + } + + + public boolean isEmpty() { + if (fast) { + return get(expected).isEmpty(); + } else { + synchronized (list) { + return get(expected).isEmpty(); + } + } + } + + public boolean contains(Object o) { + if (fast) { + return get(expected).contains(o); + } else { + synchronized (list) { + return get(expected).contains(o); + } + } + } + + public boolean containsAll(Collection o) { + if (fast) { + return get(expected).containsAll(o); + } else { + synchronized (list) { + return get(expected).containsAll(o); + } + } + } + + public Object[] toArray(Object[] o) { + if (fast) { + return get(expected).toArray(o); + } else { + synchronized (list) { + return get(expected).toArray(o); + } + } + } + + public Object[] toArray() { + if (fast) { + return get(expected).toArray(); + } else { + synchronized (list) { + return get(expected).toArray(); + } + } + } + + + public boolean equals(Object o) { + if (o == this) return true; + if (fast) { + return get(expected).equals(o); + } else { + synchronized (list) { + return get(expected).equals(o); + } + } + } + + public int hashCode() { + if (fast) { + return get(expected).hashCode(); + } else { + synchronized (list) { + return get(expected).hashCode(); + } + } + } + + public boolean add(Object o) { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + boolean r = get(temp).add(o); + if (r) last++; + list = temp; + expected = temp; + return r; + } + } else { + synchronized (list) { + return get(expected).add(o); + } + } + } + + public boolean addAll(Collection o) { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + boolean r = get(temp).addAll(o); + if (r) last += o.size(); + list = temp; + expected = temp; + return r; + } + } else { + synchronized (list) { + return get(expected).addAll(o); + } + } + } + + public void add(int i, Object o) { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + get(temp).add(i, o); + last++; + list = temp; + expected = temp; + } + } else { + synchronized (list) { + get(expected).add(i, o); + } + } + } + + public boolean addAll(int i, Collection o) { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + boolean r = get(temp).addAll(i, o); + list = temp; + if (r) last += o.size(); + expected = temp; + return r; + } + } else { + synchronized (list) { + return get(expected).addAll(i, o); + } + } + } + + public Object remove(int i) { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + Object o = get(temp).remove(i); + last--; + list = temp; + expected = temp; + return o; + } + } else { + synchronized (list) { + return get(expected).remove(i); + } + } + } + + public Object set(int i, Object a) { + if (fast) { + synchronized (FastArrayList.this) { + ArrayList temp = (ArrayList) list.clone(); + Object o = get(temp).set(i, a); + list = temp; + expected = temp; + return o; + } + } else { + synchronized (list) { + return get(expected).set(i, a); + } + } + } + + + public Iterator iterator() { + return new SubListIter(0); + } + + public ListIterator listIterator() { + return new SubListIter(0); + } + + public ListIterator listIterator(int i) { + return new SubListIter(i); + } + + + public Object get(int i) { + if (fast) { + return get(expected).get(i); + } else { + synchronized (list) { + return get(expected).get(i); + } + } + } + + public int indexOf(Object o) { + if (fast) { + return get(expected).indexOf(o); + } else { + synchronized (list) { + return get(expected).indexOf(o); + } + } + } + + + public int lastIndexOf(Object o) { + if (fast) { + return get(expected).lastIndexOf(o); + } else { + synchronized (list) { + return get(expected).lastIndexOf(o); + } + } + } + + + public List subList(int f, int l) { + if (list != expected) { + throw new ConcurrentModificationException(); + } + return new SubList(first + f, f + l); + } + + + private class SubListIter implements ListIterator { + + private List expected; + private ListIterator iter; + private int lastReturnedIndex = -1; + + + public SubListIter(int i) { + this.expected = list; + this.iter = SubList.this.get(expected).listIterator(i); + } + + private void checkMod() { + if (list != expected) { + throw new ConcurrentModificationException(); + } + } + + List get() { + return SubList.this.get(expected); + } + + public boolean hasNext() { + checkMod(); + return iter.hasNext(); + } + + public Object next() { + checkMod(); + lastReturnedIndex = iter.nextIndex(); + return iter.next(); + } + + public boolean hasPrevious() { + checkMod(); + return iter.hasPrevious(); + } + + public Object previous() { + checkMod(); + lastReturnedIndex = iter.previousIndex(); + return iter.previous(); + } + + public int previousIndex() { + checkMod(); + return iter.previousIndex(); + } + + public int nextIndex() { + checkMod(); + return iter.nextIndex(); + } + + public void remove() { + checkMod(); + if (lastReturnedIndex < 0) { + throw new IllegalStateException(); + } + get().remove(lastReturnedIndex); + last--; + expected = list; + iter = get().listIterator(previousIndex()); + lastReturnedIndex = -1; + } + + public void set(Object o) { + checkMod(); + if (lastReturnedIndex < 0) { + throw new IllegalStateException(); + } + get().set(lastReturnedIndex, o); + expected = list; + iter = get().listIterator(previousIndex() + 1); + } + + public void add(Object o) { + checkMod(); + int i = nextIndex(); + get().add(i, o); + last++; + iter = get().listIterator(i + 1); + lastReturnedIndex = 1; + } + + } + + + } + + + + private class ListIter implements ListIterator { + + private List expected; + private ListIterator iter; + private int lastReturnedIndex = -1; + + + public ListIter(int i) { + this.expected = list; + this.iter = get().listIterator(i); + } + + private void checkMod() { + if (list != expected) { + throw new ConcurrentModificationException(); + } + } + + List get() { + return expected; + } + + public boolean hasNext() { + checkMod(); + return iter.hasNext(); + } + + public Object next() { + checkMod(); + lastReturnedIndex = iter.nextIndex(); + return iter.next(); + } + + public boolean hasPrevious() { + checkMod(); + return iter.hasPrevious(); + } + + public Object previous() { + checkMod(); + lastReturnedIndex = iter.previousIndex(); + return iter.previous(); + } + + public int previousIndex() { + checkMod(); + return iter.previousIndex(); + } + + public int nextIndex() { + checkMod(); + return iter.nextIndex(); + } + + public void remove() { + checkMod(); + if (lastReturnedIndex < 0) { + throw new IllegalStateException(); + } + get().remove(lastReturnedIndex); + expected = list; + iter = get().listIterator(previousIndex()); + lastReturnedIndex = -1; + } + + public void set(Object o) { + checkMod(); + if (lastReturnedIndex < 0) { + throw new IllegalStateException(); + } + get().set(lastReturnedIndex, o); + expected = list; + iter = get().listIterator(previousIndex() + 1); + } + + public void add(Object o) { + checkMod(); + int i = nextIndex(); + get().add(i, o); + iter = get().listIterator(i + 1); + lastReturnedIndex = 1; + } + + } } diff --git a/src/java/org/apache/commons/collections/FastHashMap.java b/src/java/org/apache/commons/collections/FastHashMap.java index e472320a6..321c298cb 100644 --- a/src/java/org/apache/commons/collections/FastHashMap.java +++ b/src/java/org/apache/commons/collections/FastHashMap.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/FastHashMap.java,v 1.7 2002/08/10 00:49:45 pjack Exp $ - * $Revision: 1.7 $ - * $Date: 2002/08/10 00:49:45 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/FastHashMap.java,v 1.8 2002/08/13 04:34:08 pjack Exp $ + * $Revision: 1.8 $ + * $Date: 2002/08/13 04:34:08 $ * * ==================================================================== * @@ -65,6 +65,7 @@ package org.apache.commons.collections; import java.io.Serializable; import java.util.Collection; +import java.util.ConcurrentModificationException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -108,7 +109,7 @@ import java.util.Set; * * @since 1.0 * @author Craig R. McClanahan - * @version $Revision: 1.7 $ $Date: 2002/08/10 00:49:45 $ + * @version $Revision: 1.8 $ $Date: 2002/08/13 04:34:08 $ */ public class FastHashMap extends HashMap { @@ -280,15 +281,7 @@ public class FastHashMap extends HashMap { * element in the returned collection is a Map.Entry. */ public Set entrySet() { - - if (fast) { - return (map.entrySet()); - } else { - synchronized (map) { - return (map.entrySet()); - } - } - + return new EntrySet(); } @@ -418,15 +411,7 @@ public class FastHashMap extends HashMap { * Return a set view of the keys contained in this map. */ public Set keySet() { - - if (fast) { - return (map.keySet()); - } else { - synchronized (map) { - return (map.keySet()); - } - } - + return new KeySet(); } @@ -523,16 +508,257 @@ public class FastHashMap extends HashMap { * Return a collection view of the values contained in this map. */ public Collection values() { - - if (fast) { - return (map.values()); - } else { - synchronized (map) { - return (map.values()); - } - } - + return new Values(); } + private abstract class CollectionView implements Collection { + + public CollectionView() { + } + + protected abstract Collection get(Map map); + protected abstract Object iteratorNext(Map.Entry entry); + + + public void clear() { + if (fast) { + synchronized (FastHashMap.this) { + HashMap temp = (HashMap) map.clone(); + get(temp).clear(); + map = temp; + } + } else { + synchronized (map) { + get(map).clear(); + } + } + } + + public boolean remove(Object o) { + if (fast) { + synchronized (FastHashMap.this) { + HashMap temp = (HashMap) map.clone(); + boolean r = get(temp).remove(o); + map = temp; + return r; + } + } else { + synchronized (map) { + return get(map).remove(o); + } + } + } + + public boolean removeAll(Collection o) { + if (fast) { + synchronized (FastHashMap.this) { + HashMap temp = (HashMap) map.clone(); + boolean r = get(temp).removeAll(o); + map = temp; + return r; + } + } else { + synchronized (map) { + return get(map).removeAll(o); + } + } + } + + public boolean retainAll(Collection o) { + if (fast) { + synchronized (FastHashMap.this) { + HashMap temp = (HashMap) map.clone(); + boolean r = get(temp).retainAll(o); + map = temp; + return r; + } + } else { + synchronized (map) { + return get(map).retainAll(o); + } + } + } + + public int size() { + if (fast) { + return get(map).size(); + } else { + synchronized (map) { + return get(map).size(); + } + } + } + + + public boolean isEmpty() { + if (fast) { + return get(map).isEmpty(); + } else { + synchronized (map) { + return get(map).isEmpty(); + } + } + } + + public boolean contains(Object o) { + if (fast) { + return get(map).contains(o); + } else { + synchronized (map) { + return get(map).contains(o); + } + } + } + + public boolean containsAll(Collection o) { + if (fast) { + return get(map).containsAll(o); + } else { + synchronized (map) { + return get(map).containsAll(o); + } + } + } + + public Object[] toArray(Object[] o) { + if (fast) { + return get(map).toArray(o); + } else { + synchronized (map) { + return get(map).toArray(o); + } + } + } + + public Object[] toArray() { + if (fast) { + return get(map).toArray(); + } else { + synchronized (map) { + return get(map).toArray(); + } + } + } + + + public boolean equals(Object o) { + if (o == this) return true; + if (fast) { + return get(map).equals(o); + } else { + synchronized (map) { + return get(map).equals(o); + } + } + } + + public int hashCode() { + if (fast) { + return get(map).hashCode(); + } else { + synchronized (map) { + return get(map).hashCode(); + } + } + } + + public boolean add(Object o) { + throw new UnsupportedOperationException(); + } + + public boolean addAll(Collection c) { + throw new UnsupportedOperationException(); + } + + public Iterator iterator() { + return new CollectionViewIterator(); + } + + private class CollectionViewIterator implements Iterator { + + private Map expected; + private Map.Entry lastReturned = null; + private Iterator iterator; + + public CollectionViewIterator() { + this.expected = map; + this.iterator = expected.entrySet().iterator(); + } + + public boolean hasNext() { + if (expected != map) { + throw new ConcurrentModificationException(); + } + return iterator.hasNext(); + } + + public Object next() { + if (expected != map) { + throw new ConcurrentModificationException(); + } + lastReturned = (Map.Entry)iterator.next(); + return iteratorNext(lastReturned); + } + + public void remove() { + if (lastReturned == null) { + throw new IllegalStateException(); + } + if (fast) { + synchronized (FastHashMap.this) { + if (expected != map) { + throw new ConcurrentModificationException(); + } + FastHashMap.this.remove(lastReturned.getKey()); + lastReturned = null; + expected = map; + } + } else { + iterator.remove(); + lastReturned = null; + } + } + } + } + + + private class KeySet extends CollectionView implements Set { + + protected Collection get(Map map) { + return map.keySet(); + } + + protected Object iteratorNext(Map.Entry entry) { + return entry.getKey(); + } + + } + + + private class Values extends CollectionView { + + protected Collection get(Map map) { + return map.values(); + } + + protected Object iteratorNext(Map.Entry entry) { + return entry.getValue(); + } + } + + + private class EntrySet extends CollectionView implements Set { + + protected Collection get(Map map) { + return map.entrySet(); + } + + + protected Object iteratorNext(Map.Entry entry) { + return entry; + } + + } + } diff --git a/src/java/org/apache/commons/collections/FastTreeMap.java b/src/java/org/apache/commons/collections/FastTreeMap.java index e253f2f5f..cd7c0a3c6 100644 --- a/src/java/org/apache/commons/collections/FastTreeMap.java +++ b/src/java/org/apache/commons/collections/FastTreeMap.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/FastTreeMap.java,v 1.7 2002/08/10 00:49:45 pjack Exp $ - * $Revision: 1.7 $ - * $Date: 2002/08/10 00:49:45 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/FastTreeMap.java,v 1.8 2002/08/13 04:34:08 pjack Exp $ + * $Revision: 1.8 $ + * $Date: 2002/08/13 04:34:08 $ * * ==================================================================== * @@ -66,6 +66,7 @@ package org.apache.commons.collections; import java.io.Serializable; import java.util.Collection; import java.util.Comparator; +import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; @@ -110,7 +111,7 @@ import java.util.TreeMap; * * @since 1.0 * @author Craig R. McClanahan - * @version $Revision: 1.7 $ $Date: 2002/08/10 00:49:45 $ + * @version $Revision: 1.8 $ $Date: 2002/08/13 04:34:08 $ */ public class FastTreeMap extends TreeMap { @@ -300,15 +301,7 @@ public class FastTreeMap extends TreeMap { * element in the returned collection is a Map.Entry. */ public Set entrySet() { - - if (fast) { - return (map.entrySet()); - } else { - synchronized (map) { - return (map.entrySet()); - } - } - + return new EntrySet(); } @@ -473,15 +466,7 @@ public class FastTreeMap extends TreeMap { * Return a set view of the keys contained in this map. */ public Set keySet() { - - if (fast) { - return (map.keySet()); - } else { - synchronized (map) { - return (map.keySet()); - } - } - + return new KeySet(); } @@ -633,16 +618,259 @@ public class FastTreeMap extends TreeMap { * Return a collection view of the values contained in this map. */ public Collection values() { - - if (fast) { - return (map.values()); - } else { - synchronized (map) { - return (map.values()); - } - } - + return new Values(); } + + private abstract class CollectionView implements Collection { + + public CollectionView() { + } + + protected abstract Collection get(Map map); + protected abstract Object iteratorNext(Map.Entry entry); + + + public void clear() { + if (fast) { + synchronized (FastTreeMap.this) { + TreeMap temp = (TreeMap) map.clone(); + get(temp).clear(); + map = temp; + } + } else { + synchronized (map) { + get(map).clear(); + } + } + } + + public boolean remove(Object o) { + if (fast) { + synchronized (FastTreeMap.this) { + TreeMap temp = (TreeMap) map.clone(); + boolean r = get(temp).remove(o); + map = temp; + return r; + } + } else { + synchronized (map) { + return get(map).remove(o); + } + } + } + + public boolean removeAll(Collection o) { + if (fast) { + synchronized (FastTreeMap.this) { + TreeMap temp = (TreeMap) map.clone(); + boolean r = get(temp).removeAll(o); + map = temp; + return r; + } + } else { + synchronized (map) { + return get(map).removeAll(o); + } + } + } + + public boolean retainAll(Collection o) { + if (fast) { + synchronized (FastTreeMap.this) { + TreeMap temp = (TreeMap) map.clone(); + boolean r = get(temp).retainAll(o); + map = temp; + return r; + } + } else { + synchronized (map) { + return get(map).retainAll(o); + } + } + } + + public int size() { + if (fast) { + return get(map).size(); + } else { + synchronized (map) { + return get(map).size(); + } + } + } + + + public boolean isEmpty() { + if (fast) { + return get(map).isEmpty(); + } else { + synchronized (map) { + return get(map).isEmpty(); + } + } + } + + public boolean contains(Object o) { + if (fast) { + return get(map).contains(o); + } else { + synchronized (map) { + return get(map).contains(o); + } + } + } + + public boolean containsAll(Collection o) { + if (fast) { + return get(map).containsAll(o); + } else { + synchronized (map) { + return get(map).containsAll(o); + } + } + } + + public Object[] toArray(Object[] o) { + if (fast) { + return get(map).toArray(o); + } else { + synchronized (map) { + return get(map).toArray(o); + } + } + } + + public Object[] toArray() { + if (fast) { + return get(map).toArray(); + } else { + synchronized (map) { + return get(map).toArray(); + } + } + } + + + public boolean equals(Object o) { + if (o == this) return true; + if (fast) { + return get(map).equals(o); + } else { + synchronized (map) { + return get(map).equals(o); + } + } + } + + public int hashCode() { + if (fast) { + return get(map).hashCode(); + } else { + synchronized (map) { + return get(map).hashCode(); + } + } + } + + public boolean add(Object o) { + throw new UnsupportedOperationException(); + } + + public boolean addAll(Collection c) { + throw new UnsupportedOperationException(); + } + + public Iterator iterator() { + return new CollectionViewIterator(); + } + + private class CollectionViewIterator implements Iterator { + + private Map expected; + private Map.Entry lastReturned = null; + private Iterator iterator; + + public CollectionViewIterator() { + this.expected = map; + this.iterator = expected.entrySet().iterator(); + } + + public boolean hasNext() { + if (expected != map) { + throw new ConcurrentModificationException(); + } + return iterator.hasNext(); + } + + public Object next() { + if (expected != map) { + throw new ConcurrentModificationException(); + } + lastReturned = (Map.Entry)iterator.next(); + return iteratorNext(lastReturned); + } + + public void remove() { + if (lastReturned == null) { + throw new IllegalStateException(); + } + if (fast) { + synchronized (FastTreeMap.this) { + if (expected != map) { + throw new ConcurrentModificationException(); + } + FastTreeMap.this.remove(lastReturned.getKey()); + lastReturned = null; + expected = map; + } + } else { + iterator.remove(); + lastReturned = null; + } + } + } + } + + + private class KeySet extends CollectionView implements Set { + + protected Collection get(Map map) { + return map.keySet(); + } + + protected Object iteratorNext(Map.Entry entry) { + return entry.getKey(); + } + + } + + + private class Values extends CollectionView { + + protected Collection get(Map map) { + return map.values(); + } + + protected Object iteratorNext(Map.Entry entry) { + return entry.getValue(); + } + } + + + private class EntrySet extends CollectionView implements Set { + + protected Collection get(Map map) { + return map.entrySet(); + } + + + protected Object iteratorNext(Map.Entry entry) { + return entry; + } + + } + + } diff --git a/src/test/org/apache/commons/collections/TestFastArrayList1.java b/src/test/org/apache/commons/collections/TestFastArrayList1.java index 1de0c4e72..81c619904 100644 --- a/src/test/org/apache/commons/collections/TestFastArrayList1.java +++ b/src/test/org/apache/commons/collections/TestFastArrayList1.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastArrayList1.java,v 1.2 2002/06/21 03:33:28 mas Exp $ - * $Revision: 1.2 $ - * $Date: 2002/06/21 03:33:28 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastArrayList1.java,v 1.3 2002/08/13 04:34:09 pjack Exp $ + * $Revision: 1.3 $ + * $Date: 2002/08/13 04:34:09 $ * * ==================================================================== * @@ -71,7 +71,7 @@ import java.util.List; * Test FastArrayList implementation in fast mode. * * @author Jason van Zyl - * @version $Id: TestFastArrayList1.java,v 1.2 2002/06/21 03:33:28 mas Exp $ + * @version $Id: TestFastArrayList1.java,v 1.3 2002/08/13 04:34:09 pjack Exp $ */ public class TestFastArrayList1 extends TestFastArrayList { @@ -93,14 +93,15 @@ public class TestFastArrayList1 extends TestFastArrayList public void setUp() { - list = (ArrayList) makeList(); + list = (ArrayList) makeEmptyList(); } - public List makeList() + public List makeEmptyList() { FastArrayList fal = new FastArrayList(); fal.setFast(true); return (fal); } + } diff --git a/src/test/org/apache/commons/collections/TestFastHashMap1.java b/src/test/org/apache/commons/collections/TestFastHashMap1.java index 31edd63b0..879db5300 100644 --- a/src/test/org/apache/commons/collections/TestFastHashMap1.java +++ b/src/test/org/apache/commons/collections/TestFastHashMap1.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastHashMap1.java,v 1.3 2002/06/18 05:35:58 mas Exp $ - * $Revision: 1.3 $ - * $Date: 2002/06/18 05:35:58 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastHashMap1.java,v 1.4 2002/08/13 04:34:09 pjack Exp $ + * $Revision: 1.4 $ + * $Date: 2002/08/13 04:34:09 $ * * ==================================================================== * @@ -71,7 +71,7 @@ import java.util.Map; * Test FastHashMap in fast mode. * * @author Jason van Zyl - * @version $Id: TestFastHashMap1.java,v 1.3 2002/06/18 05:35:58 mas Exp $ + * @version $Id: TestFastHashMap1.java,v 1.4 2002/08/13 04:34:09 pjack Exp $ */ public class TestFastHashMap1 extends TestFastHashMap { @@ -91,45 +91,15 @@ public class TestFastHashMap1 extends TestFastHashMap junit.textui.TestRunner.main(testCaseName); } - public Map makeMap() { + public Map makeEmptyMap() { FastHashMap fhm = new FastHashMap(); fhm.setFast(true); return (fhm); } - /** - * When the fast hash map is in fast mode, the underlying hash map is - * cloned on modification (i.e. on a put). Because of that, any - * previously existing entry set will be representing the old (pre-clone) - * map and will not reflect changes made to the map after the clone. So, - * we must override this test. - **/ - public void testEntrySetChangesWithMapPut() { - } - - /** - * When the fast hash map is in fast mode, the underlying hash map is - * cloned on modification (i.e. on a remove). Because of that, any - * previously existing entry set will be representing the old (pre-clone) - * map and will not reflect changes made to the map after the clone. So, - * we must override this test. - **/ - public void testEntrySetChangesWithMapRemove() { - } - - /** - * When the fast hash map is in fast mode, the underlying hash map is - * cloned on modification (i.e. on a put). Because of that, any - * previously existing entry set will be representing the old (pre-clone) - * map, so changes to the set will not be seen in the map. So, we must - * override this test. - **/ - public void testEntrySetRemoveCausesMapModification() { - } - public void setUp() { - map = (HashMap) makeMap(); + map = (HashMap) makeEmptyMap(); } } diff --git a/src/test/org/apache/commons/collections/TestFastTreeMap.java b/src/test/org/apache/commons/collections/TestFastTreeMap.java index 72875fb67..e7b6eb3c3 100644 --- a/src/test/org/apache/commons/collections/TestFastTreeMap.java +++ b/src/test/org/apache/commons/collections/TestFastTreeMap.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastTreeMap.java,v 1.7 2002/08/12 18:00:46 pjack Exp $ - * $Revision: 1.7 $ - * $Date: 2002/08/12 18:00:46 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastTreeMap.java,v 1.8 2002/08/13 04:34:09 pjack Exp $ + * $Revision: 1.8 $ + * $Date: 2002/08/13 04:34:09 $ * * ==================================================================== * @@ -69,7 +69,7 @@ import java.util.TreeMap; /** * @author Jason van Zyl - * @version $Id: TestFastTreeMap.java,v 1.7 2002/08/12 18:00:46 pjack Exp $ + * @version $Id: TestFastTreeMap.java,v 1.8 2002/08/13 04:34:09 pjack Exp $ */ public class TestFastTreeMap extends TestTreeMap { @@ -94,6 +94,10 @@ public class TestFastTreeMap extends TestTreeMap ftm.setFast(false); return (ftm); } + + public Map makeConfirmedEmptyMap() { + return new TreeMap(); + } /** * The comparator for the fast tree map does not support null keys. diff --git a/src/test/org/apache/commons/collections/TestFastTreeMap1.java b/src/test/org/apache/commons/collections/TestFastTreeMap1.java index 8ad4687fc..2617b31ad 100644 --- a/src/test/org/apache/commons/collections/TestFastTreeMap1.java +++ b/src/test/org/apache/commons/collections/TestFastTreeMap1.java @@ -1,7 +1,7 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastTreeMap1.java,v 1.3 2002/06/18 05:35:58 mas Exp $ - * $Revision: 1.3 $ - * $Date: 2002/06/18 05:35:58 $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastTreeMap1.java,v 1.4 2002/08/13 04:34:09 pjack Exp $ + * $Revision: 1.4 $ + * $Date: 2002/08/13 04:34:09 $ * * ==================================================================== * @@ -71,7 +71,7 @@ import java.util.TreeMap; * Test FastTreeMap in fast mode. * * @author Jason van Zyl - * @version $Id: TestFastTreeMap1.java,v 1.3 2002/06/18 05:35:58 mas Exp $ + * @version $Id: TestFastTreeMap1.java,v 1.4 2002/08/13 04:34:09 pjack Exp $ */ public class TestFastTreeMap1 extends TestFastTreeMap { @@ -91,7 +91,7 @@ public class TestFastTreeMap1 extends TestFastTreeMap junit.textui.TestRunner.main(testCaseName); } - public Map makeMap() { + public Map makeEmptyMap() { FastTreeMap ftm = new FastTreeMap(); ftm.setFast(true); return (ftm); @@ -99,36 +99,7 @@ public class TestFastTreeMap1 extends TestFastTreeMap public void setUp() { - map = (TreeMap) makeMap(); + map = (TreeMap) makeEmptyMap(); } - /** - * When the fast tree map is in fast mode, the underlying tree map is - * cloned on modification (i.e. on a put). Because of that, any - * previously existing entry set will be representing the old (pre-clone) - * map and will not reflect changes made to the map after the clone. So, - * we must override this test. - **/ - public void testMapEntrySetChangesWithMapPut() { - } - - /** - * When the fast tree map is in fast mode, the underlying tree map is - * cloned on modification (i.e. on a put). Because of that, any - * previously existing entry set will be representing the old (pre-clone) - * map and will not reflect changes made to the map after the clone. So, - * we must override this test. - **/ - public void testMapEntrySetChangesWithMapRemove() { - } - - /** - * When the fast tree map is in fast mode, the underlying tree map is - * cloned on modification (i.e. on a put). Because of that, any - * previously existing entry set will be representing the old (pre-clone) - * map, so changes to the set will not be seen in the map. So, we must - * override this test. - **/ - public void testMapEntrySetRemoveCausesMapModification() { - } }