You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2017/07/11 17:53:49 UTC
[01/18] commons-collections git commit: merging serialization test
methods into the 1.x branch
Repository: commons-collections
Updated Branches:
refs/heads/collections_1_x_branch [created] 88d84e95e
merging serialization test methods into the 1.x branch
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130590 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/6a2c9bff
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/6a2c9bff
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/6a2c9bff
Branch: refs/heads/collections_1_x_branch
Commit: 6a2c9bff5d2130a06b077472a37c35d334725764
Parents: 7696ab2
Author: Morgan James Delagrange <mo...@apache.org>
Authored: Tue Feb 26 00:51:21 2002 +0000
Committer: Morgan James Delagrange <mo...@apache.org>
Committed: Tue Feb 26 00:51:21 2002 +0000
----------------------------------------------------------------------
.../apache/commons/collections/TestHashMap.java | 12 +-
.../apache/commons/collections/TestLRUMap.java | 12 +-
.../org/apache/commons/collections/TestMap.java | 953 ++++++++++++++++++-
.../commons/collections/TestMultiHashMap.java | 8 +-
.../apache/commons/collections/TestObject.java | 135 ++-
.../apache/commons/collections/TestTreeMap.java | 12 +-
6 files changed, 1053 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/6a2c9bff/src/test/org/apache/commons/collections/TestHashMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestHashMap.java b/src/test/org/apache/commons/collections/TestHashMap.java
index 84399a7..c28f788 100644
--- a/src/test/org/apache/commons/collections/TestHashMap.java
+++ b/src/test/org/apache/commons/collections/TestHashMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestHashMap.java,v 1.2 2001/07/14 23:33:27 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2001/07/14 23:33:27 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestHashMap.java,v 1.2.2.1 2002/02/26 00:51:21 morgand Exp $
+ * $Revision: 1.2.2.1 $
+ * $Date: 2002/02/26 00:51:21 $
*
* ====================================================================
*
@@ -69,7 +69,7 @@ import java.util.Map;
/**
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: TestHashMap.java,v 1.2 2001/07/14 23:33:27 craigmcc Exp $
+ * @version $Id: TestHashMap.java,v 1.2.2.1 2002/02/26 00:51:21 morgand Exp $
*/
public class TestHashMap extends TestMap
{
@@ -89,7 +89,7 @@ public class TestHashMap extends TestMap
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeMap() {
+ public Map makeEmptyMap() {
HashMap hm = new HashMap();
return (hm);
}
@@ -98,7 +98,7 @@ public class TestHashMap extends TestMap
public void setUp()
{
- map = (HashMap) makeMap();
+ map = (HashMap) makeEmptyMap();
}
public void testNewMap()
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/6a2c9bff/src/test/org/apache/commons/collections/TestLRUMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestLRUMap.java b/src/test/org/apache/commons/collections/TestLRUMap.java
index 3e9319a..091252b 100644
--- a/src/test/org/apache/commons/collections/TestLRUMap.java
+++ b/src/test/org/apache/commons/collections/TestLRUMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.11 2002/02/19 21:28:53 morgand Exp $
- * $Revision: 1.11 $
- * $Date: 2002/02/19 21:28:53 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.11.2.1 2002/02/26 00:51:21 morgand Exp $
+ * $Revision: 1.11.2.1 $
+ * $Date: 2002/02/26 00:51:21 $
*
* ====================================================================
*
@@ -76,7 +76,7 @@ import java.util.HashMap;
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author <a href="mailto:morgand@apache.org">Morgan Delagrange</a>
- * @version $Id: TestLRUMap.java,v 1.11 2002/02/19 21:28:53 morgand Exp $
+ * @version $Id: TestLRUMap.java,v 1.11.2.1 2002/02/26 00:51:21 morgand Exp $
*/
public class TestLRUMap extends TestMap
{
@@ -93,7 +93,7 @@ public class TestLRUMap extends TestMap
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeMap() {
+ public Map makeEmptyMap() {
LRUMap map = new LRUMap(10);
return map;
}
@@ -153,7 +153,7 @@ public class TestLRUMap extends TestMap
public void testMapSupportsNullValues() {
- Map map = makeMap();
+ Map map = makeEmptyMap();
map.put(new Integer(1),"foo");
assertTrue("no null values in Map",map.containsValue(null) == false);
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/6a2c9bff/src/test/org/apache/commons/collections/TestMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestMap.java b/src/test/org/apache/commons/collections/TestMap.java
index ce8063a..0261d3f 100644
--- a/src/test/org/apache/commons/collections/TestMap.java
+++ b/src/test/org/apache/commons/collections/TestMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.3 2002/02/15 20:48:18 morgand Exp $
- * $Revision: 1.3 $
- * $Date: 2002/02/15 20:48:18 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.3.2.1 2002/02/26 00:51:21 morgand Exp $
+ * $Revision: 1.3.2.1 $
+ * $Date: 2002/02/26 00:51:21 $
*
* ====================================================================
*
@@ -62,55 +62,730 @@
package org.apache.commons.collections;
import junit.framework.*;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collection;
import java.util.Map;
import java.util.Collection;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.HashSet;
+import java.util.NoSuchElementException;
/**
* Tests base {@link java.util.Map} methods and contracts.
* <p>
- * To use, simply extend this class, and implement
- * the {@link #makeMap} method.
+ * If your class implements the full Map interface, including optional
+ * operations, simply extend this class, and implement the {@link
+ * #makeEmptyMap()} method.
* <p>
- * If your {@link Map} fails one of these tests by design,
- * you may still use this base set of cases. Simply override the
- * test case (method) your {@link Map} fails.
+ * If your {@link Map} fails one of these tests by design, you may still use
+ * this base set of cases. Simply override the test case (method) your {@link
+ * Map} fails and/or the methods that define the assumptions used by the test
+ * cases. For example, if your map does not allow duplicate values, override
+ * {@link useDuplicateValues()} and have it return <code>false</code>
*
+ * @author Michael Smith
* @author Rodney Waldhoff
- * @version $Id: TestMap.java,v 1.3 2002/02/15 20:48:18 morgand Exp $
+ * @version $Id: TestMap.java,v 1.3.2.1 2002/02/26 00:51:21 morgand Exp $
*/
public abstract class TestMap extends TestObject {
+
public TestMap(String testName) {
super(testName);
}
+ /**
+ * Override if your map does not allow a <code>null</code> key. The
+ * default implementation returns <code>true</code>
+ **/
+ public boolean useNullKey() {
+ return true;
+ }
+
+ /**
+ * Override if your map does not allow <code>null</code> values. The
+ * default implementation returns <code>true</code>.
+ **/
+ public boolean useNullValue() {
+ return true;
+ }
+
+ /**
+ * Override if your map does not allow duplicate values. The default
+ * implementation returns <code>true</code>.
+ **/
+ public boolean useDuplicateValues() {
+ return true;
+ }
+
+ /**
+ * Override if your map allows its mappings to be changed to new values.
+ * The default implementation returns <code>true</code>.
+ **/
+ public boolean isChangeable() {
+ return true;
+ }
+
+ /**
+ * Override if your map does not allow add/remove modifications. The
+ * default implementation returns <code>true</code>.
+ **/
+ public boolean isAddRemoveModifiable() {
+ return true;
+ }
+
+ /**
+ * Returns the set of keys in the mappings used to test the map. This
+ * method must return an array with the same length as {@link
+ * #getSampleValues()} and all array elements must be different. The
+ * default implementation constructs a set of String keys, and includes a
+ * single null key if {@link #useNullKey()} returns <code>true</code>.
+ **/
+ public Object[] getSampleKeys() {
+ Object[] result = new Object[] {
+ "blah", "foo", "bar", "baz", "tmp", "gosh", "golly", "gee",
+ "hello", "goodbye", "we'll", "see", "you", "all", "again",
+ "key",
+ "key2",
+ (useNullKey()) ? null : "nonnullkey"
+ };
+ return result;
+ }
+
+ /**
+ * Returns the set of values in the mappings used to test the map. This
+ * method must return an array with the same length as {@link
+ * #getSampleKeys()}. The default implementation contructs a set of
+ * String values and includes a single null value if {@link
+ * #useNullValue()} returns <code>true</code>, and includes two values
+ * that are the same if {@link #useDuplicateValues()} returns
+ * <code>true</code>.
+ **/
+ public Object[] getSampleValues() {
+ Object[] result = new Object[] {
+ "blahv", "foov", "barv", "bazv", "tmpv", "goshv", "gollyv", "geev",
+ "hellov", "goodbyev", "we'llv", "seev", "youv", "allv", "againv",
+ (useNullValue()) ? null : "nonnullvalue",
+ "value",
+ (useDuplicateValues()) ? "value" : "value2",
+ };
+ return result;
+ }
+
+ /**
+ * Returns a the set of values that can be used to replace the values
+ * returned from {@link #getSampleValues()}. This method must return an
+ * array with the same length as {@link #getSampleValues()}. The values
+ * returned from this method should not be the same as those returned from
+ * {@link #getSampleValues()}. The default implementation constructs a
+ * set of String values and includes a single null value if {@link
+ * #useNullValue()} returns <code>true</code>, and includes two values
+ * that are the same if {@link #useDuplicateValues()} returns
+ * <code>true</code>.
+ **/
+ public Object[] getNewSampleValues() {
+ Object[] result = new Object[] {
+ (useNullValue()) ? null : "newnonnullvalue",
+ "newvalue",
+ (useDuplicateValues()) ? "newvalue" : "newvalue2",
+ "newblahv", "newfoov", "newbarv", "newbazv", "newtmpv", "newgoshv",
+ "newgollyv", "newgeev", "newhellov", "newgoodbyev", "newwe'llv",
+ "newseev", "newyouv", "newallv", "newagainv",
+ };
+ return result;
+ }
+
+ /**
+ * Helper method to add all the mappings described by {@link
+ * #getSampleKeys()} and {@link #getSampleValues()}.
+ **/
+ public void addSampleMappings(Map m) {
+
+ Object[] keys = getSampleKeys();
+ Object[] values = getSampleValues();
+
+ for(int i = 0; i < keys.length; i++) {
+ try {
+ m.put(keys[i], values[i]);
+ } catch (NullPointerException exception) {
+ assertTrue("NullPointerException only allowed to be thrown " +
+ "if either the key or value is null.",
+ keys[i] == null || values[i] == null);
+
+ assertTrue("NullPointerException on null key, but " +
+ "useNullKey is not overridden to return false.",
+ keys[i] == null || !useNullKey());
+
+ assertTrue("NullPointerException on null value, but " +
+ "useNullValue is not overridden to return false.",
+ values[i] == null || !useNullValue());
+
+ assertTrue("Unknown reason for NullPointer.", false);
+ }
+ }
+ assertEquals("size must reflect number of mappings added.",
+ keys.length, m.size());
+ }
/**
- * Return a new, empty {@link Map} to used for testing.
+ * Return a new, empty {@link Map} to be used for testing.
*/
- public abstract Map makeMap();
+ public abstract Map makeEmptyMap();
+
+ /**
+ * Return a new, populated map. The mappings in the map should match the
+ * keys and values returned from {@linke #getSampleKeys()} and {@link
+ * #getSampleValues()}. The default implementation uses makeEmptyMap()
+ * and calls {@link #addSampleMappings()} to add all the mappings to the
+ * map.
+ **/
+ public Map makeFullMap() {
+ Map m = makeEmptyMap();
+ addSampleMappings(m);
+ return m;
+ }
public Object makeObject() {
- return makeMap();
+ return makeEmptyMap();
}
- /*
+ /**
+ * Test to ensure the test setup is working properly. This method checks
+ * to ensure that the getSampleKeys and getSampleValues methods are
+ * returning results that look appropriate. That is, they both return a
+ * non-null array of equal length. The keys array must not have any
+ * duplicate values, and may only contain a (single) null key if
+ * useNullKey() returns true. The values array must only have a null
+ * value if useNullValue() is true and may only have duplicate values if
+ * useDuplicateValues() returns true.
+ **/
+ public void testSampleMappings() {
+ Object[] keys = getSampleKeys();
+ Object[] values = getSampleValues();
+ Object[] newValues = getNewSampleValues();
- // optional operation
- public void testMapClear() {
- // XXX finish me
+ assertTrue("failure in test: Must have keys returned from " +
+ "getSampleKeys.", keys != null);
+
+ assertTrue("failure in test: Must have values returned from " +
+ "getSampleValues.", values != null);
+
+ // verify keys and values have equivalent lengths (in case getSampleX are
+ // overridden)
+ assertEquals("failure in test: not the same number of sample " +
+ "keys and values.", keys.length, values.length);
+
+ assertEquals("failure in test: not the same number of values and new values.",
+ values.length, newValues.length);
+
+ // verify there aren't duplicate keys, and check values
+ for(int i = 0; i < keys.length - 1; i++) {
+ for(int j = i + 1; j < keys.length; j++) {
+ assertTrue("failure in test: duplicate null keys.",
+ (keys[i] != null || keys[j] != null));
+ assertTrue("failure in test: duplicate non-null key.",
+ (keys[i] == null || keys[j] == null ||
+ (!keys[i].equals(keys[j]) &&
+ !keys[j].equals(keys[i]))));
+ }
+ assertTrue("failure in test: found null key, but useNullKey " +
+ "is false.", keys[i] != null || useNullKey());
+ assertTrue("failure in test: found null value, but useNullValue " +
+ "is false.", values[i] != null || useNullValue());
+ assertTrue("failure in test: found null new value, but useNullValue " +
+ "is false.", newValues[i] != null || useNullValue());
+ assertTrue("failure in test: values should not be the same as new value",
+ values[i] != newValues[i] &&
+ (values[i] == null || !values[i].equals(newValues[i])));
+ }
}
+
+ // tests begin here. Each test adds a little bit of tested functionality.
+ // Many methods assume previous methods passed. That is, they do not
+ // exhaustively recheck things that have already been checked in a previous
+ // test methods.
- public void testMapContainsKey() {
- // XXX finish me
+ /**
+ * Test to ensure that makeEmptyMap and makeFull returns a new non-null
+ * map with each invocation.
+ **/
+ public void testMakeMap() {
+ Map em = makeEmptyMap();
+ assertTrue("failure in test: makeEmptyMap must return a non-null map.",
+ em != null);
+
+ Map em2 = makeEmptyMap();
+ assertTrue("failure in test: makeEmptyMap must return a non-null map.",
+ em != null);
+
+ assertTrue("failure in test: makeEmptyMap must return a new map " +
+ "with each invocation.", em != em2);
+
+ Map fm = makeFullMap();
+ assertTrue("failure in test: makeFullMap must return a non-null map.",
+ fm != null);
+
+ Map fm2 = makeFullMap();
+ assertTrue("failure in test: makeFullMap must return a non-null map.",
+ fm != null);
+
+ assertTrue("failure in test: makeFullMap must return a new map " +
+ "with each invocation.", fm != fm2);
}
- public void testMapContainsValue() {
- // XXX finish me
+ /**
+ * Tests Map.isEmpty()
+ **/
+ public void testIsEmpty() {
+ Map em = makeEmptyMap();
+ assertEquals("Map.isEmpty() should return true with an empty map",
+ true, em.isEmpty());
+
+ Map fm = makeFullMap();
+ assertEquals("Map.isEmpty() should return false with a non-empty map",
+ false, fm.isEmpty());
}
- public void testMapEntrySet() {
- // XXX finish me
+ /**
+ * Tests Map.size()
+ **/
+ public void testSize() {
+ Map em = makeEmptyMap();
+ assertEquals("Map.size() should be 0 with an empty map",
+ 0, em.size());
+
+ Map fm = makeFullMap();
+ assertEquals("Map.size() should equal the number of entries in the map",
+ getSampleKeys().length, fm.size());
}
+ /**
+ * Tests {@link Map#clear()}. If the map {@link #isAddRemoveModifiable()
+ * can add and remove elements}, then {@link Map#size()} and {@link
+ * Map#isEmpty()} are used to ensure that map has no elements after a call
+ * to clear. If the map does not support adding and removing elements,
+ * this method checks to ensure clear throws an
+ * UnsupportedOperationException. This method checks that the both maps
+ * returned by makeEmptyMap and makeFullMap have correct behavior.
+ **/
+ public void testClear() {
+ Map em = makeEmptyMap();
+ try {
+ em.clear();
+ assertTrue("Map must throw UnsupportedOperationException if the " +
+ "map does not support removing elements",
+ isAddRemoveModifiable());
+ assertEquals("size() must return zero after clear.",
+ 0, em.size());
+ assertEquals("isEmpty() must return true after clear.",
+ true, em.isEmpty());
+ } catch (UnsupportedOperationException exception) {
+ assertTrue("Map must not throw UnsupportedOperationException if the " +
+ "map supports removing elements", !isAddRemoveModifiable());
+ }
+
+ Map fm = makeFullMap();
+ try {
+ fm.clear();
+ assertTrue("Map must throw UnsupportedOperationException if the " +
+ "map does not support removing elements",
+ isAddRemoveModifiable());
+ assertEquals("size() must return zero after clear.",
+ 0, fm.size());
+ assertEquals("isEmpty() must return true after clear.",
+ true, fm.isEmpty());
+ } catch (UnsupportedOperationException exception) {
+ assertTrue("Map must not throw UnsupportedOperationException if the " +
+ "map supports removing elements", !isAddRemoveModifiable());
+ }
+ }
+
+ /**
+ * Tests:
+ * <ul>
+ * <li> Map.entrySet().isEmpty()
+ * <li> Map.entrySet().size()
+ * </ul>
+ **/
+ public void testEntrySetIsEmpty() {
+ Map em = makeEmptyMap();
+ Set es = em.entrySet();
+
+ assertEquals("entrySet() must return an empty set when map is empty.",
+ em.isEmpty(), es.isEmpty());
+ assertEquals("entrySet() must return a set with the same size as " +
+ "the map.", em.size(), es.size());
+
+ Map fm = makeEmptyMap();
+ Set fs = fm.entrySet();
+
+ assertEquals("entrySet() must return a non-empty set when map is not empty.",
+ fm.isEmpty(), fs.isEmpty());
+ assertEquals("entrySet() must return a set with the same size as " +
+ "the map.", fm.size(), fs.size());
+ }
+
+ /**
+ * Tests Map.containsKey(Object) by verifying it returns false for all
+ * sample keys on a map created using makeEmptyMap() and returns true for
+ * all sample keys returned on a map created using makeFullMap()
+ **/
+ public void testContainsKey() {
+ Object[] keys = getSampleKeys();
+
+ Map em = makeEmptyMap();
+
+ for(int i = 0; i < keys.length; i++) {
+ assertTrue("Map must not contain key when map is empty",
+ !em.containsKey(keys[i]));
+ }
+
+ Map fm = makeFullMap();
+
+ for(int i = 0; i < keys.length; i++) {
+ assertTrue("Map must contain key for a mapping in the map.",
+ fm.containsKey(keys[i]));
+ }
+ }
+
+ /**
+ * Tests Map.containsValue(Object) by verifying it returns false for all
+ * sample alues on a map created using makeEmptyMap() and returns true for
+ * all sample values returned on a map created using makeFullMap.
+ **/
+ public void testContainsValue() {
+ Object[] values = getSampleValues();
+
+ Map em = makeEmptyMap();
+
+ for(int i = 0; i < values.length; i++) {
+ assertTrue("Empty map must not contain value",
+ !em.containsValue(values[i]));
+ }
+
+ Map fm = makeFullMap();
+
+ for(int i = 0; i < values.length; i++) {
+ assertTrue("Map must contain value for a mapping in the map.",
+ fm.containsValue(values[i]));
+ }
+ }
+
+ /**
+ * Test to ensure that Map.entrySet() returns a non-null set.
+ **/
+ public void testEntrySet() {
+ Map em = makeEmptyMap();
+ Set es = em.entrySet();
+
+ assertTrue("entrySet() must return a non-null set.", es != null);
+
+ Map fm = makeEmptyMap();
+ Set fs = fm.entrySet();
+
+ assertTrue("entrySet() must return a non-null set.", fs != null);
+ }
+
+ /**
+ * Tests:
+ * <ul>
+ * <li> Map.entrySet().contains(Object)
+ * <li> Map.entrySet().containsAll(Collection)
+ * </ul>
+ *
+ * Note: This test relies on a working commons.collections.DefaultMapEntry class.
+ **/
+ public void testEntrySetContainsProperMappings() {
+ Object[] keys = getSampleKeys();
+ Object[] values = getSampleValues();
+ Map.Entry[] entries = new Map.Entry[keys.length];
+ HashSet mappings = new HashSet();
+
+ for(int i = 0; i < keys.length; i++) {
+ entries[i] = new DefaultMapEntry(keys[i], values[i]);
+ mappings.add(entries[i]);
+ }
+
+ // test an empty map
+ Map em = makeEmptyMap();
+ Set es = em.entrySet();
+
+ for(int i = 0; i < keys.length; i++) {
+ assertEquals("entrySet().contains(Object) must return false when map " +
+ "is empty", false, es.contains(entries[i]));
+ }
+
+ assertEquals("entrySet().containsAll(Collection) must return false when the " +
+ "map is empty", false, es.containsAll(mappings));
+
+
+ Map fm = makeFullMap();
+ Set fs = fm.entrySet();
+
+ for(int i = 0; i < keys.length; i++) {
+ assertEquals("entrySet().contains(Object) must return true when map " +
+ "contains the mapping", true, fs.contains(entries[i]));
+ }
+ assertEquals("entrySet().containsAll(Collection) must return true when the " +
+ "map contains the mapping", true, fs.containsAll(mappings));
+
+ try {
+ es.containsAll((Collection)null);
+ fail("entrySet().containsAll(null) should " +
+ "throw a NullPointerException");
+ } catch (NullPointerException exception) {
+ // expected
+ }
+ try {
+ fs.containsAll((Collection)null);
+ fail("entrySet().containsAll(null) should " +
+ "throw a NullPointerException");
+ } catch (NullPointerException exception) {
+ // expected
+ }
+ }
+
+ // TODO: test entrySet().clear()
+ // TODO: test entrySet().add() throws OperationNotSupported
+ // TODO: test entrySet().addAll() throws OperationNotSupported
+ // TODO: test entrySet().contains(Object)
+ // TODO: test entrySet().containsAll(Collection)
+ // TODO: test entrySet().equals(Object)
+ // TODO: test entrySet().hashCode()
+ // TODO: test entrySet().toArray()
+ // TODO: test entrySet().toArray(Object[] a)
+ // TODO: test entrySet().remove(Object)
+ // TODO: test entrySet().removeAll(Collection)
+ // TODO: test entrySet().retainAll(Collection)
+
+ /**
+ * Tests:
+ * <ul>
+ * <li> Map.entrySet().iterator()
+ * <li> Map.entrySet().iterator().hasNext()
+ * <li> Map.entrySet().iterator().next()
+ * </ul>
+ **/
+ public void testEntrySetIterator() {
+ Map em = makeEmptyMap();
+ Set es = em.entrySet();
+ Iterator eiter = es.iterator();
+
+ assertEquals("entrySet().iterator().hasNext() must return false " +
+ "when then the map is empty.",
+ false, eiter.hasNext());
+
+ // note: we make a new map to test for this because some impls in the
+ // past have required a call to hasMoreElements before a call to next
+ // for it to work properly. By using a new map, we make sure this test
+ // will catch those broken impls.
+ em = makeEmptyMap();
+ es = em.entrySet();
+ eiter = es.iterator();
+
+ try {
+ eiter.next();
+ fail("entrySet().iterator().next() must throw a NoSuchElementException " +
+ "when the map is empty");
+ } catch (NoSuchElementException exception) {
+ // expected
+ }
+
+
+ Map fm = makeFullMap();
+
+ Set fs = fm.entrySet();
+
+ Object[] keys = getSampleKeys();
+ Object[] values = getSampleValues();
+ boolean[] found = new boolean[keys.length];
+
+ Iterator iter = fs.iterator();
+
+ assertTrue("entrySet().iterator() must return a non-null " +
+ "iterator.", iter != null);
+
+ while(iter.hasNext()) {
+ Object obj = iter.next();
+ assertTrue("Null is not allowed to be returned from the " +
+ "entrySet().iterator()'s next().", obj != null);
+ assertTrue("Objects returned from entrySet().iterator() must be " +
+ "instances of Map.Entry.", obj instanceof Map.Entry);
+
+ Map.Entry entry = (Map.Entry)obj;
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+
+ assertTrue("the key for an entry returned from the entry " +
+ "set's iterator can only be null if useNullKey " +
+ "is true.",
+ key != null || (key == null && useNullKey()));
+
+ assertTrue("the value for an entry returned from the entry " +
+ "set's iterator can only be null if useNullValue " +
+ "is true.",
+ value != null || (value == null && useNullValue()));
+
+ for(int i = 0; i < keys.length; i++) {
+ if((key == null && keys[i] == null) ||
+ (key != null && key.equals(keys[i]))) {
+ assertTrue("entrySet().iterator() must not return " +
+ "multiple entries with the same key.",
+ !found[i]);
+
+ found[i] = true;
+
+ assertTrue
+ ("value of entry returned from iterator " +
+ "must be the value for the added mapping.",
+ (value == null && values[i] == null) ||
+ (value != null && value.equals(values[i])));
+ }
+ }
+ }
+ for(int i = 0; i < found.length; i++) {
+ assertTrue("must find all added elements through entrySet's " +
+ "iterator().", found[i]);
+ }
+ }
+
+ /**
+ * Tests Map.entrySet().iterator().remove()
+ **/
+ public void testEntrySetIteratorRemove() {
+ Map m = makeFullMap();
+ Set s = m.entrySet();
+ Iterator iter = s.iterator();
+
+ try {
+ iter.remove();
+ fail("Entry set iterator must not allow a call to remove " +
+ "before any calls to next");
+ } catch (IllegalStateException exception) {
+ // expected exception provided add/remove modifiable
+ assertTrue("iterator should throw UnsupportedOperationException " +
+ "if remove is not allowed from the entrySet().iterator()",
+ isAddRemoveModifiable());
+ } catch (UnsupportedOperationException exception) {
+ assertTrue("iterator should not throw UnsupportedOperationException " +
+ "if the map supports adding and removing elements",
+ !isAddRemoveModifiable());
+ }
+
+ while(iter.hasNext()) {
+ Map.Entry entry = (Map.Entry)iter.next();
+
+ assertTrue("Entry key from entry set iterator must exist in map",
+ m.containsKey(entry.getKey()));
+ try {
+ iter.remove();
+ // note: we do not check that the mapping was actually removed
+ // from the map because some classes do not have their
+ // entrySet().iterator() backed by the map. That test occurs
+ // below in testEntrySetIteratorRemoveCausesMapModification
+ } catch (UnsupportedOperationException exception) {
+ assertTrue("iterator should not throw UnsupportedOperationException " +
+ "if the map supports adding and removing elements",
+ !isAddRemoveModifiable());
+ }
+
+ try {
+ iter.remove();
+ fail("Entry set iterator must not allow two calls to " +
+ "remove without a call to next.");
+ } catch (IllegalStateException exception) {
+ // expected exception provided add/remove modifiable
+ assertTrue("iterator should throw UnsupportedOperationException " +
+ "if remove is not allowed from the entrySet().iterator()",
+ isAddRemoveModifiable());
+ } catch (UnsupportedOperationException exception) {
+ assertTrue("iterator should not throw UnsupportedOperationException " +
+ "if the map supports adding and removing elements",
+ !isAddRemoveModifiable());
+ }
+ }
+ }
+
+ /**
+ * Tests whether the map's entrySet() is backed by the map by making sure
+ * a put in the map is reflected in the entrySet. This test does nothing
+ * if add/remove modifications are not supported.
+ **/
+ public void testEntrySetChangesWithMapPut() {
+ if(!isAddRemoveModifiable()) return;
+
+ Map m = makeEmptyMap();
+
+ // test insert reflected in entry set
+ Set s = m.entrySet();
+ addSampleMappings(m);
+ assertEquals("entrySet() must only be empty if map is empty.",
+ m.isEmpty(), s.isEmpty());
+ assertEquals("entrySet() must adjust size when map changes.",
+ m.size(), s.size());
+ // TODO: test set and map reflect the same contents
+ }
+
+ /**
+ * Tests whether the map's entrySet() is backed by the map by making sure
+ * a remove from the map is reflected in the entrySet. This test does nothing
+ * if add/remove modifications are not supported.
+ **/
+ public void testEntrySetChangesWithMapRemove() {
+ if(!isAddRemoveModifiable()) return;
+
+ Map m = makeFullMap();
+ Set s = m.entrySet();
+
+ Object[] keys = getSampleKeys();
+ Object[] values = getSampleValues();
+
+ for(int i = 0; i < keys.length; i++) {
+ m.remove(keys[i]);
+ assertEquals("entrySet() must only be empty if map is empty.",
+ m.isEmpty(), s.isEmpty());
+ assertEquals("entrySet() must adjust size when map changes.",
+ m.size(), s.size());
+ //TODO: test set and map reflect the same contents
+ }
+ }
+
+ // TODO: test entrySet() changes after Map.remove
+ // TODO: test entrySet() changes after Map.clear
+ // TODO: test entrySet() changes after Map.putAll
+
+ /**
+ * Tests whether the map's entrySet() is backed by the map by making sure
+ * a remove from the entrySet's iterator is reflected in the map. This
+ * test does nothing if add/remove modifications are not supported.
+ **/
+ public void testEntrySetIteratorRemoveCausesMapModification() {
+ if(!isAddRemoveModifiable()) return;
+
+ Map m = makeFullMap();
+ Set s = m.entrySet();
+ Iterator iter = s.iterator();
+
+ while(iter.hasNext()) {
+ Map.Entry entry = (Map.Entry)iter.next();
+
+ try {
+ iter.remove();
+ assertTrue("Entry key from entry set iterator must " +
+ "no longer exist in map",
+ !m.containsKey(entry.getKey()));
+ } catch (UnsupportedOperationException exception) {
+ // isAddRemoveModifiable is true -- we've checked that above
+ fail("iterator should not throw UnsupportedOperationException " +
+ "if the map supports adding and removing elements");
+ }
+ }
+ }
+
+ // TODO: test map changes after entrySet().remove
+ // TODO: test map changes after entrySet().removeAll
+ // TODO: test map changes after entrySet().retainAll
+
public void testMapEquals() {
// XXX finish me
}
@@ -123,14 +798,206 @@ public abstract class TestMap extends TestObject {
// XXX finish me
}
- public void testMapIsEmpty() {
+ public void testMapKeySet() {
// XXX finish me
}
+
+ //-------TEST AGAINST OPTIONAL OPERATIONS, ENABLE IN TEST SUBCLASSES
- public void testMapKeySet() {
- // XXX finish me
+ public void testMapSupportsNullValues() {
+
+ if ((this instanceof TestMap.SupportsPut) == false) {
+ return;
+ }
+
+ Map map = makeEmptyMap();
+ map.put(new Integer(1),"foo");
+
+ assertTrue("no null values in Map",map.containsValue(null) == false);
+
+ map.put(new Integer(2),null);
+
+ assertTrue("null value in Map",map.containsValue(null));
+ assertTrue("key to a null value",map.containsKey(new Integer(2)));
+ }
+
+ public void testMultiplePuts() {
+
+ if ((this instanceof TestMap.SupportsPut) == false) {
+ return;
+ }
+
+ Map map = makeEmptyMap();
+ map.put(new Integer(4),"foo");
+ map.put(new Integer(4),"bar");
+ map.put(new Integer(4),"foo");
+ map.put(new Integer(4),"bar");
+
+ assertTrue("same key different value",map.get(new Integer(4)).equals("bar"));
+ }
+
+
+ public void testCapacity() {
+
+ if ((this instanceof TestMap.SupportsPut) == false) {
+ return;
+ }
+
+ Map map = makeEmptyMap();
+ map.put(new Integer(1),"foo");
+ map.put(new Integer(2),"foo");
+ map.put(new Integer(3),"foo");
+ map.put(new Integer(1),"foo");
+
+ assertTrue("size of Map should be 3, but was " + map.size(), map.size() == 3);
+ }
+
+ public void testEntrySetRemove() {
+
+ if ((this instanceof TestMap.EntrySetSupportsRemove) == false ||
+ (this instanceof TestMap.SupportsPut) == false) {
+ return;
+ }
+
+ Map map = makeEmptyMap();
+ map.put("1","1");
+ map.put("2","2");
+ map.put("3","3");
+
+ Object o = map.entrySet().iterator().next();
+ // remove one of the key/value pairs
+ Set set = map.entrySet();
+ set.remove(o);
+ assertTrue(set.size() == 2);
+ // try to remove it again, to make sure
+ // the Set is not confused by missing entries
+ set.remove(o);
+
+ assertTrue("size of Map should be 2, but was " + map.size(), map.size() == 2);
+
+ }
+
+ public void testEntrySetContains() {
+
+ if ((this instanceof TestMap.SupportsPut) == false) {
+ return;
+ }
+
+ Map map = makeEmptyMap();
+ map.put("1","1");
+ map.put("2","2");
+ map.put("3","3");
+
+ Set set = map.entrySet();
+ Object o = set.iterator().next();
+ assertTrue("entry set should contain valid element",set.contains(o));
+
+ // create a fresh entry mapped to existing values
+ DefaultMapEntry goodEntry = new DefaultMapEntry("2","2");
+ assertTrue("entry set should recognize externally constructed MapEntry objects",
+ set.contains(goodEntry));
+
+ // make a bogus entry
+ DefaultMapEntry badEntry = new DefaultMapEntry("4","4");
+ assertTrue("entry set should not contain a bogus element",
+ set.contains(badEntry) == false);
+
+
+ }
+
+ public void testEmptyMapSerialization()
+ throws IOException, ClassNotFoundException {
+ Map map = makeEmptyMap();
+ if (!(map instanceof Serializable)) return;
+
+ byte[] objekt = writeExternalFormToBytes((Serializable) map);
+ Map map2 = (Map) readExternalFormFromBytes(objekt);
+
+ assertTrue("Both maps are empty",map.isEmpty() == true);
+ assertTrue("Both maps are empty",map2.isEmpty() == true);
}
+ public void testFullMapSerialization()
+ throws IOException, ClassNotFoundException {
+ Map map = makeFullMap();
+ if (!(map instanceof Serializable)) return;
+
+ byte[] objekt = writeExternalFormToBytes((Serializable) map);
+ Map map2 = (Map) readExternalFormFromBytes(objekt);
+
+ assertEquals("Both maps are same size",map.size(), getSampleKeys().length);
+ assertEquals("Both maps are same size",map2.size(),getSampleKeys().length);
+ }
+
+
+ public String getCanonicalEmptyMapName(Map map) {
+ StringBuffer retval = new StringBuffer();
+ retval.append("data/test/");
+ String mapName = map.getClass().getName();
+ mapName = mapName.substring(mapName.lastIndexOf(".")+1,mapName.length());
+ retval.append(mapName);
+ retval.append(".emptyMap.version");
+ retval.append(getCompatibilityVersion());
+ retval.append(".obj");
+ return retval.toString();
+ }
+
+ public String getCanonicalFullMapName(Map map) {
+ StringBuffer retval = new StringBuffer();
+ retval.append("data/test/");
+ String mapName = map.getClass().getName();
+ mapName = mapName.substring(mapName.lastIndexOf(".")+1,mapName.length());
+ retval.append(mapName);
+ retval.append(".fullMap.version");
+ retval.append(getCompatibilityVersion());
+ retval.append(".obj");
+ return retval.toString();
+ }
+
+ /**
+ * Compare the current serialized form of the Map
+ * against the canonical version in CVS.
+ */
+ public void testEmptyMapCompatibility() throws IOException, ClassNotFoundException {
+ /**
+ * Create canonical objects with this code
+ Map map = makeEmptyMap();
+ if (!(map instanceof Serializable)) return;
+
+ writeExternalFormToDisk((Serializable) map, getCanonicalEmptyMapName(map));
+ */
+
+ // test to make sure the canonical form has been preserved
+ if (!(makeEmptyMap() instanceof Serializable)) return;
+ Map map = (Map) readExternalFormFromDisk(getCanonicalEmptyMapName(makeEmptyMap()));
+ assertTrue("Map is empty",map.isEmpty() == true);
+ }
+
+ /**
+ * Compare the current serialized form of the Map
+ * against the canonical version in CVS.
+ */
+ public void testFullMapCompatibility() throws IOException, ClassNotFoundException {
+ /**
+ * Create canonical objects with this code
+ Map map = makeFullMap();
+ if (!(map instanceof Serializable)) return;
+
+ writeExternalFormToDisk((Serializable) map, getCanonicalFullMapName(map));
+ */
+
+ // test to make sure the canonical form has been preserved
+ if (!(makeFullMap() instanceof Serializable)) return;
+ Map map = (Map) readExternalFormFromDisk(getCanonicalFullMapName(makeFullMap()));
+ assertEquals("Map is the right size",map.size(), getSampleKeys().length);
+ }
+
+ /*
+ // optional operation
+public void testMapClear() {
+ // XXX finish me
+}
+
// optional operation
public void testMapPut() {
// XXX finish me
@@ -146,38 +1013,20 @@ public abstract class TestMap extends TestObject {
// XXX finish me
}
- public void testMapSize() {
- // XXX finish me
- }
-
public void testMapValues() {
// XXX finish me
}
- */
-
/**
- * Try to put the given pair into the given Collection.
- *
- * Fails any Throwable except UnsupportedOperationException,
- * ClassCastException, or IllegalArgumentException
- * or NullPointerException is thrown.
+ * Marker interface, indicating that a TestMap subclass
+ * can test put(Object,Object) operations.
*/
- protected Object tryToPut(Map map, Object key, Object val) {
- try {
- return map.put(key,val);
- } catch(UnsupportedOperationException e) {
- return null;
- } catch(ClassCastException e) {
- return null;
- } catch(IllegalArgumentException e) {
- return null;
- } catch(NullPointerException e) {
- return null;
- } catch(Throwable t) {
- t.printStackTrace();
- fail("Map.put should only throw UnsupportedOperationException, ClassCastException, IllegalArgumentException or NullPointerException. Found " + t.toString());
- return null; // never get here, since fail throws exception
- }
+ public interface SupportsPut {
+
+ }
+
+ public interface EntrySetSupportsRemove {
+
}
+
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/6a2c9bff/src/test/org/apache/commons/collections/TestMultiHashMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestMultiHashMap.java b/src/test/org/apache/commons/collections/TestMultiHashMap.java
index d296bc2..bc7ed85 100644
--- a/src/test/org/apache/commons/collections/TestMultiHashMap.java
+++ b/src/test/org/apache/commons/collections/TestMultiHashMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestMultiHashMap.java,v 1.1 2001/09/18 10:41:39 jstrachan Exp $
- * $Revision: 1.1 $
- * $Date: 2001/09/18 10:41:39 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestMultiHashMap.java,v 1.1.2.1 2002/02/26 00:51:21 morgand Exp $
+ * $Revision: 1.1.2.1 $
+ * $Date: 2002/02/26 00:51:21 $
*
* ====================================================================
*
@@ -90,7 +90,7 @@ public class TestMultiHashMap extends TestMap
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeMap() {
+ public Map makeEmptyMap() {
return new MultiHashMap();
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/6a2c9bff/src/test/org/apache/commons/collections/TestObject.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestObject.java b/src/test/org/apache/commons/collections/TestObject.java
index 9d23a6b..fa97171 100644
--- a/src/test/org/apache/commons/collections/TestObject.java
+++ b/src/test/org/apache/commons/collections/TestObject.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestObject.java,v 1.1 2001/04/20 16:54:03 rwaldhoff Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/20 16:54:03 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestObject.java,v 1.1.2.1 2002/02/26 00:48:14 morgand Exp $
+ * $Revision: 1.1.2.1 $
+ * $Date: 2002/02/26 00:48:14 $
*
* ====================================================================
*
@@ -62,6 +62,18 @@
package org.apache.commons.collections;
import junit.framework.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
@@ -71,20 +83,39 @@ import java.util.NoSuchElementException;
* Tests base {@link java.util.Object} methods and contracts.
* <p>
* To use, simply extend this class, and implement
- * the {@link #makeObject} method.
+ * the {@link #makeObject()} method.
* <p>
* If your {@link Object} fails one of these tests by design,
* you may still use this base set of cases. Simply override the
* test case (method) your {@link Object} fails.
*
* @author Rodney Waldhoff
- * @version $Id: TestObject.java,v 1.1 2001/04/20 16:54:03 rwaldhoff Exp $
+ * @version $Id: TestObject.java,v 1.1.2.1 2002/02/26 00:48:14 morgand Exp $
*/
public abstract class TestObject extends TestCase {
public TestObject(String testName) {
super(testName);
}
+ // current major release for Collections
+ public static final int COLLECTIONS_MAJOR_VERSION = 2;
+
+ /**
+ * This constant makes it possible for TestMap (and other subclasses,
+ * if necessary) to automatically check CVS for a versionX copy of a
+ * Serialized object, so we can make sure that compatibility is maintained.
+ * See, for example, TestMap.getCanonicalFullMapName(Map map).
+ * Subclasses can override this variable, indicating compatibility
+ * with earlier Collections versions.
+ * Defaults to 1, the earliest Collections version. (Note: some
+ * collections did not even exist in this version).
+ *
+ * @return 1
+ */
+ public int getCompatibilityVersion() {
+ return 1;
+ }
+
/**
* Return a new, empty {@link Object} to used for testing.
*/
@@ -108,6 +139,100 @@ public abstract class TestObject extends TestCase {
Object obj2 = makeObject();
if(obj1.equals(obj2)) {
assertEquals("[2] When two objects are equal, their hashCodes should be also.",obj1.hashCode(),obj2.hashCode());
+ assertTrue("When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true", obj2.equals(obj1));
+ }
+ }
+
+ private void writeExternalFormToStream(Serializable o, OutputStream stream)
+ throws IOException {
+ ObjectOutputStream oStream = new ObjectOutputStream(stream);
+ oStream.writeObject(o);
+ }
+
+ /**
+ * Write a Serializable or Externalizable object as
+ * a file at the given path. NOT USEFUL as part
+ * of a unit test; this is just a utility method
+ * for creating disk-based objects in CVS that can become
+ * the basis for compatibility tests using
+ * readExternalFormFromDisk(String path)
+ *
+ * @param o Object to serialize
+ * @param path path to write the serialized Object
+ * @exception IOException
+ */
+ protected void writeExternalFormToDisk(Serializable o, String path)
+ throws IOException {
+ FileOutputStream fileStream = new FileOutputStream(path);
+ writeExternalFormToStream(o,fileStream);
+ }
+
+ /**
+ * Converts a Serializable or Externalizable object to
+ * bytes. Useful for in-memory tests of serialization
+ *
+ * @param o Object to convert to bytes
+ * @return serialized form of the Object
+ * @exception IOException
+ */
+ protected byte[] writeExternalFormToBytes(Serializable o)
+ throws IOException {
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+ writeExternalFormToStream(o,byteStream);
+ return byteStream.toByteArray();
+ }
+
+ private Object readExternalFormFromStream(InputStream stream)
+ throws IOException, ClassNotFoundException {
+ ObjectInputStream oStream = new ObjectInputStream(stream);
+ return oStream.readObject();
+ }
+
+ /**
+ * Reads a Serialized or Externalized Object from disk.
+ * Useful for creating compatibility tests betweeen
+ * different CVS versions of the same class
+ *
+ * @param path path to the serialized Object
+ * @return the Object at the given path
+ * @exception IOException
+ * @exception ClassNotFoundException
+ */
+ protected Object readExternalFormFromDisk(String path)
+ throws IOException, ClassNotFoundException {
+ FileInputStream stream = new FileInputStream(path);
+ return readExternalFormFromStream(stream);
+ }
+
+ /**
+ * Read a Serialized or Externalized Object from bytes.
+ * Useful for verifying serialization in memory.
+ *
+ * @param b byte array containing a serialized Object
+ * @return Object contained in the bytes
+ * @exception IOException
+ * @exception ClassNotFoundException
+ */
+ protected Object readExternalFormFromBytes(byte[] b)
+ throws IOException, ClassNotFoundException {
+ ByteArrayInputStream stream = new ByteArrayInputStream(b);
+ return readExternalFormFromStream(stream);
+ }
+
+ /**
+ * Sanity check method, makes sure that any Serializable
+ * class can be serialized and de-serialized in memory,
+ * using the handy makeObject() method
+ *
+ * @exception IOException
+ * @exception ClassNotFoundException
+ */
+ public void testSimpleSerialization()
+ throws IOException, ClassNotFoundException {
+ Object o = makeObject();
+ if (o instanceof Serializable) {
+ byte[] objekt = writeExternalFormToBytes((Serializable) o);
+ Object p = readExternalFormFromBytes(objekt);
}
}
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/6a2c9bff/src/test/org/apache/commons/collections/TestTreeMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestTreeMap.java b/src/test/org/apache/commons/collections/TestTreeMap.java
index b3f07ac..ab8d6bf 100644
--- a/src/test/org/apache/commons/collections/TestTreeMap.java
+++ b/src/test/org/apache/commons/collections/TestTreeMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestTreeMap.java,v 1.2 2001/07/14 23:33:27 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2001/07/14 23:33:27 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestTreeMap.java,v 1.2.2.1 2002/02/26 00:51:21 morgand Exp $
+ * $Revision: 1.2.2.1 $
+ * $Date: 2002/02/26 00:51:21 $
*
* ====================================================================
*
@@ -69,7 +69,7 @@ import java.util.Map;
/**
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: TestTreeMap.java,v 1.2 2001/07/14 23:33:27 craigmcc Exp $
+ * @version $Id: TestTreeMap.java,v 1.2.2.1 2002/02/26 00:51:21 morgand Exp $
*/
public class TestTreeMap extends TestMap
{
@@ -89,7 +89,7 @@ public class TestTreeMap extends TestMap
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeMap() {
+ public Map makeEmptyMap() {
TreeMap tm = new TreeMap();
return (tm);
}
@@ -98,7 +98,7 @@ public class TestTreeMap extends TestMap
public void setUp()
{
- map = (TreeMap) makeMap();
+ map = (TreeMap) makeEmptyMap();
}
public void testNewMap()
[05/18] commons-collections git commit: to ease maintenance,
removed all unreleased classes from the 1.x branch
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/MultiMap.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/MultiMap.java b/src/java/org/apache/commons/collections/MultiMap.java
deleted file mode 100644
index f9eb99f..0000000
--- a/src/java/org/apache/commons/collections/MultiMap.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/MultiMap.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.Map;
-
-/**
- * This is simply a Map with slightly different semantics.
- * Instead of returning an Object, it returns a Collection.
- * So for example, you can put( key, new Integer(1) );
- * and then a Object get( key ); will return you a Collection
- * instead of an Integer.
- * Thus, this is simply a tag interface.
- *
- * @author Christopher Berry
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-public interface MultiMap extends Map {
-
- public Object remove( Object key, Object item );
-
-}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/SequencedHashMap.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/SequencedHashMap.java b/src/java/org/apache/commons/collections/SequencedHashMap.java
deleted file mode 100644
index b6a76f6..0000000
--- a/src/java/org/apache/commons/collections/SequencedHashMap.java
+++ /dev/null
@@ -1,888 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SequencedHashMap.java,v 1.3 2002/02/18 20:34:57 morgand Exp $
- * $Revision: 1.3 $
- * $Date: 2002/02/18 20:34:57 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.AbstractCollection;
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.NoSuchElementException;
-
-/**
- * A map of objects whose mapping entries are sequenced based on the order in
- * which they were added. This data structure has fast <I>O(1)</I> search
- * time, deletion time, and insertion time.
- *
- * This class inherits from {@link java.util.HashMap} purely for backwards
- * compatibility. It should really be inheriting from {@link
- * java.util.AbstractMap}, or with a tiny extra bit of work, implement the
- * full map interface on its own. APIs should not rely on this class being an
- * actual {@link java.util.HashMap}, and instead should recognize it only as a
- * generic {@link java.util.Map} (unless, of course, you need the sequencing
- * functionality, but even in that case, this class should not be referred to
- * as a java.util.HashMap).
- *
- * <P>Although this map is sequenced, it cannot implement {@link
- * java.util.List} because of incompatible interface definitions. The remove
- * methods in List and Map have different return values (see: {@link
- * java.util.List#remove(Object)} and {@link java.util.Map#remove(Object)}).
- *
- * <P>This class is not thread safe. When a thread safe implementation is
- * required, use {@link Collections#synchronizedMap(Map)} as it is documented,
- * or use explicit synchronization controls.
- *
- * @author <a href="mailto:michael@iammichael.org">Michael A. Smith</A>
- * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
- * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
- */
-public class SequencedHashMap extends HashMap {
-
- /**
- * {@link java.util.Map.Entry} that doubles as a node in the linked list
- * of sequenced mappings.
- **/
- private static class Entry implements Map.Entry {
- // Note: This class cannot easily be made clonable. While the actual
- // implementation of a clone would be simple, defining the semantics is
- // difficult. If a shallow clone is implemented, then entry.next.prev !=
- // entry, which is unintuitive and probably breaks all sorts of assumptions
- // in code that uses this implementation. If a deep clone is
- // implementated, then what happens when the linked list is cyclical (as is
- // the case with SequencedHashMap)? It's impossible to know in the clone
- // when to stop cloning, and thus you end up in a recursive loop,
- // continuously cloning the "next" in the list.
-
- private final Object key;
- private Object value;
-
- // package private to allow the SequencedHashMap to access and manipulate
- // them.
- Entry next = null;
- Entry prev = null;
-
- public Entry(Object key, Object value) {
- this.key = key;
- this.value = value;
- }
-
- // per Map.Entry.getKey()
- public Object getKey() {
- return this.key;
- }
-
- // per Map.Entry.getValue()
- public Object getValue() {
- return this.value;
- }
-
- // per Map.Entry.setValue()
- public Object setValue(Object value) {
- Object oldValue = this.value;
- this.value = value;
- return oldValue;
- }
-
- public int hashCode() {
- // implemented per api docs for Map.Entry.hashCode()
- return ((getKey() == null ? 0 : getKey().hashCode()) ^
- (getValue()==null ? 0 : getValue().hashCode()));
- }
-
- public boolean equals(Object obj) {
- if(obj == null) return false;
- if(obj == this) return true;
- if(!(obj instanceof Map.Entry)) return false;
-
- Map.Entry other = (Map.Entry)obj;
-
- // implemented per api docs for Map.Entry.equals(Object)
- return((getKey() == null ?
- other.getKey() == null :
- getKey().equals(other.getKey())) &&
- (getValue() == null ?
- other.getValue() == null :
- getValue().equals(other.getValue())));
- }
- public String toString() {
- return "[" + getKey() + "=" + getValue() + "]";
- }
- }
-
- /**
- * Construct an empty sentinel used to hold the head (sentinel.next) and the
- * tail (sentinel.prev) of the list. The sentinal has a <code>null</code>
- * key and value.
- **/
- private static final Entry createSentinel() {
- Entry s = new Entry(null, null);
- s.prev = s;
- s.next = s;
- return s;
- }
-
- /**
- * Sentinel used to hold the head and tail of the list of entries.
- **/
- private Entry sentinel;
-
- /**
- * Map of keys to entries
- **/
- private HashMap entries;
-
- /**
- * Construct a new sequenced hash map with default initial size and load
- * factor.
- **/
- public SequencedHashMap() {
- sentinel = createSentinel();
- entries = new HashMap();
- }
-
- /**
- * Construct a new sequenced hash map with the specified initial size and
- * default load factor.
- *
- * @param initialSize the initial size for the hash table
- *
- * @see HashMap#HashMap(int)
- **/
- public SequencedHashMap(int initialSize) {
- sentinel = createSentinel();
- entries = new HashMap(initialSize);
- }
-
- /**
- * Construct a new sequenced hash map with the specified initial size and
- * load factor.
- *
- * @param initialSize the initial size for the hash table
- *
- * @param loadFactor the load factor for the hash table.
- *
- * @see HashMap#HashMap(int,float)
- **/
- public SequencedHashMap(int initialSize, float loadFactor) {
- sentinel = createSentinel();
- entries = new HashMap(initialSize, loadFactor);
- }
-
- /**
- * Construct a new sequenced hash map and add all the elements in the
- * specified map. The order in which the mappings in the specified map are
- * added is defined by {@link #putAll(Map)}.
- **/
- public SequencedHashMap(Map m) {
- this();
- putAll(m);
- }
-
- /**
- * Removes an internal entry from the linked list. This does not remove
- * it from the underlying map.
- **/
- private void removeEntry(Entry entry) {
- entry.next.prev = entry.prev;
- entry.prev.next = entry.next;
- }
-
- /**
- * Inserts a new internal entry to the tail of the linked list. This does
- * not add the entry to the underlying map.
- **/
- private void insertEntry(Entry entry) {
- entry.next = sentinel;
- entry.prev = sentinel.prev;
- sentinel.prev.next = entry;
- sentinel.prev = entry;
- }
-
- // per Map.size()
- public int size() {
- // use the underlying Map's size since size is not maintained here.
- return entries.size();
- }
-
- // per Map.isEmpty()
- public boolean isEmpty() {
- // for quick check whether the map is entry, we can check the linked list
- // and see if there's anything in it.
- return sentinel.next == sentinel;
- }
-
- // per Map.containsKey(Object)
- public boolean containsKey(Object key) {
- // pass on to underlying map implementation
- return entries.containsKey(key);
- }
-
- // per Map.containsValue(Object)
- public boolean containsValue(Object value) {
- // unfortunately, we cannot just pass this call to the underlying map
- // because we are mapping keys to entries, not keys to values. The
- // underlying map doesn't have an efficient implementation anyway, so this
- // isn't a big deal.
-
- // do null comparison outside loop so we only need to do it once. This
- // provides a tighter, more efficient loop at the expense of slight
- // code duplication.
- if(value == null) {
- for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
- if(pos.getValue() == null) return true;
- }
- } else {
- for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
- if(value.equals(pos.getValue())) return true;
- }
- }
- return false;
- }
-
- // per Map.get(Object)
- public Object get(Object o) {
- // find entry for the specified key object
- Entry entry = (Entry)entries.get(o);
- if(entry == null) return null;
-
- return entry.getValue();
- }
-
- /**
- * Return the entry for the "oldest" mapping. That is, return the Map.Entry
- * for the key-value pair that was first put into the map when compared to
- * all the other pairings in the map. This behavior is equivalent to using
- * <code>entrySet().iterator().next()</code>, but this method provides an
- * optimized implementation.
- *
- * @return The first entry in the sequence, or <code>null</code> if the
- * map is empty.
- **/
- public Map.Entry getFirst() {
- // sentinel.next points to the "first" element of the sequence -- the head
- // of the list, which is exactly the entry we need to return. We must test
- // for an empty list though because we don't want to return the sentinel!
- return (isEmpty()) ? null : sentinel.next;
- }
-
- /**
- * Return the key for the "oldest" mapping. That is, return the key for the
- * mapping that was first put into the map when compared to all the other
- * objects in the map. This behavior is equivalent to using
- * <code>getFirst().getKey()</code>, but this method provides a slightly
- * optimized implementation.
- *
- * @return The first key in the sequence, or <code>null</code> if the
- * map is empty.
- **/
- public Object getFirstKey() {
- // sentinel.next points to the "first" element of the sequence -- the head
- // of the list -- and the requisite key is returned from it. An empty list
- // does not need to be tested. In cases where the list is empty,
- // sentinel.next will point to the sentinel itself which has a null key,
- // which is exactly what we would want to return if the list is empty (a
- // nice convient way to avoid test for an empty list)
- return sentinel.next.getKey();
- }
-
- /**
- * Return the value for the "oldest" mapping. That is, return the value for
- * the mapping that was first put into the map when compared to all the
- * other objects in the map. This behavior is equivalent to using
- * <code>getFirst().getValue()</code>, but this method provides a slightly
- * optimized implementation.
- *
- * @return The first value in the sequence, or <code>null</code> if the
- * map is empty.
- **/
- public Object getFirstValue() {
- // sentinel.next points to the "first" element of the sequence -- the head
- // of the list -- and the requisite value is returned from it. An empty
- // list does not need to be tested. In cases where the list is empty,
- // sentinel.next will point to the sentinel itself which has a null value,
- // which is exactly what we would want to return if the list is empty (a
- // nice convient way to avoid test for an empty list)
- return sentinel.next.getValue();
- }
-
- /**
- * Return the entry for the "newest" mapping. That is, return the Map.Entry
- * for the key-value pair that was first put into the map when compared to
- * all the other pairings in the map. The behavior is equivalent to:
- *
- * <pre>
- * Object obj = null;
- * Iterator iter = entrySet().iterator();
- * while(iter.hasNext()) {
- * obj = iter.next();
- * }
- * return (Map.Entry)obj;
- * </pre>
- *
- * However, the implementation of this method ensures an O(1) lookup of the
- * last key rather than O(n).
- *
- * @return The last entry in the sequence, or <code>null</code> if the map
- * is empty.
- **/
- public Map.Entry getLast() {
- // sentinel.prev points to the "last" element of the sequence -- the tail
- // of the list, which is exactly the entry we need to return. We must test
- // for an empty list though because we don't want to return the sentinel!
- return (isEmpty()) ? null : sentinel.prev;
- }
-
- /**
- * Return the key for the "newest" mapping. That is, return the key for the
- * mapping that was last put into the map when compared to all the other
- * objects in the map. This behavior is equivalent to using
- * <code>getLast().getKey()</code>, but this method provides a slightly
- * optimized implementation.
- *
- * @return The last key in the sequence, or <code>null</code> if the map is
- * empty.
- **/
- public Object getLastKey() {
- // sentinel.prev points to the "last" element of the sequence -- the tail
- // of the list -- and the requisite key is returned from it. An empty list
- // does not need to be tested. In cases where the list is empty,
- // sentinel.prev will point to the sentinel itself which has a null key,
- // which is exactly what we would want to return if the list is empty (a
- // nice convient way to avoid test for an empty list)
- return sentinel.prev.getKey();
- }
-
- /**
- * Return the value for the "newest" mapping. That is, return the value for
- * the mapping that was last put into the map when compared to all the other
- * objects in the map. This behavior is equivalent to using
- * <code>getLast().getValue()</code>, but this method provides a slightly
- * optimized implementation.
- *
- * @return The last value in the sequence, or <code>null</code> if the map
- * is empty.
- **/
- public Object getLastValue() {
- // sentinel.prev points to the "last" element of the sequence -- the tail
- // of the list -- and the requisite value is returned from it. An empty
- // list does not need to be tested. In cases where the list is empty,
- // sentinel.prev will point to the sentinel itself which has a null value,
- // which is exactly what we would want to return if the list is empty (a
- // nice convient way to avoid test for an empty list)
- return sentinel.prev.getValue();
- }
-
- // per Map.put(Object,Object)
- public Object put(Object key, Object value) {
-
- Object oldValue = null;
-
- // lookup the entry for the specified key
- Entry e = (Entry)entries.get(key);
-
- // check to see if it already exists
- if(e != null) {
- // remove from list so the entry gets "moved" to the end of list
- removeEntry(e);
-
- // update value in map
- oldValue = e.setValue(value);
-
- // Note: We do not update the key here because its unnecessary. We only
- // do comparisons using equals(Object) and we know the specified key and
- // that in the map are equal in that sense. This may cause a problem if
- // someone does not implement their hashCode() and/or equals(Object)
- // method properly and then use it as a key in this map.
- } else {
- // add new entry
- e = new Entry(key, value);
- entries.put(key, e);
- }
- // assert(entry in map, but not list)
-
- // add to list
- insertEntry(e);
-
- return oldValue;
- }
-
- // per Map.remove(Object)
- public Object remove(Object key) {
- Entry e = (Entry)entries.remove(key);
- if(e == null) return null;
- removeEntry(e);
- return e.getValue();
- }
-
- /**
- * Adds all the mappings in the specified map to this map, replacing any
- * mappings that already exist (as per {@link Map#putAll(Map)}). The order
- * in which the entries are added is determined by the iterator returned
- * from {@link Map#entrySet()} for the specified map.
- *
- * @param t the mappings that should be added to this map.
- *
- * @exception NullPointerException if <code>t</code> is <code>null</code>
- **/
- public void putAll(Map t) {
- Iterator iter = t.entrySet().iterator();
- while(iter.hasNext()) {
- Map.Entry entry = (Map.Entry)iter.next();
- put(entry.getKey(), entry.getValue());
- }
- }
-
- // per Map.clear()
- public void clear() {
- // remove all from the underlying map
- entries.clear();
-
- // and the list
- sentinel.next = sentinel;
- sentinel.prev = sentinel;
- }
-
- // per Map.keySet()
- public Set keySet() {
- return new AbstractSet() {
-
- // required impls
- public Iterator iterator() { return new OrderedIterator(KEY); }
- public boolean remove(Object o) {
- return SequencedHashMap.this.remove(o) != null;
- }
-
- // more efficient impls than abstract set
- public void clear() {
- SequencedHashMap.this.clear();
- }
- public int size() {
- return SequencedHashMap.this.size();
- }
- public boolean isEmpty() {
- return SequencedHashMap.this.isEmpty();
- }
- public boolean contains(Object o) {
- return SequencedHashMap.this.containsKey(o);
- }
-
- };
- }
-
- // per Map.values()
- public Collection values() {
- return new AbstractCollection() {
- // required impl
- public Iterator iterator() { return new OrderedIterator(VALUE); }
- public boolean remove(Object value) {
- // do null comparison outside loop so we only need to do it once. This
- // provides a tighter, more efficient loop at the expense of slight
- // code duplication.
- if(value == null) {
- for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
- if(pos.getValue() == null) {
- SequencedHashMap.this.remove(pos.getKey());
- return true;
- }
- }
- } else {
- for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
- if(value.equals(pos.getValue())) {
- SequencedHashMap.this.remove(pos.getKey());
- return true;
- }
- }
- }
-
- return false;
- }
-
- // more efficient impls than abstract collection
- public void clear() {
- SequencedHashMap.this.clear();
- }
- public int size() {
- return SequencedHashMap.this.size();
- }
- public boolean isEmpty() {
- return SequencedHashMap.this.isEmpty();
- }
- public boolean contains(Object o) {
- return SequencedHashMap.this.containsValue(o);
- }
- };
- }
-
- // per Map.entrySet()
- public Set entrySet() {
- return new AbstractSet() {
- // helper
- private Entry findEntry(Object o) {
- if(o == null) return null;
- if(!(o instanceof Map.Entry)) return null;
-
- Map.Entry e = (Map.Entry)o;
- Entry entry = (Entry)entries.get(e.getKey());
- if(entry.equals(e)) return entry;
- else return null;
- }
-
- // required impl
- public Iterator iterator() {
- return new OrderedIterator(ENTRY);
- }
- public boolean remove(Object o) {
- Entry e = findEntry(o);
- if(e == null) return false;
-
- return SequencedHashMap.this.remove(e.getKey()) != null;
- }
-
- // more efficient impls than abstract collection
- public void clear() {
- SequencedHashMap.this.clear();
- }
- public int size() {
- return SequencedHashMap.this.size();
- }
- public boolean isEmpty() {
- return SequencedHashMap.this.isEmpty();
- }
- public boolean contains(Object o) {
- return findEntry(o) != null;
- }
- };
- }
-
- // constants to define what the iterator should return on "next"
- private static final int KEY = 0;
- private static final int VALUE = 1;
- private static final int ENTRY = 2;
- private static final int REMOVED_MASK = 0x80000000;
-
- private class OrderedIterator implements Iterator {
- /**
- * Holds the type that should be returned from the iterator. The value
- * should be either {@link #KEY}, {@link #VALUE}, or {@link #ENTRY}. To
- * save a tiny bit of memory, this field is also used as a marker for when
- * remove has been called on the current object to prevent a second remove
- * on the same element. Essientially, if this value is negative (i.e. the
- * bit specified by {@link #REMOVED_MASK} is set), the current position
- * has been removed. If positive, remove can still be called.
- **/
- private int returnType;
-
- /**
- * Holds the "current" position in the iterator. when pos.next is the
- * sentinel, we've reached the end of the list.
- **/
- private Entry pos = sentinel;
-
- /**
- * Construct an iterator over the sequenced elements in the order in which
- * they were added. The {@link #next()} method returns the type specified
- * by <code>returnType</code> which must be either {@link #KEY}, {@link
- * #VALUE}, or {@link #ENTRY}.
- **/
- public OrderedIterator(int returnType) {
- //// Since this is a private inner class, nothing else should have
- //// access to the constructor. Since we know the rest of the outer
- //// class uses the iterator correctly, we can leave of the following
- //// check:
- //if(returnType >= 0 && returnType <= 2) {
- // throw new IllegalArgumentException("Invalid iterator type");
- //}
-
- // Set the "removed" bit so that the iterator starts in a state where
- // "next" must be called before "remove" will succeed.
- this.returnType = returnType | REMOVED_MASK;
- }
-
- /**
- * Returns whether there is any additional elements in the iterator to be
- * returned.
- *
- * @return <code>true</code> if there are more elements left to be
- * returned from the iterator; <code>false</code> otherwise.
- **/
- public boolean hasNext() {
- return pos.next != sentinel;
- }
-
- /**
- * Returns the next element from the iterator.
- *
- * @return the next element from the iterator.
- *
- * @exception NoSuchElementException if there are no more elements in the
- * iterator.
- **/
- public Object next() {
- if(pos.next == sentinel) {
- throw new NoSuchElementException();
- }
-
- // clear the "removed" flag
- returnType = returnType & ~REMOVED_MASK;
-
- pos = pos.next;
- switch(returnType) {
- case KEY:
- return pos.getKey();
- case VALUE:
- return pos.getValue();
- case ENTRY:
- return pos;
- default:
- // should never happen
- throw new Error("bad iterator type: " + returnType);
- }
-
- }
-
- /**
- * Removes the last element returned from the {@link #next()} method from
- * the sequenced map.
- *
- * @exception IllegalStateException if there isn't a "last element" to be
- * removed. That is, if {@link #next()} has never been called, or if
- * {@link #remove()} was already called on the element.
- **/
- public void remove() {
- if((returnType & REMOVED_MASK) != 0) {
- throw new IllegalStateException("remove() must follow next()");
- }
-
- // remove the entry
- SequencedHashMap.this.remove(pos.getKey());
-
- // set the removed flag
- returnType = returnType | REMOVED_MASK;
- }
- }
-
- // APIs maintained from previous version of SequencedHashMap for backwards
- // compatibility
-
- /**
- * Creates a shallow copy of this object, preserving the internal structure
- * by copying only references. The keys and values themselves are not
- * <code>clone()</code>'d. The cloned object maintains the same sequence.
- *
- * @return A clone of this instance.
- */
- public Object clone () {
- // yes, calling super.clone() silly since we're just blowing away all
- // the stuff that super might be doing anyway, but for motivations on
- // this, see:
- // http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html
- SequencedHashMap map = (SequencedHashMap)super.clone();
-
- // create new, empty sentinel
- map.sentinel = createSentinel();
-
- // create a new, empty entry map
- // note: this does not preserve the initial capacity and load factor.
- map.entries = new HashMap();
-
- // add all the mappings
- map.putAll(this);
-
- // Note: We cannot just clone the hashmap and sentinel because we must
- // duplicate our internal structures. Cloning those two will not clone all
- // the other entries they reference, and so the cloned hash map will not be
- // able to maintain internal consistency because there are two objects with
- // the same entries. See discussion in the Entry implementation on why we
- // cannot implement a clone of the Entry (and thus why we need to recreate
- // everything).
-
- return map;
- }
-
- /**
- * Returns the Map.Entry at the specified index
- *
- * @exception ArrayIndexOutOfBoundsException if the specified index is
- * <code>< 0</code> or <code>></code> the size of the map.
- **/
- private Map.Entry getEntry(int index) {
- Entry pos = sentinel;
-
- if(index < 0) {
- throw new ArrayIndexOutOfBoundsException(index + " < 0");
- }
-
- // loop to one before the position
- int i = -1;
- while(i < (index-1) && pos.next != sentinel) {
- i++;
- pos = pos.next;
- }
- // pos.next is the requested position
-
- // if sentinel is next, past end of list
- if(pos.next == sentinel) {
- throw new ArrayIndexOutOfBoundsException(index + " >= " + (i + 1));
- }
-
- return pos.next;
- }
-
- /**
- * Returns the key at the specified index.
- *
- * @exception ArrayIndexOutOfBoundsException if the <code>index</code> is
- * <code>< 0</code> or <code>></code> the size of the map.
- */
- public Object get (int index)
- {
- return getEntry(index).getKey();
- }
-
- /**
- * Returns the value at the specified index.
- *
- * @exception ArrayIndexOutOfBoundsException if the <code>index</code> is
- * <code>< 0</code> or <code>></code> the size of the map.
- */
- public Object getValue (int index)
- {
- return getEntry(index).getValue();
- }
-
- /**
- * Returns the index of the specified key.
- */
- public int indexOf (Object key)
- {
- Entry e = (Entry)entries.get(key);
- int pos = 0;
- while(e.prev != sentinel) {
- pos++;
- e = e.prev;
- }
- return pos;
- }
-
- /**
- * Returns a key iterator.
- */
- public Iterator iterator ()
- {
- return keySet().iterator();
- }
-
- /**
- * Returns the last index of the specified key.
- */
- public int lastIndexOf (Object key)
- {
- // keys in a map are guarunteed to be unique
- return indexOf(key);
- }
-
- /**
- * Returns a List view of the keys rather than a set view. The returned
- * list is unmodifiable. This is required because changes to the values of
- * the list (using {@link java.util.ListIterator#set(Object)}) will
- * effectively remove the value from the list and reinsert that value at
- * the end of the list, which is an unexpected side effect of changing the
- * value of a list. This occurs because changing the key, changes when the
- * mapping is added to the map and thus where it appears in the list.
- *
- * <P>An alternative to this method is to use {@link #keySet()}
- *
- * @see #keySet()
- * @return The ordered list of keys.
- */
- public List sequence()
- {
- List l = new ArrayList(size());
- Iterator iter = keySet().iterator();
- while(iter.hasNext()) {
- l.add(iter.next());
- }
-
- return Collections.unmodifiableList(l);
- }
-
- /**
- * Removes the element at the specified index.
- *
- * @param index The index of the object to remove.
- * @return The previous value coressponding the <code>key</code>, or
- * <code>null</code> if none existed.
- *
- * @exception ArrayIndexOutOfBoundsException if the <code>index</code> is
- * <code>< 0</code> or <code>></code> the size of the map.
- */
- public Object remove (int index)
- {
- return remove(get(index));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/SingletonIterator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/SingletonIterator.java b/src/java/org/apache/commons/collections/SingletonIterator.java
deleted file mode 100644
index 61a3737..0000000
--- a/src/java/org/apache/commons/collections/SingletonIterator.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/SingletonIterator.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/** <p><code>SingleIterator</code> is an {@link Iterator} over a single
- * object instance.</p>
- *
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- * @version $Revision: 1.2 $
- */
-public class SingletonIterator implements Iterator {
-
- private boolean first = true;
- private Object object;
-
- public SingletonIterator(Object object) {
- this.object = object;
- }
-
- public boolean hasNext() {
- return first;
- }
-
- public Object next() {
- if (! first ) {
- throw new NoSuchElementException();
- }
- Object answer = object;
- object = null;
- first = false;
- return answer;
- }
-
- public void remove() {
- throw new UnsupportedOperationException( "remove() is not supported by this iterator" );
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/SortedBag.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/SortedBag.java b/src/java/org/apache/commons/collections/SortedBag.java
deleted file mode 100644
index 7c6da63..0000000
--- a/src/java/org/apache/commons/collections/SortedBag.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SortedBag.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.Comparator;
-
-/**
- * A type of {@link Bag} that maintains order among its unique
- * representative members.
- * @author Chuck Burdick
- **/
-public interface SortedBag extends Bag {
-
- /**
- * Returns the comparator associated with this sorted set, or null
- * if it uses its elements' natural ordering.
- **/
- public Comparator comparator();
-
- /**
- * Returns the first (lowest) member.
- **/
- public Object first();
-
- /**
- * Returns the last (highest) member.
- **/
- public Object last();
-}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/TreeBag.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/TreeBag.java b/src/java/org/apache/commons/collections/TreeBag.java
deleted file mode 100644
index 64760dc..0000000
--- a/src/java/org/apache/commons/collections/TreeBag.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/TreeBag.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-/**
- * An implementation of {@link Bag} that is backed by a {@link
- * TreeMap}. Order will be maintained among the unique representative
- * members.
- *
- * @author Chuck Burdick
- **/
-public class TreeBag extends AbstractBag implements SortedBag, Bag {
- public TreeBag() {
- setMap(new TreeMap());
- }
-
- /**
- * New {@link Bag} that maintains order on its unique
- * representative members according to the given {@link
- * Comparator}.
- **/
- public TreeBag(Comparator c) {
- setMap(new TreeMap(c));
- }
-
- /**
- * New {@link Bag} containing all the members of the given
- * collection.
- * @see #addAll
- **/
- public TreeBag(Collection c) {
- this();
- addAll(c);
- }
-
- public Object first() {
- return ((SortedMap)getMap()).firstKey();
- }
-
- public Object last() {
- return ((SortedMap)getMap()).lastKey();
- }
-
- public Comparator comparator() {
- return ((SortedMap)getMap()).comparator();
- }
-}
-
-
-
-
-
-
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/test/org/apache/commons/collections/TestAll.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestAll.java b/src/test/org/apache/commons/collections/TestAll.java
index f3107d9..dc87876 100644
--- a/src/test/org/apache/commons/collections/TestAll.java
+++ b/src/test/org/apache/commons/collections/TestAll.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestAll.java,v 1.15 2002/02/13 20:59:12 morgand Exp $
- * $Revision: 1.15 $
- * $Date: 2002/02/13 20:59:12 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestAll.java,v 1.15.2.1 2002/02/26 00:58:29 morgand Exp $
+ * $Revision: 1.15.2.1 $
+ * $Date: 2002/02/26 00:58:29 $
*
* ====================================================================
*
@@ -66,7 +66,7 @@ import junit.framework.*;
/**
* Entry point for all Collections tests.
* @author Rodney Waldhoff
- * @version $Id: TestAll.java,v 1.15 2002/02/13 20:59:12 morgand Exp $
+ * @version $Id: TestAll.java,v 1.15.2.1 2002/02/26 00:58:29 morgand Exp $
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
@@ -88,14 +88,8 @@ public class TestAll extends TestCase {
suite.addTest(TestFastHashMap1.suite());
suite.addTest(TestFastTreeMap.suite());
suite.addTest(TestFastTreeMap1.suite());
- suite.addTest(TestHashBag.suite());
suite.addTest(TestHashMap.suite());
- suite.addTest(TestMultiHashMap.suite());
- suite.addTest(TestSequencedHashMap.suite());
- suite.addTest(TestSingletonIterator.suite());
- suite.addTest(TestTreeBag.suite());
suite.addTest(TestTreeMap.suite());
- suite.addTest(TestDoubleOrderedMap.suite());
suite.addTest(TestLRUMap.suite());
return suite;
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/test/org/apache/commons/collections/TestBag.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestBag.java b/src/test/org/apache/commons/collections/TestBag.java
deleted file mode 100644
index 1f3c17c..0000000
--- a/src/test/org/apache/commons/collections/TestBag.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestBag.java,v 1.1 2001/08/29 15:28:07 jstrachan Exp $
- * $Revision: 1.1 $
- * $Date: 2001/08/29 15:28:07 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import junit.framework.*;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Tests base {@link Bag} methods and contracts.
- * <p>
- * To use, simply extend this class, and implement
- * the {@link #makeBag} method.
- * <p>
- * If your {@link Bag} fails one of these tests by design,
- * you may still use this base set of cases. Simply override the
- * test case (method) your {@link Bag} fails.
- *
- * @author Chuck Burdick
- * @version $Id: TestBag.java,v 1.1 2001/08/29 15:28:07 jstrachan Exp $
- */
-public abstract class TestBag extends TestCollection {
- public TestBag(String testName) {
- super(testName);
- }
-
- /**
- * Return a new, empty {@link Bag} to used for testing.
- */
- public abstract Bag makeBag();
-
- public Collection makeCollection() {
- return makeBag();
- }
-
- public void testBagAdd() {
- Bag bag = makeBag();
- bag.add("A");
- assertTrue("Should contain 'A'", bag.contains("A"));
- assertEquals("Should have count of 1",
- 1, bag.getCount("A"));
- bag.add("A");
- assertTrue("Should contain 'A'", bag.contains("A"));
- assertEquals("Should have count of 2",
- 2, bag.getCount("A"));
- bag.add("B");
- assertTrue(bag.contains("A"));
- assertTrue(bag.contains("B"));
- }
-
- public void testBagEqualsSelf() {
- Bag bag = makeBag();
- assertTrue(bag.equals(bag));
- bag.add("elt");
- assertTrue(bag.equals(bag));
- bag.add("elt"); // again
- assertTrue(bag.equals(bag));
- bag.add("elt2");
- assertTrue(bag.equals(bag));
- }
-
- public void testRemove() {
- Bag bag = makeBag();
- bag.add("A");
- assertEquals("Should have count of 1", 1, bag.getCount("A"));
- bag.remove("A");
- assertEquals("Should have count of 0", 0, bag.getCount("A"));
- bag.add("A");
- bag.add("A");
- bag.add("A");
- bag.add("A");
- assertEquals("Should have count of 4", 4, bag.getCount("A"));
- bag.remove("A", 0);
- assertEquals("Should have count of 4", 4, bag.getCount("A"));
- bag.remove("A", 2);
- assertEquals("Should have count of 2", 2, bag.getCount("A"));
- bag.remove("A");
- assertEquals("Should have count of 0", 0, bag.getCount("A"));
- }
-
- public void testRemoveAll() {
- Bag bag = makeBag();
- bag.add("A", 2);
- assertEquals("Should have count of 2", 2, bag.getCount("A"));
- bag.add("B");
- bag.add("C");
- assertEquals("Should have count of 4", 4, bag.size());
- List delete = new ArrayList();
- delete.add("A");
- delete.add("B");
- bag.removeAll(delete);
- assertEquals("Should have count of 1", 1, bag.getCount("A"));
- assertEquals("Should have count of 0", 0, bag.getCount("B"));
- assertEquals("Should have count of 1", 1, bag.getCount("C"));
- assertEquals("Should have count of 2", 2, bag.size());
- }
-
- public void testContains() {
- Bag bag = makeBag();
- bag.add("A");
- bag.add("A");
- bag.add("A");
- bag.add("B");
- bag.add("B");
- List compare = new ArrayList();
- compare.add("A");
- compare.add("B");
- assertEquals("Other list has 1 'B'", 1,
- (new HashBag(compare)).getCount("B"));
- assertTrue("Bag has at least 1 'B'", 1 <= bag.getCount("B"));
- assertTrue("Bag contains items in the list", bag.containsAll(compare));
- compare.add("A");
- compare.add("B");
- assertEquals("Other list has 2 'B'", 2,
- (new HashBag(compare)).getCount("B"));
- assertTrue("Bag has at least 2 'B'", 2 <= bag.getCount("B"));
- assertTrue("Bag contains items in the list", bag.containsAll(compare));
- compare.add("A");
- compare.add("B");
- assertEquals("Other list has 3 'B'", 3,
- (new HashBag(compare)).getCount("B"));
- assertTrue("Bag does not have 3 'B'", 3 > bag.getCount("B"));
- assertTrue("Bag contains items in the list", !bag.containsAll(compare));
- }
-
- public void testSize() {
- Bag bag = makeBag();
- bag.add("A");
- bag.add("A");
- bag.add("A");
- bag.add("B");
- bag.add("B");
- assertEquals("Should have 5 total items", 5, bag.size());
- bag.remove("A", 2);
- assertEquals("Should have 1 'A'", 1, bag.getCount("A"));
- assertEquals("Should have 3 total items", 3, bag.size());
- bag.remove("B");
- assertEquals("Should have 1 total item", 1, bag.size());
- }
-
- public void testRetainAll() {
- Bag bag = makeBag();
- bag.add("A");
- bag.add("A");
- bag.add("A");
- bag.add("B");
- bag.add("B");
- bag.add("C");
- List retains = new ArrayList();
- retains.add("B");
- retains.add("C");
- bag.retainAll(retains);
- assertEquals("Should have 2 total items", 2, bag.size());
- }
-
- public void testIterator() {
- Bag bag = makeBag();
- bag.add("A");
- bag.add("A");
- bag.add("B");
- assertEquals("Bag should have 3 items", 3, bag.size());
- Iterator i = bag.iterator();
- assertEquals("First should be 'A'", "A", i.next());
- assertEquals("Second should be 'A'", "A", i.next());
- i.remove();
- assertEquals("Third should be 'B'", "B", i.next());
- assertTrue("Should have no more", !i.hasNext());
- assertEquals("Bag should have 2 items", 2, bag.size());
- assertEquals("Bag should have 1 'A'", 1, bag.getCount("A"));
- }
-
- public void testIteratorFail() {
- Bag bag = makeBag();
- bag.add("A");
- bag.add("A");
- bag.add("B");
- Iterator i = bag.iterator();
- assertEquals("First should be 'A'", "A", i.next());
- bag.remove("A");
- try {
- i.next();
- fail("Should throw ConcurrentModificationException");
- } catch (ConcurrentModificationException e) {
- // expected
- }
- }
-}
-
-
[14/18] commons-collections git commit: merged with HEAD
Posted by ch...@apache.org.
merged with HEAD
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130605 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/a1fdbead
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/a1fdbead
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/a1fdbead
Branch: refs/heads/collections_1_x_branch
Commit: a1fdbead61b7ecf4b2db39bcf13e750114ce1847
Parents: 37f759c
Author: Morgan James Delagrange <mo...@apache.org>
Authored: Tue Feb 26 20:23:10 2002 +0000
Committer: Morgan James Delagrange <mo...@apache.org>
Committed: Tue Feb 26 20:23:10 2002 +0000
----------------------------------------------------------------------
data/test/FastHashMap.emptyMap.version1.obj | Bin 200 -> 0 bytes
data/test/FastHashMap.fullMap.version1.obj | Bin 451 -> 0 bytes
data/test/FastTreeMap.emptyMap.version1.obj | Bin 191 -> 0 bytes
data/test/FastTreeMap.fullMap.version1.obj | Bin 630 -> 0 bytes
data/test/LRUMap.emptyCollection.version1.obj | Bin 0 -> 126 bytes
data/test/LRUMap.emptyMap.version1.obj | Bin 126 -> 0 bytes
data/test/LRUMap.fullCollection.version1.obj | Bin 0 -> 663 bytes
data/test/LRUMap.fullMap.version1.obj | Bin 663 -> 0 bytes
.../org/apache/commons/collections/TestAll.java | 9 +-
.../commons/collections/TestArrayList.java | 18 +--
.../commons/collections/TestArrayStack.java | 12 +-
.../collections/TestCursorableLinkedList.java | 10 +-
.../commons/collections/TestFastArrayList.java | 12 +-
.../apache/commons/collections/TestList.java | 136 +++++++++++++++----
.../org/apache/commons/collections/TestMap.java | 41 ++----
.../apache/commons/collections/TestObject.java | 38 +++++-
16 files changed, 177 insertions(+), 99 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/data/test/FastHashMap.emptyMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastHashMap.emptyMap.version1.obj b/data/test/FastHashMap.emptyMap.version1.obj
deleted file mode 100644
index 113e5cc..0000000
Binary files a/data/test/FastHashMap.emptyMap.version1.obj and /dev/null differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/data/test/FastHashMap.fullMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastHashMap.fullMap.version1.obj b/data/test/FastHashMap.fullMap.version1.obj
deleted file mode 100644
index 3e8dff1..0000000
Binary files a/data/test/FastHashMap.fullMap.version1.obj and /dev/null differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/data/test/FastTreeMap.emptyMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastTreeMap.emptyMap.version1.obj b/data/test/FastTreeMap.emptyMap.version1.obj
deleted file mode 100644
index ad18ca8..0000000
Binary files a/data/test/FastTreeMap.emptyMap.version1.obj and /dev/null differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/data/test/FastTreeMap.fullMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastTreeMap.fullMap.version1.obj b/data/test/FastTreeMap.fullMap.version1.obj
deleted file mode 100644
index 32ef3e3..0000000
Binary files a/data/test/FastTreeMap.fullMap.version1.obj and /dev/null differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/data/test/LRUMap.emptyCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/LRUMap.emptyCollection.version1.obj b/data/test/LRUMap.emptyCollection.version1.obj
new file mode 100644
index 0000000..c235e33
Binary files /dev/null and b/data/test/LRUMap.emptyCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/data/test/LRUMap.emptyMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/LRUMap.emptyMap.version1.obj b/data/test/LRUMap.emptyMap.version1.obj
deleted file mode 100644
index c235e33..0000000
Binary files a/data/test/LRUMap.emptyMap.version1.obj and /dev/null differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/data/test/LRUMap.fullCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/LRUMap.fullCollection.version1.obj b/data/test/LRUMap.fullCollection.version1.obj
new file mode 100644
index 0000000..417b1fa
Binary files /dev/null and b/data/test/LRUMap.fullCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/data/test/LRUMap.fullMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/LRUMap.fullMap.version1.obj b/data/test/LRUMap.fullMap.version1.obj
deleted file mode 100644
index 417b1fa..0000000
Binary files a/data/test/LRUMap.fullMap.version1.obj and /dev/null differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/src/test/org/apache/commons/collections/TestAll.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestAll.java b/src/test/org/apache/commons/collections/TestAll.java
index 81385a9..42536b3 100644
--- a/src/test/org/apache/commons/collections/TestAll.java
+++ b/src/test/org/apache/commons/collections/TestAll.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestAll.java,v 1.15.2.3 2002/02/26 06:17:51 morgand Exp $
- * $Revision: 1.15.2.3 $
- * $Date: 2002/02/26 06:17:51 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestAll.java,v 1.15.2.4 2002/02/26 20:23:10 morgand Exp $
+ * $Revision: 1.15.2.4 $
+ * $Date: 2002/02/26 20:23:10 $
*
* ====================================================================
*
@@ -66,7 +66,7 @@ import junit.framework.*;
/**
* Entry point for all Collections tests.
* @author Rodney Waldhoff
- * @version $Id: TestAll.java,v 1.15.2.3 2002/02/26 06:17:51 morgand Exp $
+ * @version $Id: TestAll.java,v 1.15.2.4 2002/02/26 20:23:10 morgand Exp $
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
@@ -76,7 +76,6 @@ public class TestAll extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(TestArrayIterator.suite());
- suite.addTest(TestArrayList.suite());
suite.addTest(TestArrayStack.suite());
suite.addTest(TestCollectionUtils.suite());
suite.addTest(TestCursorableLinkedList.suite());
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/src/test/org/apache/commons/collections/TestArrayList.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestArrayList.java b/src/test/org/apache/commons/collections/TestArrayList.java
index 44a2e8f..ef929ac 100644
--- a/src/test/org/apache/commons/collections/TestArrayList.java
+++ b/src/test/org/apache/commons/collections/TestArrayList.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestArrayList.java,v 1.2 2001/07/14 23:33:26 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2001/07/14 23:33:26 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestArrayList.java,v 1.2.2.1 2002/02/26 20:23:10 morgand Exp $
+ * $Revision: 1.2.2.1 $
+ * $Date: 2002/02/26 20:23:10 $
*
* ====================================================================
*
@@ -69,9 +69,9 @@ import java.util.List;
/**
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: TestArrayList.java,v 1.2 2001/07/14 23:33:26 craigmcc Exp $
+ * @version $Id: TestArrayList.java,v 1.2.2.1 2002/02/26 20:23:10 morgand Exp $
*/
-public class TestArrayList extends TestList
+public abstract class TestArrayList extends TestList
{
public TestArrayList(String testName)
{
@@ -93,13 +93,7 @@ public class TestArrayList extends TestList
public void setUp()
{
- list = (ArrayList) makeList();
- }
-
- public List makeList()
- {
- ArrayList al = new ArrayList();
- return (al);
+ list = (ArrayList) makeEmptyList();
}
public void testNewArrayList()
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/src/test/org/apache/commons/collections/TestArrayStack.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestArrayStack.java b/src/test/org/apache/commons/collections/TestArrayStack.java
index 1b57b65..624005d 100644
--- a/src/test/org/apache/commons/collections/TestArrayStack.java
+++ b/src/test/org/apache/commons/collections/TestArrayStack.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestArrayStack.java,v 1.5 2001/07/14 23:33:26 craigmcc Exp $
- * $Revision: 1.5 $
- * $Date: 2001/07/14 23:33:26 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestArrayStack.java,v 1.5.2.1 2002/02/26 20:23:10 morgand Exp $
+ * $Revision: 1.5.2.1 $
+ * $Date: 2002/02/26 20:23:10 $
*
* ====================================================================
*
@@ -66,7 +66,7 @@ import java.util.*;
/**
* @author Craig McClanahan
- * @version $Id: TestArrayStack.java,v 1.5 2001/07/14 23:33:26 craigmcc Exp $
+ * @version $Id: TestArrayStack.java,v 1.5.2.1 2002/02/26 20:23:10 morgand Exp $
*/
public class TestArrayStack extends TestArrayList {
@@ -84,14 +84,14 @@ public class TestArrayStack extends TestArrayList {
junit.textui.TestRunner.main(testCaseName);
}
- public List makeList() {
+ public List makeEmptyList() {
return new ArrayStack();
}
protected ArrayStack stack = null;
public void setUp() {
- stack = (ArrayStack) makeList();
+ stack = (ArrayStack) makeEmptyList();
list = stack;
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/src/test/org/apache/commons/collections/TestCursorableLinkedList.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestCursorableLinkedList.java b/src/test/org/apache/commons/collections/TestCursorableLinkedList.java
index 87c5349..0e1e665 100644
--- a/src/test/org/apache/commons/collections/TestCursorableLinkedList.java
+++ b/src/test/org/apache/commons/collections/TestCursorableLinkedList.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestCursorableLinkedList.java,v 1.3 2001/07/14 23:33:27 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/07/14 23:33:27 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestCursorableLinkedList.java,v 1.3.2.1 2002/02/26 20:23:10 morgand Exp $
+ * $Revision: 1.3.2.1 $
+ * $Date: 2002/02/26 20:23:10 $
*
* ====================================================================
*
@@ -66,7 +66,7 @@ import java.util.*;
/**
* @author Rodney Waldhoff
- * @version $Id: TestCursorableLinkedList.java,v 1.3 2001/07/14 23:33:27 craigmcc Exp $
+ * @version $Id: TestCursorableLinkedList.java,v 1.3.2.1 2002/02/26 20:23:10 morgand Exp $
*/
public class TestCursorableLinkedList extends TestList {
public TestCursorableLinkedList(String testName) {
@@ -88,7 +88,7 @@ public class TestCursorableLinkedList extends TestList {
list = new CursorableLinkedList();
}
- public List makeList() {
+ public List makeEmptyList() {
return new CursorableLinkedList();
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/src/test/org/apache/commons/collections/TestFastArrayList.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestFastArrayList.java b/src/test/org/apache/commons/collections/TestFastArrayList.java
index 1905a6e..7907e0c 100644
--- a/src/test/org/apache/commons/collections/TestFastArrayList.java
+++ b/src/test/org/apache/commons/collections/TestFastArrayList.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastArrayList.java,v 1.3 2001/04/21 12:22:30 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/04/21 12:22:30 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastArrayList.java,v 1.3.2.1 2002/02/26 20:23:10 morgand Exp $
+ * $Revision: 1.3.2.1 $
+ * $Date: 2002/02/26 20:23:10 $
*
* ====================================================================
*
@@ -69,7 +69,7 @@ import java.util.List;
/**
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: TestFastArrayList.java,v 1.3 2001/04/21 12:22:30 craigmcc Exp $
+ * @version $Id: TestFastArrayList.java,v 1.3.2.1 2002/02/26 20:23:10 morgand Exp $
*/
public class TestFastArrayList extends TestArrayList
{
@@ -91,10 +91,10 @@ public class TestFastArrayList extends TestArrayList
public void setUp()
{
- list = (ArrayList) makeList();
+ list = (ArrayList) makeEmptyList();
}
- public List makeList()
+ public List makeEmptyList()
{
FastArrayList fal = new FastArrayList();
fal.setFast(false);
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/src/test/org/apache/commons/collections/TestList.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestList.java b/src/test/org/apache/commons/collections/TestList.java
index fd80712..227b05b 100644
--- a/src/test/org/apache/commons/collections/TestList.java
+++ b/src/test/org/apache/commons/collections/TestList.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestList.java,v 1.5 2001/07/14 23:33:27 craigmcc Exp $
- * $Revision: 1.5 $
- * $Date: 2001/07/14 23:33:27 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestList.java,v 1.5.2.1 2002/02/26 20:23:10 morgand Exp $
+ * $Revision: 1.5.2.1 $
+ * $Date: 2002/02/26 20:23:10 $
*
* ====================================================================
*
@@ -62,6 +62,8 @@
package org.apache.commons.collections;
import junit.framework.*;
+import java.io.IOException;
+import java.io.Serializable;
import java.util.List;
import java.util.Collection;
import java.util.Arrays;
@@ -80,7 +82,7 @@ import java.util.ListIterator;
* test case (method) your {@link List} fails.
*
* @author Rodney Waldhoff
- * @version $Id: TestList.java,v 1.5 2001/07/14 23:33:27 craigmcc Exp $
+ * @version $Id: TestList.java,v 1.5.2.1 2002/02/26 20:23:10 morgand Exp $
*/
public abstract class TestList extends TestCollection {
public TestList(String testName) {
@@ -90,14 +92,30 @@ public abstract class TestList extends TestCollection {
/**
* Return a new, empty {@link List} to used for testing.
*/
- public abstract List makeList();
+ public abstract List makeEmptyList();
+
+ public List makeFullList() {
+ // only works if list supports optional "add(Object)"
+ // and "add(int,Object)" operations
+ List list = makeEmptyList();
+ list.add("1");
+ // must be able to add to the end this way
+ list.add(list.size(),"4");
+ // must support duplicates
+ list.add("1");
+ // must support insertions
+ list.add(1,"3");
+
+ // resultant list: 1, 3, 4, 1
+ return list;
+ }
public Collection makeCollection() {
- return makeList();
+ return makeEmptyList();
}
public void testListAddByIndexBoundsChecking() {
- List list = makeList();
+ List list = makeEmptyList();
try {
list.add(Integer.MIN_VALUE,"element");
@@ -153,7 +171,7 @@ public abstract class TestList extends TestCollection {
}
public void testListAddByIndexBoundsChecking2() {
- List list = makeList();
+ List list = makeEmptyList();
boolean added = tryToAdd(list,"element");
try {
@@ -184,7 +202,7 @@ public abstract class TestList extends TestCollection {
}
public void testListAddByIndex() {
- List list = makeList();
+ List list = makeEmptyList();
assertEquals(0,list.size());
if(tryToAdd(list,0,"element2")) {
assertEquals(1,list.size());
@@ -201,7 +219,7 @@ public abstract class TestList extends TestCollection {
}
public void testListAdd() {
- List list = makeList();
+ List list = makeEmptyList();
if(tryToAdd(list,"1")) {
assertTrue(list.contains("1"));
if(tryToAdd(list,"2")) {
@@ -223,7 +241,7 @@ public abstract class TestList extends TestCollection {
}
public void testListEqualsSelf() {
- List list = makeList();
+ List list = makeEmptyList();
assertTrue(list.equals(list));
tryToAdd(list,"elt");
assertTrue(list.equals(list));
@@ -232,7 +250,7 @@ public abstract class TestList extends TestCollection {
}
public void testListEqualsArrayList() {
- List list1 = makeList();
+ List list1 = makeEmptyList();
List list2 = new ArrayList();
assertTrue(list1.equals(list2));
assertEquals(list1.hashCode(),list2.hashCode());
@@ -252,8 +270,8 @@ public abstract class TestList extends TestCollection {
}
public void testListEquals() {
- List list1 = makeList();
- List list2 = makeList();
+ List list1 = makeEmptyList();
+ List list2 = makeEmptyList();
assertTrue(list1.equals(list2));
if(tryToAdd(list1,"a") && tryToAdd(list2,"a")) {
assertTrue(list1.equals(list2));
@@ -270,7 +288,7 @@ public abstract class TestList extends TestCollection {
}
public void testListGetByIndex() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"a");
tryToAdd(list,"b");
tryToAdd(list,"c");
@@ -284,7 +302,7 @@ public abstract class TestList extends TestCollection {
}
public void testListGetByIndexBoundsChecking() {
- List list = makeList();
+ List list = makeEmptyList();
try {
list.get(Integer.MIN_VALUE);
@@ -323,7 +341,7 @@ public abstract class TestList extends TestCollection {
}
public void testListGetByIndexBoundsChecking2() {
- List list = makeList();
+ List list = makeEmptyList();
boolean added = tryToAdd(list,"a");
try {
@@ -356,7 +374,7 @@ public abstract class TestList extends TestCollection {
}
public void testListIndexOf() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"a");
tryToAdd(list,"b");
tryToAdd(list,"c");
@@ -371,7 +389,7 @@ public abstract class TestList extends TestCollection {
}
public void testListLastIndexOf1() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"a");
tryToAdd(list,"b");
tryToAdd(list,"c");
@@ -386,7 +404,7 @@ public abstract class TestList extends TestCollection {
}
public void testListLastIndexOf2() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"a");
tryToAdd(list,"b");
tryToAdd(list,"c");
@@ -434,7 +452,7 @@ public abstract class TestList extends TestCollection {
}
public void testListSetByIndexBoundsChecking() {
- List list = makeList();
+ List list = makeEmptyList();
try {
list.set(Integer.MIN_VALUE,"a");
@@ -503,7 +521,7 @@ public abstract class TestList extends TestCollection {
}
public void testListSetByIndexBoundsChecking2() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"element");
tryToAdd(list,"element2");
@@ -561,7 +579,7 @@ public abstract class TestList extends TestCollection {
}
public void testListSetByIndex() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"element");
tryToAdd(list,"element2");
tryToAdd(list,"element3");
@@ -586,7 +604,7 @@ public abstract class TestList extends TestCollection {
}
public void testListRemoveByIndex() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"element");
tryToAdd(list,"element2");
tryToAdd(list,"element3");
@@ -615,7 +633,7 @@ public abstract class TestList extends TestCollection {
}
public void testListRemoveByValue() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"element1");
tryToAdd(list,"element2");
tryToAdd(list,"element3");
@@ -637,7 +655,7 @@ public abstract class TestList extends TestCollection {
}
public void testListListIteratorNextPrev() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"element1");
tryToAdd(list,"element2");
tryToAdd(list,"element3");
@@ -667,7 +685,7 @@ public abstract class TestList extends TestCollection {
}
public void testListListIteratorNextIndexPrevIndex() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"element1");
tryToAdd(list,"element2");
tryToAdd(list,"element3");
@@ -689,7 +707,7 @@ public abstract class TestList extends TestCollection {
}
public void testListListIteratorSet() {
- List list = makeList();
+ List list = makeEmptyList();
tryToAdd(list,"element1");
tryToAdd(list,"element2");
tryToAdd(list,"element3");
@@ -782,4 +800,66 @@ public abstract class TestList extends TestCollection {
}
}
+ public void testEmptyListSerialization()
+ throws IOException, ClassNotFoundException {
+ List list = makeEmptyList();
+ if (!(list instanceof Serializable)) return;
+
+ byte[] objekt = writeExternalFormToBytes((Serializable) list);
+ List list2 = (List) readExternalFormFromBytes(objekt);
+
+ assertTrue("Both lists are empty",list.size() == 0);
+ assertTrue("Both lists are empty",list2.size() == 0);
+ }
+
+ public void testFullListSerialization()
+ throws IOException, ClassNotFoundException {
+ List list = makeFullList();
+ if (!(list instanceof Serializable)) return;
+
+ byte[] objekt = writeExternalFormToBytes((Serializable) list);
+ List list2 = (List) readExternalFormFromBytes(objekt);
+
+ assertEquals("Both lists are same size",list.size(), 4);
+ assertEquals("Both lists are same size",list2.size(),4);
+ }
+
+ /**
+ * Compare the current serialized form of the List
+ * against the canonical version in CVS.
+ */
+ public void testEmptyListCompatibility() throws IOException, ClassNotFoundException {
+ /**
+ * Create canonical objects with this code
+ List list = makeEmptyList();
+ if (!(list instanceof Serializable)) return;
+
+ writeExternalFormToDisk((Serializable) list, getCanonicalEmptyCollectionName(list));
+ */
+
+ // test to make sure the canonical form has been preserved
+ if (!(makeEmptyList() instanceof Serializable)) return;
+ List list = (List) readExternalFormFromDisk(getCanonicalEmptyCollectionName(makeEmptyList()));
+ assertTrue("List is empty",list.size() == 0);
+ }
+
+ /**
+ * Compare the current serialized form of the List
+ * against the canonical version in CVS.
+ */
+ public void testFullListCompatibility() throws IOException, ClassNotFoundException {
+ /**
+ * Create canonical objects with this code
+ List list = makeFullList();
+ if (!(list instanceof Serializable)) return;
+
+ writeExternalFormToDisk((Serializable) list, getCanonicalFullCollectionName(list));
+ */
+
+ // test to make sure the canonical form has been preserved
+ if (!(makeFullList() instanceof Serializable)) return;
+ List list = (List) readExternalFormFromDisk(getCanonicalFullCollectionName(makeFullList()));
+ assertEquals("List is the right size",list.size(), 4);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/src/test/org/apache/commons/collections/TestMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestMap.java b/src/test/org/apache/commons/collections/TestMap.java
index 7c18049..b522bcd 100644
--- a/src/test/org/apache/commons/collections/TestMap.java
+++ b/src/test/org/apache/commons/collections/TestMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.3.2.3 2002/02/26 06:28:41 morgand Exp $
- * $Revision: 1.3.2.3 $
- * $Date: 2002/02/26 06:28:41 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.3.2.4 2002/02/26 20:18:53 morgand Exp $
+ * $Revision: 1.3.2.4 $
+ * $Date: 2002/02/26 20:18:53 $
*
* ====================================================================
*
@@ -87,7 +87,7 @@ import java.util.NoSuchElementException;
*
* @author Michael Smith
* @author Rodney Waldhoff
- * @version $Id: TestMap.java,v 1.3.2.3 2002/02/26 06:28:41 morgand Exp $
+ * @version $Id: TestMap.java,v 1.3.2.4 2002/02/26 20:18:53 morgand Exp $
*/
public abstract class TestMap extends TestObject {
@@ -929,31 +929,6 @@ public abstract class TestMap extends TestObject {
assertEquals("Both maps are same size",map2.size(),getSampleKeys().length);
}
-
- public String getCanonicalEmptyMapName(Map map) {
- StringBuffer retval = new StringBuffer();
- retval.append("data/test/");
- String mapName = map.getClass().getName();
- mapName = mapName.substring(mapName.lastIndexOf(".")+1,mapName.length());
- retval.append(mapName);
- retval.append(".emptyMap.version");
- retval.append(getCompatibilityVersion());
- retval.append(".obj");
- return retval.toString();
- }
-
- public String getCanonicalFullMapName(Map map) {
- StringBuffer retval = new StringBuffer();
- retval.append("data/test/");
- String mapName = map.getClass().getName();
- mapName = mapName.substring(mapName.lastIndexOf(".")+1,mapName.length());
- retval.append(mapName);
- retval.append(".fullMap.version");
- retval.append(getCompatibilityVersion());
- retval.append(".obj");
- return retval.toString();
- }
-
/**
* Compare the current serialized form of the Map
* against the canonical version in CVS.
@@ -965,12 +940,12 @@ public abstract class TestMap extends TestObject {
map = makeEmptyMap();
if (!(map instanceof Serializable)) return;
- writeExternalFormToDisk((Serializable) map, getCanonicalEmptyMapName(map));
+ writeExternalFormToDisk((Serializable) map, getCanonicalEmptyCollectionName(map));
*/
// test to make sure the canonical form has been preserved
if (!(makeEmptyMap() instanceof Serializable)) return;
- map = (Map) readExternalFormFromDisk(getCanonicalEmptyMapName(makeEmptyMap()));
+ map = (Map) readExternalFormFromDisk(getCanonicalEmptyCollectionName(makeEmptyMap()));
assertTrue("Map is empty",map.isEmpty() == true);
}
@@ -986,12 +961,12 @@ public abstract class TestMap extends TestObject {
map = makeFullMap();
if (!(map instanceof Serializable)) return;
- writeExternalFormToDisk((Serializable) map, getCanonicalFullMapName(map));
+ writeExternalFormToDisk((Serializable) map, getCanonicalFullCollectionName(map));
*/
// test to make sure the canonical form has been preserved
if (!(makeFullMap() instanceof Serializable)) return;
- map = (Map) readExternalFormFromDisk(getCanonicalFullMapName(makeFullMap()));
+ map = (Map) readExternalFormFromDisk(getCanonicalFullCollectionName(makeFullMap()));
assertEquals("Map is the right size",map.size(), getSampleKeys().length);
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/a1fdbead/src/test/org/apache/commons/collections/TestObject.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestObject.java b/src/test/org/apache/commons/collections/TestObject.java
index fa97171..7e04a35 100644
--- a/src/test/org/apache/commons/collections/TestObject.java
+++ b/src/test/org/apache/commons/collections/TestObject.java
@@ -1,7 +1,13 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestObject.java,v 1.1.2.1 2002/02/26 00:48:14 morgand Exp $
- * $Revision: 1.1.2.1 $
- * $Date: 2002/02/26 00:48:14 $
+<<<<<<< TestObject.java
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestObject.java,v 1.1.2.2 2002/02/26 20:18:53 morgand Exp $
+ * $Revision: 1.1.2.2 $
+ * $Date: 2002/02/26 20:18:53 $
+=======
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestObject.java,v 1.1.2.2 2002/02/26 20:18:53 morgand Exp $
+ * $Revision: 1.1.2.2 $
+ * $Date: 2002/02/26 20:18:53 $
+>>>>>>> 1.8
*
* ====================================================================
*
@@ -90,7 +96,7 @@ import java.util.NoSuchElementException;
* test case (method) your {@link Object} fails.
*
* @author Rodney Waldhoff
- * @version $Id: TestObject.java,v 1.1.2.1 2002/02/26 00:48:14 morgand Exp $
+ * @version $Id: TestObject.java,v 1.1.2.2 2002/02/26 20:18:53 morgand Exp $
*/
public abstract class TestObject extends TestCase {
public TestObject(String testName) {
@@ -235,4 +241,28 @@ public abstract class TestObject extends TestCase {
Object p = readExternalFormFromBytes(objekt);
}
}
+
+ public String getCanonicalEmptyCollectionName(Object object) {
+ StringBuffer retval = new StringBuffer();
+ retval.append("data/test/");
+ String colName = object.getClass().getName();
+ colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
+ retval.append(colName);
+ retval.append(".emptyCollection.version");
+ retval.append(getCompatibilityVersion());
+ retval.append(".obj");
+ return retval.toString();
+ }
+
+ public String getCanonicalFullCollectionName(Object object) {
+ StringBuffer retval = new StringBuffer();
+ retval.append("data/test/");
+ String colName = object.getClass().getName();
+ colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
+ retval.append(colName);
+ retval.append(".fullCollection.version");
+ retval.append(getCompatibilityVersion());
+ retval.append(".obj");
+ return retval.toString();
+ }
}
[09/18] commons-collections git commit: merged in test changed from
the HEAD into collections 1.x branch
Posted by ch...@apache.org.
merged in test changed from the HEAD into collections 1.x branch
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130593 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/14117694
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/14117694
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/14117694
Branch: refs/heads/collections_1_x_branch
Commit: 141176948fd644eace598e9a5ea705720212f7ba
Parents: 205c1a3
Author: Morgan James Delagrange <mo...@apache.org>
Authored: Tue Feb 26 06:17:51 2002 +0000
Committer: Morgan James Delagrange <mo...@apache.org>
Committed: Tue Feb 26 06:17:51 2002 +0000
----------------------------------------------------------------------
.../org/apache/commons/collections/TestAll.java | 10 +++----
.../commons/collections/TestFastHashMap.java | 12 ++++----
.../commons/collections/TestFastTreeMap.java | 19 +++++++++----
.../apache/commons/collections/TestHashMap.java | 27 ++++++++----------
.../apache/commons/collections/TestLRUMap.java | 29 +++-----------------
.../org/apache/commons/collections/TestMap.java | 18 ++++--------
.../commons/collections/TestSoftRefHashMap.java | 12 ++++----
.../apache/commons/collections/TestTreeMap.java | 26 +++++++++---------
8 files changed, 64 insertions(+), 89 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/14117694/src/test/org/apache/commons/collections/TestAll.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestAll.java b/src/test/org/apache/commons/collections/TestAll.java
index 5c138e3..81385a9 100644
--- a/src/test/org/apache/commons/collections/TestAll.java
+++ b/src/test/org/apache/commons/collections/TestAll.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestAll.java,v 1.15.2.2 2002/02/26 05:44:14 morgand Exp $
- * $Revision: 1.15.2.2 $
- * $Date: 2002/02/26 05:44:14 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestAll.java,v 1.15.2.3 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.15.2.3 $
+ * $Date: 2002/02/26 06:17:51 $
*
* ====================================================================
*
@@ -66,7 +66,7 @@ import junit.framework.*;
/**
* Entry point for all Collections tests.
* @author Rodney Waldhoff
- * @version $Id: TestAll.java,v 1.15.2.2 2002/02/26 05:44:14 morgand Exp $
+ * @version $Id: TestAll.java,v 1.15.2.3 2002/02/26 06:17:51 morgand Exp $
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
@@ -87,8 +87,6 @@ public class TestAll extends TestCase {
suite.addTest(TestFastHashMap1.suite());
suite.addTest(TestFastTreeMap.suite());
suite.addTest(TestFastTreeMap1.suite());
- suite.addTest(TestHashMap.suite());
- suite.addTest(TestTreeMap.suite());
suite.addTest(TestLRUMap.suite());
return suite;
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/14117694/src/test/org/apache/commons/collections/TestFastHashMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestFastHashMap.java b/src/test/org/apache/commons/collections/TestFastHashMap.java
index 8241ee6..fc66754 100644
--- a/src/test/org/apache/commons/collections/TestFastHashMap.java
+++ b/src/test/org/apache/commons/collections/TestFastHashMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastHashMap.java,v 1.3 2001/04/21 12:22:30 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/04/21 12:22:30 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastHashMap.java,v 1.3.2.1 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.3.2.1 $
+ * $Date: 2002/02/26 06:17:51 $
*
* ====================================================================
*
@@ -69,7 +69,7 @@ import java.util.Map;
/**
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: TestFastHashMap.java,v 1.3 2001/04/21 12:22:30 craigmcc Exp $
+ * @version $Id: TestFastHashMap.java,v 1.3.2.1 2002/02/26 06:17:51 morgand Exp $
*/
public class TestFastHashMap extends TestHashMap
{
@@ -89,7 +89,7 @@ public class TestFastHashMap extends TestHashMap
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeMap() {
+ public Map makeEmptyMap() {
FastHashMap fhm = new FastHashMap();
fhm.setFast(false);
return (fhm);
@@ -97,7 +97,7 @@ public class TestFastHashMap extends TestHashMap
public void setUp()
{
- map = (HashMap) makeMap();
+ map = (HashMap) makeEmptyMap();
}
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/14117694/src/test/org/apache/commons/collections/TestFastTreeMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestFastTreeMap.java b/src/test/org/apache/commons/collections/TestFastTreeMap.java
index 4313fc8..fd95c42 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.3 2001/04/21 12:22:30 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2001/04/21 12:22:30 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestFastTreeMap.java,v 1.3.2.1 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.3.2.1 $
+ * $Date: 2002/02/26 06:17:51 $
*
* ====================================================================
*
@@ -69,7 +69,7 @@ import java.util.TreeMap;
/**
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: TestFastTreeMap.java,v 1.3 2001/04/21 12:22:30 craigmcc Exp $
+ * @version $Id: TestFastTreeMap.java,v 1.3.2.1 2002/02/26 06:17:51 morgand Exp $
*/
public class TestFastTreeMap extends TestTreeMap
{
@@ -89,15 +89,22 @@ public class TestFastTreeMap extends TestTreeMap
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeMap() {
+ public Map makeEmptyMap() {
FastTreeMap ftm = new FastTreeMap();
ftm.setFast(false);
return (ftm);
}
+
+ /**
+ * The comparator for the fast tree map does not support null keys.
+ **/
+ public boolean useNullKey() {
+ return false;
+ }
public void setUp()
{
- map = (TreeMap) makeMap();
+ map = (TreeMap) makeEmptyMap();
}
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/14117694/src/test/org/apache/commons/collections/TestHashMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestHashMap.java b/src/test/org/apache/commons/collections/TestHashMap.java
index c28f788..5e0c569 100644
--- a/src/test/org/apache/commons/collections/TestHashMap.java
+++ b/src/test/org/apache/commons/collections/TestHashMap.java
@@ -1,7 +1,13 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestHashMap.java,v 1.2.2.1 2002/02/26 00:51:21 morgand Exp $
- * $Revision: 1.2.2.1 $
- * $Date: 2002/02/26 00:51:21 $
+<<<<<<< TestHashMap.java
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestHashMap.java,v 1.2.2.2 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.2.2.2 $
+ * $Date: 2002/02/26 06:17:51 $
+=======
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestHashMap.java,v 1.2.2.2 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.2.2.2 $
+ * $Date: 2002/02/26 06:17:51 $
+>>>>>>> 1.6
*
* ====================================================================
*
@@ -69,31 +75,21 @@ import java.util.Map;
/**
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: TestHashMap.java,v 1.2.2.1 2002/02/26 00:51:21 morgand Exp $
+ * @version $Id: TestHashMap.java,v 1.2.2.2 2002/02/26 06:17:51 morgand Exp $
*/
-public class TestHashMap extends TestMap
+public abstract class TestHashMap extends TestMap
{
public TestHashMap(String testName)
{
super(testName);
}
- public static Test suite()
- {
- return new TestSuite(TestHashMap.class);
- }
-
public static void main(String args[])
{
String[] testCaseName = { TestHashMap.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeEmptyMap() {
- HashMap hm = new HashMap();
- return (hm);
- }
-
protected HashMap map = null;
public void setUp()
@@ -114,4 +110,5 @@ public class TestHashMap extends TestMap
assertEquals("Top item is 'Second Item'", map.get("first"), "First Item");
assertEquals("Next Item is 'First Item'", map.get("second"), "Second Item");
}
+
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/14117694/src/test/org/apache/commons/collections/TestLRUMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestLRUMap.java b/src/test/org/apache/commons/collections/TestLRUMap.java
index 091252b..3b022da 100644
--- a/src/test/org/apache/commons/collections/TestLRUMap.java
+++ b/src/test/org/apache/commons/collections/TestLRUMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.11.2.1 2002/02/26 00:51:21 morgand Exp $
- * $Revision: 1.11.2.1 $
- * $Date: 2002/02/26 00:51:21 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.11.2.2 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.11.2.2 $
+ * $Date: 2002/02/26 06:17:51 $
*
* ====================================================================
*
@@ -76,7 +76,7 @@ import java.util.HashMap;
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author <a href="mailto:morgand@apache.org">Morgan Delagrange</a>
- * @version $Id: TestLRUMap.java,v 1.11.2.1 2002/02/26 00:51:21 morgand Exp $
+ * @version $Id: TestLRUMap.java,v 1.11.2.2 2002/02/26 06:17:51 morgand Exp $
*/
public class TestLRUMap extends TestMap
{
@@ -190,27 +190,6 @@ public class TestLRUMap extends TestMap
map.size() == 3);
}
-
- public void testExternalizable() throws IOException, ClassNotFoundException {
- /*
- * Test object created with this code
- * Object created from CVS version 1.3 of the LRUMap class
- *
- LRUMap map2 = new LRUMap(3);
- map2.put(new Integer(1),"foo");
- map2.put(new Integer(4),"bar");
- map2.put(new Integer(6),"yeah");
- map2.writeExternal(new ObjectOutputStream(new FileOutputStream("data/test/LRUMapVersion1.obj")));
- */
-
- // purposely start me out with a smaller capacity
- LRUMap map2 = new LRUMap(1);
- map2.readExternal(new ObjectInputStream(new FileInputStream("data/test/LRUMapVersion1.obj")));
- assertTrue("Integer(1) equals foo",map2.get(new Integer(1)).equals("foo"));
- assertTrue("Integer(4) equals bar",map2.get(new Integer(4)).equals("bar"));
- assertTrue("Integer(6) equals yeah",map2.get(new Integer(6)).equals("yeah"));
- }
-
/**
* You should be able to subclass LRUMap and perform a
* custom action when items are removed automatically
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/14117694/src/test/org/apache/commons/collections/TestMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestMap.java b/src/test/org/apache/commons/collections/TestMap.java
index 0261d3f..5847898 100644
--- a/src/test/org/apache/commons/collections/TestMap.java
+++ b/src/test/org/apache/commons/collections/TestMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.3.2.1 2002/02/26 00:51:21 morgand Exp $
- * $Revision: 1.3.2.1 $
- * $Date: 2002/02/26 00:51:21 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.3.2.2 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.3.2.2 $
+ * $Date: 2002/02/26 06:17:51 $
*
* ====================================================================
*
@@ -87,7 +87,7 @@ import java.util.NoSuchElementException;
*
* @author Michael Smith
* @author Rodney Waldhoff
- * @version $Id: TestMap.java,v 1.3.2.1 2002/02/26 00:51:21 morgand Exp $
+ * @version $Id: TestMap.java,v 1.3.2.2 2002/02/26 06:17:51 morgand Exp $
*/
public abstract class TestMap extends TestObject {
@@ -959,17 +959,14 @@ public abstract class TestMap extends TestObject {
* against the canonical version in CVS.
*/
public void testEmptyMapCompatibility() throws IOException, ClassNotFoundException {
- /**
- * Create canonical objects with this code
Map map = makeEmptyMap();
if (!(map instanceof Serializable)) return;
writeExternalFormToDisk((Serializable) map, getCanonicalEmptyMapName(map));
- */
// test to make sure the canonical form has been preserved
if (!(makeEmptyMap() instanceof Serializable)) return;
- Map map = (Map) readExternalFormFromDisk(getCanonicalEmptyMapName(makeEmptyMap()));
+ map = (Map) readExternalFormFromDisk(getCanonicalEmptyMapName(makeEmptyMap()));
assertTrue("Map is empty",map.isEmpty() == true);
}
@@ -978,17 +975,14 @@ public abstract class TestMap extends TestObject {
* against the canonical version in CVS.
*/
public void testFullMapCompatibility() throws IOException, ClassNotFoundException {
- /**
- * Create canonical objects with this code
Map map = makeFullMap();
if (!(map instanceof Serializable)) return;
writeExternalFormToDisk((Serializable) map, getCanonicalFullMapName(map));
- */
// test to make sure the canonical form has been preserved
if (!(makeFullMap() instanceof Serializable)) return;
- Map map = (Map) readExternalFormFromDisk(getCanonicalFullMapName(makeFullMap()));
+ map = (Map) readExternalFormFromDisk(getCanonicalFullMapName(makeFullMap()));
assertEquals("Map is the right size",map.size(), getSampleKeys().length);
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/14117694/src/test/org/apache/commons/collections/TestSoftRefHashMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestSoftRefHashMap.java b/src/test/org/apache/commons/collections/TestSoftRefHashMap.java
index bae4fa1..ccb19a5 100644
--- a/src/test/org/apache/commons/collections/TestSoftRefHashMap.java
+++ b/src/test/org/apache/commons/collections/TestSoftRefHashMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestSoftRefHashMap.java,v 1.1 2001/05/06 11:10:36 jstrachan Exp $
- * $Revision: 1.1 $
- * $Date: 2001/05/06 11:10:36 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestSoftRefHashMap.java,v 1.1.2.1 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.1.2.1 $
+ * $Date: 2002/02/26 06:17:51 $
*
* ====================================================================
*
@@ -69,7 +69,7 @@ import java.util.HashMap;
/**
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- * @version $Id: TestSoftRefHashMap.java,v 1.1 2001/05/06 11:10:36 jstrachan Exp $
+ * @version $Id: TestSoftRefHashMap.java,v 1.1.2.1 2002/02/26 06:17:51 morgand Exp $
*/
public class TestSoftRefHashMap extends TestHashMap
{
@@ -86,13 +86,13 @@ public class TestSoftRefHashMap extends TestHashMap
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeMap() {
+ public Map makeEmptyMap() {
SoftRefHashMap map = new SoftRefHashMap();
return map;
}
public void setUp() {
- map = (HashMap) makeMap();
+ map = (HashMap) makeEmptyMap();
}
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/14117694/src/test/org/apache/commons/collections/TestTreeMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestTreeMap.java b/src/test/org/apache/commons/collections/TestTreeMap.java
index ab8d6bf..d85211b 100644
--- a/src/test/org/apache/commons/collections/TestTreeMap.java
+++ b/src/test/org/apache/commons/collections/TestTreeMap.java
@@ -1,7 +1,13 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestTreeMap.java,v 1.2.2.1 2002/02/26 00:51:21 morgand Exp $
- * $Revision: 1.2.2.1 $
- * $Date: 2002/02/26 00:51:21 $
+<<<<<<< TestTreeMap.java
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestTreeMap.java,v 1.2.2.2 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.2.2.2 $
+ * $Date: 2002/02/26 06:17:51 $
+=======
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestTreeMap.java,v 1.2.2.2 2002/02/26 06:17:51 morgand Exp $
+ * $Revision: 1.2.2.2 $
+ * $Date: 2002/02/26 06:17:51 $
+>>>>>>> 1.5
*
* ====================================================================
*
@@ -69,29 +75,23 @@ import java.util.Map;
/**
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: TestTreeMap.java,v 1.2.2.1 2002/02/26 00:51:21 morgand Exp $
+ * @version $Id: TestTreeMap.java,v 1.2.2.2 2002/02/26 06:17:51 morgand Exp $
*/
-public class TestTreeMap extends TestMap
+public abstract class TestTreeMap extends TestMap
{
public TestTreeMap(String testName)
{
super(testName);
}
- public static Test suite()
- {
- return new TestSuite(TestTreeMap.class);
- }
-
public static void main(String args[])
{
String[] testCaseName = { TestTreeMap.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeEmptyMap() {
- TreeMap tm = new TreeMap();
- return (tm);
+ public boolean useNullKey() {
+ return false;
}
protected TreeMap map = null;
[02/18] commons-collections git commit: This commit was manufactured
by cvs2svn to create branch 'collections_1_x_branch'.
Posted by ch...@apache.org.
This commit was manufactured by cvs2svn to create branch
'collections_1_x_branch'.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130589 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/7696ab2d
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/7696ab2d
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/7696ab2d
Branch: refs/heads/collections_1_x_branch
Commit: 7696ab2d1413b17a9dba462f5d3c8154301d8c10
Parents: b5b971b
Author: No Author <de...@apache.org>
Authored: Tue Feb 26 00:51:21 2002 +0000
Committer: No Author <de...@apache.org>
Committed: Tue Feb 26 00:51:21 2002 +0000
----------------------------------------------------------------------
----------------------------------------------------------------------
[15/18] commons-collections git commit: Serialized copies of
Collections 1.0 objects
Posted by ch...@apache.org.
Serialized copies of Collections 1.0 objects
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130606 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/cc2033e3
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/cc2033e3
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/cc2033e3
Branch: refs/heads/collections_1_x_branch
Commit: cc2033e325f145f167b599e10d734317acbb5c1e
Parents: a1fdbea
Author: Morgan James Delagrange <mo...@apache.org>
Authored: Tue Feb 26 20:27:31 2002 +0000
Committer: Morgan James Delagrange <mo...@apache.org>
Committed: Tue Feb 26 20:27:31 2002 +0000
----------------------------------------------------------------------
data/test/ArrayStack.emptyCollection.version1.obj | Bin 0 -> 114 bytes
data/test/ArrayStack.fullCollection.version1.obj | Bin 0 -> 131 bytes
...CursorableLinkedList.emptyCollection.version1.obj | Bin 0 -> 179 bytes
.../CursorableLinkedList.fullCollection.version1.obj | Bin 0 -> 196 bytes
data/test/FastArrayList.emptyCollection.version1.obj | Bin 0 -> 173 bytes
data/test/FastArrayList.fullCollection.version1.obj | Bin 0 -> 190 bytes
6 files changed, 0 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/cc2033e3/data/test/ArrayStack.emptyCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/ArrayStack.emptyCollection.version1.obj b/data/test/ArrayStack.emptyCollection.version1.obj
new file mode 100644
index 0000000..2591e23
Binary files /dev/null and b/data/test/ArrayStack.emptyCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/cc2033e3/data/test/ArrayStack.fullCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/ArrayStack.fullCollection.version1.obj b/data/test/ArrayStack.fullCollection.version1.obj
new file mode 100644
index 0000000..9a623e4
Binary files /dev/null and b/data/test/ArrayStack.fullCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/cc2033e3/data/test/CursorableLinkedList.emptyCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/CursorableLinkedList.emptyCollection.version1.obj b/data/test/CursorableLinkedList.emptyCollection.version1.obj
new file mode 100644
index 0000000..ed9a054
Binary files /dev/null and b/data/test/CursorableLinkedList.emptyCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/cc2033e3/data/test/CursorableLinkedList.fullCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/CursorableLinkedList.fullCollection.version1.obj b/data/test/CursorableLinkedList.fullCollection.version1.obj
new file mode 100644
index 0000000..eaa0622
Binary files /dev/null and b/data/test/CursorableLinkedList.fullCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/cc2033e3/data/test/FastArrayList.emptyCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastArrayList.emptyCollection.version1.obj b/data/test/FastArrayList.emptyCollection.version1.obj
new file mode 100644
index 0000000..158dd80
Binary files /dev/null and b/data/test/FastArrayList.emptyCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/cc2033e3/data/test/FastArrayList.fullCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastArrayList.fullCollection.version1.obj b/data/test/FastArrayList.fullCollection.version1.obj
new file mode 100644
index 0000000..85b92cb
Binary files /dev/null and b/data/test/FastArrayList.fullCollection.version1.obj differ
[17/18] commons-collections git commit: Moving back :)
Posted by ch...@apache.org.
Moving back :)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@560658 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/ae8c0faf
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/ae8c0faf
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/ae8c0faf
Branch: refs/heads/collections_1_x_branch
Commit: ae8c0fafa6ef68539f753d9316e104a385a9190c
Parents: cc2033e 0df455f
Author: Henri Yandell <ba...@apache.org>
Authored: Sun Jul 29 03:42:15 2007 +0000
Committer: Henri Yandell <ba...@apache.org>
Committed: Sun Jul 29 03:42:15 2007 +0000
----------------------------------------------------------------------
----------------------------------------------------------------------
[16/18] commons-collections git commit: Moving to TLP
Posted by ch...@apache.org.
Moving to TLP
git-svn-id: https://svn.apache.org/repos/asf/commons/commons/proper/collections/branches/collections_1_x_branch@560657 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/0df455f9
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/0df455f9
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/0df455f9
Branch: refs/heads/collections_1_x_branch
Commit: 0df455f9b4337ddb42698d8363616b63360d203a
Parents: cc2033e
Author: Henri Yandell <ba...@apache.org>
Authored: Sun Jul 29 03:40:41 2007 +0000
Committer: Henri Yandell <ba...@apache.org>
Committed: Sun Jul 29 03:40:41 2007 +0000
----------------------------------------------------------------------
----------------------------------------------------------------------
[06/18] commons-collections git commit: to ease maintenance,
removed all unreleased classes from the 1.x branch
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/DoubleOrderedMap.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/DoubleOrderedMap.java b/src/java/org/apache/commons/collections/DoubleOrderedMap.java
deleted file mode 100644
index 94009a4..0000000
--- a/src/java/org/apache/commons/collections/DoubleOrderedMap.java
+++ /dev/null
@@ -1,2046 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/DoubleOrderedMap.java,v 1.1 2002/01/20 04:36:08 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2002/01/20 04:36:08 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-
-
-import java.lang.reflect.Array;
-
-import java.util.*;
-
-
-/**
-* Red-Black tree-based implementation of Map. This class guarantees
-* that the map will be in both ascending key order and ascending
-* value order, sorted according to the natural order for the key's
-* and value's classes.<p>
-*
-* This Map is intended for applications that need to be able to look
-* up a key-value pairing by either key or value, and need to do so
-* with equal efficiency.<p>
-*
-* While that goal could be accomplished by taking a pair of TreeMaps
-* and redirecting requests to the appropriate TreeMap (e.g.,
-* containsKey would be directed to the TreeMap that maps values to
-* keys, containsValue would be directed to the TreeMap that maps keys
-* to values), there are problems with that implementation,
-* particularly when trying to keep the two TreeMaps synchronized with
-* each other. And if the data contained in the TreeMaps is large, the
-* cost of redundant storage becomes significant.<p>
-*
-* This solution keeps the data properly synchronized and minimizes
-* the data storage. The red-black algorithm is based on TreeMap's,
-* but has been modified to simultaneously map a tree node by key and
-* by value. This doubles the cost of put operations (but so does
-* using two TreeMaps), and nearly doubles the cost of remove
-* operations (there is a savings in that the lookup of the node to be
-* removed only has to be performed once). And since only one node
-* contains the key and value, storage is significantly less than that
-* required by two TreeMaps.<p>
-*
-* There are some limitations placed on data kept in this Map. The
-* biggest one is this:<p>
-*
-* When performing a put operation, neither the key nor the value may
-* already exist in the Map. In the java.util Map implementations
-* (HashMap, TreeMap), you can perform a put with an already mapped
-* key, and neither cares about duplicate values at all ... but this
-* implementation's put method with throw an IllegalArgumentException
-* if either the key or the value is already in the Map.<p>
-*
-* Obviously, that same restriction (and consequence of failing to
-* heed that restriction) applies to the putAll method.<p>
-*
-* The Map.Entry instances returned by the appropriate methods will
-* not allow setValue() and will throw an
-* UnsupportedOperationException on attempts to call that method.<p>
-*
-* New methods are added to take advantage of the fact that values are
-* kept sorted independently of their keys:<p>
-*
-* Object getKeyForValue(Object value) is the opposite of get; it
-* takes a value and returns its key, if any.<p>
-*
-* Object removeValue(Object value) finds and removes the specified
-* value and returns the now un-used key.<p>
-*
-* Set entrySetByValue() returns the Map.Entry's in a Set whose
-* iterator will iterate over the Map.Entry's in ascending order by
-* their corresponding values.<p>
-*
-* Set keySetByValue() returns the keys in a Set whose iterator will
-* iterate over the keys in ascending order by their corresponding
-* values.<p>
-*
-* Collection valuesByValue() returns the values in a Collection whose
-* iterator will iterate over the values in ascending order.<p>
-*
-* @author Marc Johnson (marcj at users dot sourceforge dot net)
-*/
-
-// final for performance
-public final class DoubleOrderedMap extends AbstractMap {
-
- private Node[] rootNode = new Node[]{ null,
- null };
- private int nodeCount = 0;
- private int modifications = 0;
- private Set[] setOfKeys = new Set[]{ null,
- null };
- private Set[] setOfEntries = new Set[]{ null,
- null };
- private Collection[] collectionOfValues = new Collection[]{
-null,
-
-null };
- private static final int KEY = 0;
- private static final int VALUE = 1;
- private static final int SUM_OF_INDICES = KEY + VALUE;
- private static final int FIRST_INDEX = 0;
- private static final int NUMBER_OF_INDICES = 2;
- private static final String[] dataName = new String[]{ "key",
- "value"
-};
-
- /**
- * Construct a new DoubleOrderedMap
- */
- public DoubleOrderedMap() {}
-
- /**
- * Constructs a new DoubleOrderedMap from an existing Map, with keys and
- * values sorted
- *
- * @param map the map whose mappings are to be placed in this map.
- *
- * @exception ClassCastException if the keys in the map are not
- * Comparable, or are not mutually
- * comparable; also if the values in
- * the map are not Comparable, or
- * are not mutually Comparable
- * @exception NullPointerException if any key or value in the map
- * is null
- * @exception IllegalArgumentException if there are duplicate keys
- * or duplicate values in the
- * map
- */
- public DoubleOrderedMap(final Map map)
- throws ClassCastException, NullPointerException,
- IllegalArgumentException {
- putAll(map);
- }
-
- /**
- * Returns the key to which this map maps the specified value.
- * Returns null if the map contains no mapping for this value.
- *
- * @param value value whose associated key is to be returned.
- *
- * @return the key to which this map maps the specified value, or
- * null if the map contains no mapping for this value.
- *
- * @exception ClassCastException if the value is of an
- * inappropriate type for this map.
- * @exception NullPointerException if the value is null
- */
- public Object getKeyForValue(final Object value)
- throws ClassCastException, NullPointerException {
- return doGet((Comparable) value, VALUE);
- }
-
- /**
- * Removes the mapping for this value from this map if present
- *
- * @param value value whose mapping is to be removed from the map.
- *
- * @return previous key associated with specified value, or null
- * if there was no mapping for value.
- */
- public Object removeValue(final Object value) {
- return doRemove((Comparable) value, VALUE);
- }
-
- /**
- * Returns a set view of the mappings contained in this map. Each
- * element in the returned set is a Map.Entry. The set is backed
- * by the map, so changes to the map are reflected in the set, and
- * vice-versa. If the map is modified while an iteration over the
- * set is in progress, the results of the iteration are
- * undefined. The set supports element removal, which removes the
- * corresponding mapping from the map, via the Iterator.remove,
- * Set.remove, removeAll, retainAll and clear operations. It does
- * not support the add or addAll operations.<p>
- *
- * The difference between this method and entrySet is that
- * entrySet's iterator() method returns an iterator that iterates
- * over the mappings in ascending order by key. This method's
- * iterator method iterates over the mappings in ascending order
- * by value.
- *
- * @return a set view of the mappings contained in this map.
- */
- public Set entrySetByValue() {
-
- if (setOfEntries[VALUE] == null) {
- setOfEntries[VALUE] = new AbstractSet() {
-
- public Iterator iterator() {
-
- return new DoubleOrderedMapIterator(VALUE) {
-
- protected Object doGetNext() {
- return lastReturnedNode;
- }
- };
- }
-
- public boolean contains(Object o) {
-
- if (!(o instanceof Map.Entry)) {
- return false;
- }
-
- Map.Entry entry = (Map.Entry) o;
- Object key = entry.getKey();
- Node node = lookup((Comparable) entry.getValue(),
- VALUE);
-
- return (node != null) && node.getData(KEY).equals(key);
- }
-
- public boolean remove(Object o) {
-
- if (!(o instanceof Map.Entry)) {
- return false;
- }
-
- Map.Entry entry = (Map.Entry) o;
- Object key = entry.getKey();
- Node node = lookup((Comparable) entry.getValue(),
- VALUE);
-
- if ((node != null) && node.getData(KEY).equals(key)) {
- doRedBlackDelete(node);
-
- return true;
- }
-
- return false;
- }
-
- public int size() {
- return DoubleOrderedMap.this.size();
- }
-
- public void clear() {
- DoubleOrderedMap.this.clear();
- }
- };
- }
-
- return setOfEntries[VALUE];
- }
-
- /**
- * Returns a set view of the keys contained in this map. The set
- * is backed by the map, so changes to the map are reflected in
- * the set, and vice-versa. If the map is modified while an
- * iteration over the set is in progress, the results of the
- * iteration are undefined. The set supports element removal,
- * which removes the corresponding mapping from the map, via the
- * Iterator.remove, Set.remove, removeAll, retainAll, and clear
- * operations. It does not support the add or addAll
- * operations.<p>
- *
- * The difference between this method and keySet is that keySet's
- * iterator() method returns an iterator that iterates over the
- * keys in ascending order by key. This method's iterator method
- * iterates over the keys in ascending order by value.
- *
- * @return a set view of the keys contained in this map.
- */
- public Set keySetByValue() {
-
- if (setOfKeys[VALUE] == null) {
- setOfKeys[VALUE] = new AbstractSet() {
-
- public Iterator iterator() {
-
- return new DoubleOrderedMapIterator(VALUE) {
-
- protected Object doGetNext() {
- return lastReturnedNode.getData(KEY);
- }
- };
- }
-
- public int size() {
- return DoubleOrderedMap.this.size();
- }
-
- public boolean contains(Object o) {
- return containsKey(o);
- }
-
- public boolean remove(Object o) {
-
- int oldnodeCount = nodeCount;
-
- DoubleOrderedMap.this.remove(o);
-
- return nodeCount != oldnodeCount;
- }
-
- public void clear() {
- DoubleOrderedMap.this.clear();
- }
- };
- }
-
- return setOfKeys[VALUE];
- }
-
- /**
- * Returns a collection view of the values contained in this
- * map. The collection is backed by the map, so changes to the map
- * are reflected in the collection, and vice-versa. If the map is
- * modified while an iteration over the collection is in progress,
- * the results of the iteration are undefined. The collection
- * supports element removal, which removes the corresponding
- * mapping from the map, via the Iterator.remove,
- * Collection.remove, removeAll, retainAll and clear operations.
- * It does not support the add or addAll operations.<p>
- *
- * The difference between this method and values is that values's
- * iterator() method returns an iterator that iterates over the
- * values in ascending order by key. This method's iterator method
- * iterates over the values in ascending order by key.
- *
- * @return a collection view of the values contained in this map.
- */
- public Collection valuesByValue() {
-
- if (collectionOfValues[VALUE] == null) {
- collectionOfValues[VALUE] = new AbstractCollection() {
-
- public Iterator iterator() {
-
- return new DoubleOrderedMapIterator(VALUE) {
-
- protected Object doGetNext() {
- return lastReturnedNode.getData(VALUE);
- }
- };
- }
-
- public int size() {
- return DoubleOrderedMap.this.size();
- }
-
- public boolean contains(Object o) {
- return containsValue(o);
- }
-
- public boolean remove(Object o) {
-
- int oldnodeCount = nodeCount;
-
- removeValue(o);
-
- return nodeCount != oldnodeCount;
- }
-
- public boolean removeAll(Collection c) {
-
- boolean modified = false;
- Iterator iter = c.iterator();
-
- while (iter.hasNext()) {
- if (removeValue(iter.next()) != null) {
- modified = true;
- }
- }
-
- return modified;
- }
-
- public void clear() {
- DoubleOrderedMap.this.clear();
- }
- };
- }
-
- return collectionOfValues[VALUE];
- }
-
- /**
- * common remove logic (remove by key or remove by value)
- *
- * @param o the key, or value, that we're looking for
- * @param index KEY or VALUE
- *
- * @return the key, if remove by value, or the value, if remove by
- * key. null if the specified key or value could not be
- * found
- */
- private Object doRemove(final Comparable o, final int index) {
-
- Node node = lookup(o, index);
- Object rval = null;
-
- if (node != null) {
- rval = node.getData(oppositeIndex(index));
-
- doRedBlackDelete(node);
- }
-
- return rval;
- }
-
- /**
- * common get logic, used to get by key or get by value
- *
- * @param o the key or value that we're looking for
- * @param index KEY or VALUE
- *
- * @return the key (if the value was mapped) or the value (if the
- * key was mapped); null if we couldn't find the specified
- * object
- */
- private Object doGet(final Comparable o, final int index) {
-
- checkNonNullComparable(o, index);
-
- Node node = lookup(o, index);
-
- return ((node == null)
- ? null
- : node.getData(oppositeIndex(index)));
- }
-
- /**
- * Get the opposite index of the specified index
- *
- * @param index KEY or VALUE
- *
- * @return VALUE (if KEY was specified), else KEY
- */
- private int oppositeIndex(final int index) {
-
- // old trick ... to find the opposite of a value, m or n,
- // subtract the value from the sum of the two possible
- // values. (m + n) - m = n; (m + n) - n = m
- return SUM_OF_INDICES - index;
- }
-
- /**
- * do the actual lookup of a piece of data
- *
- * @param data the key or value to be looked up
- * @param index KEY or VALUE
- *
- * @return the desired Node, or null if there is no mapping of the
- * specified data
- */
- private Node lookup(final Comparable data, final int index) {
-
- Node rval = null;
- Node node = rootNode[index];
-
- while (node != null) {
- int cmp = compare(data, node.getData(index));
-
- if (cmp == 0) {
- rval = node;
-
- break;
- } else {
- node = (cmp < 0)
- ? node.getLeft(index)
- : node.getRight(index);
- }
- }
-
- return rval;
- }
-
- /**
- * Compare two objects
- *
- * @param o1 the first object
- * @param o2 the second object
- *
- * @return negative value if o1 < o2; 0 if o1 == o2; positive
- * value if o1 > o2
- */
- private static int compare(final Comparable o1, final Comparable o2) {
- return ((Comparable) o1).compareTo(o2);
- }
-
- /**
- * find the least node from a given node. very useful for starting
- * a sorting iterator ...
- *
- * @param node the node from which we will start searching
- * @param index KEY or VALUE
- *
- * @return the smallest node, from the specified node, in the
- * specified mapping
- */
- private static Node leastNode(final Node node, final int index) {
-
- Node rval = node;
-
- if (rval != null) {
- while (rval.getLeft(index) != null) {
- rval = rval.getLeft(index);
- }
- }
-
- return rval;
- }
-
- /**
- * get the next larger node from the specified node
- *
- * @param node the node to be searched from
- * @param index KEY or VALUE
- *
- * @return the specified node
- */
- private Node nextGreater(final Node node, final int index) {
-
- Node rval = null;
-
- if (node == null) {
- rval = null;
- } else if (node.getRight(index) != null) {
-
- // everything to the node's right is larger. The least of
- // the right node's descendents is the next larger node
- rval = leastNode(node.getRight(index), index);
- } else {
-
- // traverse up our ancestry until we find an ancestor that
- // is null or one whose left child is our ancestor. If we
- // find a null, then this node IS the largest node in the
- // tree, and there is no greater node. Otherwise, we are
- // the largest node in the subtree on that ancestor's left
- // ... and that ancestor is the next greatest node
- Node parent = node.getParent(index);
- Node child = node;
-
- while ((parent != null) && (child == parent.getRight(index))) {
- child = parent;
- parent = parent.getParent(index);
- }
-
- rval = parent;
- }
-
- return rval;
- }
-
- /**
- * copy the color from one node to another, dealing with the fact
- * that one or both nodes may, in fact, be null
- *
- * @param from the node whose color we're copying; may be null
- * @param to the node whose color we're changing; may be null
- * @param index KEY or VALUE
- */
- private static void copyColor(final Node from, final Node to,
- final int index) {
-
- if (to != null) {
- if (from == null) {
-
- // by default, make it black
- to.setBlack(index);
- } else {
- to.copyColor(from, index);
- }
- }
- }
-
- /**
- * is the specified node red? if the node does not exist, no, it's
- * black, thank you
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static boolean isRed(final Node node, final int index) {
-
- return ((node == null)
- ? false
- : node.isRed(index));
- }
-
- /**
- * is the specified black red? if the node does not exist, sure,
- * it's black, thank you
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static boolean isBlack(final Node node, final int index) {
-
- return ((node == null)
- ? true
- : node.isBlack(index));
- }
-
- /**
- * force a node (if it exists) red
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static void makeRed(final Node node, final int index) {
-
- if (node != null) {
- node.setRed(index);
- }
- }
-
- /**
- * force a node (if it exists) black
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static void makeBlack(final Node node, final int index) {
-
- if (node != null) {
- node.setBlack(index);
- }
- }
-
- /**
- * get a node's grandparent. mind you, the node, its parent, or
- * its grandparent may not exist. no problem
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static Node getGrandParent(final Node node, final int index) {
- return getParent(getParent(node, index), index);
- }
-
- /**
- * get a node's parent. mind you, the node, or its parent, may not
- * exist. no problem
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static Node getParent(final Node node, final int index) {
-
- return ((node == null)
- ? null
- : node.getParent(index));
- }
-
- /**
- * get a node's right child. mind you, the node may not exist. no
- * problem
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static Node getRightChild(final Node node, final int index) {
-
- return (node == null)
- ? null
- : node.getRight(index);
- }
-
- /**
- * get a node's left child. mind you, the node may not exist. no
- * problem
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static Node getLeftChild(final Node node, final int index) {
-
- return (node == null)
- ? null
- : node.getLeft(index);
- }
-
- /**
- * is this node its parent's left child? mind you, the node, or
- * its parent, may not exist. no problem. if the node doesn't
- * exist ... it's its non-existent parent's left child. If the
- * node does exist but has no parent ... no, we're not the
- * non-existent parent's left child. Otherwise (both the specified
- * node AND its parent exist), check.
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static boolean isLeftChild(final Node node, final int index) {
-
- return (node == null)
- ? true
- : ((node.getParent(index) == null)
- ? false
- : (node == node.getParent(index).getLeft(index)));
- }
-
- /**
- * is this node its parent's right child? mind you, the node, or
- * its parent, may not exist. no problem. if the node doesn't
- * exist ... it's its non-existent parent's right child. If the
- * node does exist but has no parent ... no, we're not the
- * non-existent parent's right child. Otherwise (both the
- * specified node AND its parent exist), check.
- *
- * @param node the node (may be null) in question
- * @param index KEY or VALUE
- */
- private static boolean isRightChild(final Node node, final int index) {
-
- return (node == null)
- ? true
- : ((node.getParent(index) == null)
- ? false
- : (node == node.getParent(index).getRight(index)));
- }
-
- /**
- * do a rotate left. standard fare in the world of balanced trees
- *
- * @param node the node to be rotated
- * @param index KEY or VALUE
- */
- private void rotateLeft(final Node node, final int index) {
-
- Node rightChild = node.getRight(index);
-
- node.setRight(rightChild.getLeft(index), index);
-
- if (rightChild.getLeft(index) != null) {
- rightChild.getLeft(index).setParent(node, index);
- }
-
- rightChild.setParent(node.getParent(index), index);
-
- if (node.getParent(index) == null) {
-
- // node was the root ... now its right child is the root
- rootNode[index] = rightChild;
- } else if (node.getParent(index).getLeft(index) == node) {
- node.getParent(index).setLeft(rightChild, index);
- } else {
- node.getParent(index).setRight(rightChild, index);
- }
-
- rightChild.setLeft(node, index);
- node.setParent(rightChild, index);
- }
-
- /**
- * do a rotate right. standard fare in the world of balanced trees
- *
- * @param node the node to be rotated
- * @param index KEY or VALUE
- */
- private void rotateRight(final Node node, final int index) {
-
- Node leftChild = node.getLeft(index);
-
- node.setLeft(leftChild.getRight(index), index);
-
- if (leftChild.getRight(index) != null) {
- leftChild.getRight(index).setParent(node, index);
- }
-
- leftChild.setParent(node.getParent(index), index);
-
- if (node.getParent(index) == null) {
-
- // node was the root ... now its left child is the root
- rootNode[index] = leftChild;
- } else if (node.getParent(index).getRight(index) == node) {
- node.getParent(index).setRight(leftChild, index);
- } else {
- node.getParent(index).setLeft(leftChild, index);
- }
-
- leftChild.setRight(node, index);
- node.setParent(leftChild, index);
- }
-
- /**
- * complicated red-black insert stuff. Based on Sun's TreeMap
- * implementation, though it's barely recognizeable any more
- *
- * @param insertedNode the node to be inserted
- * @param index KEY or VALUE
- */
- private void doRedBlackInsert(final Node insertedNode, final int index)
-{
-
- Node currentNode = insertedNode;
-
- makeRed(currentNode, index);
-
- while ((currentNode != null) && (currentNode != rootNode[index])
- && (isRed(currentNode.getParent(index), index))) {
- if (isLeftChild(getParent(currentNode, index), index)) {
- Node y = getRightChild(getGrandParent(currentNode, index),
- index);
-
- if (isRed(y, index)) {
- makeBlack(getParent(currentNode, index), index);
- makeBlack(y, index);
- makeRed(getGrandParent(currentNode, index), index);
-
- currentNode = getGrandParent(currentNode, index);
- } else {
- if (isRightChild(currentNode, index)) {
- currentNode = getParent(currentNode, index);
-
- rotateLeft(currentNode, index);
- }
-
- makeBlack(getParent(currentNode, index), index);
- makeRed(getGrandParent(currentNode, index), index);
-
- if (getGrandParent(currentNode, index) != null) {
- rotateRight(getGrandParent(currentNode, index),
- index);
- }
- }
- } else {
-
- // just like clause above, except swap left for right
- Node y = getLeftChild(getGrandParent(currentNode, index),
- index);
-
- if (isRed(y, index)) {
- makeBlack(getParent(currentNode, index), index);
- makeBlack(y, index);
- makeRed(getGrandParent(currentNode, index), index);
-
- currentNode = getGrandParent(currentNode, index);
- } else {
- if (isLeftChild(currentNode, index)) {
- currentNode = getParent(currentNode, index);
-
- rotateRight(currentNode, index);
- }
-
- makeBlack(getParent(currentNode, index), index);
- makeRed(getGrandParent(currentNode, index), index);
-
- if (getGrandParent(currentNode, index) != null) {
- rotateLeft(getGrandParent(currentNode, index),
-index);
- }
- }
- }
- }
-
- makeBlack(rootNode[index], index);
- }
-
- /**
- * complicated red-black delete stuff. Based on Sun's TreeMap
- * implementation, though it's barely recognizeable any more
- *
- * @param deletedNode the node to be deleted
- */
- private void doRedBlackDelete(final Node deletedNode) {
-
- for (int index = FIRST_INDEX; index < NUMBER_OF_INDICES; index++) {
-
- // if deleted node has both left and children, swap with
- // the next greater node
- if ((deletedNode.getLeft(index) != null)
- && (deletedNode.getRight(index) != null)) {
- swapPosition(nextGreater(deletedNode, index), deletedNode,
- index);
- }
-
- Node replacement = ((deletedNode.getLeft(index) != null)
- ? deletedNode.getLeft(index)
- : deletedNode.getRight(index));
-
- if (replacement != null) {
- replacement.setParent(deletedNode.getParent(index), index);
-
- if (deletedNode.getParent(index) == null) {
- rootNode[index] = replacement;
- } else if (deletedNode
- == deletedNode.getParent(index).getLeft(index)) {
- deletedNode.getParent(index).setLeft(replacement,
-index);
- } else {
- deletedNode.getParent(index).setRight(replacement,
-index);
- }
-
- deletedNode.setLeft(null, index);
- deletedNode.setRight(null, index);
- deletedNode.setParent(null, index);
-
- if (isBlack(deletedNode, index)) {
- doRedBlackDeleteFixup(replacement, index);
- }
- } else {
-
- // replacement is null
- if (deletedNode.getParent(index) == null) {
-
- // empty tree
- rootNode[index] = null;
- } else {
-
- // deleted node had no children
- if (isBlack(deletedNode, index)) {
- doRedBlackDeleteFixup(deletedNode, index);
- }
-
- if (deletedNode.getParent(index) != null) {
- if (deletedNode
- == deletedNode.getParent(index)
- .getLeft(index)) {
- deletedNode.getParent(index).setLeft(null,
-index);
- } else {
- deletedNode.getParent(index).setRight(null,
- index);
- }
-
- deletedNode.setParent(null, index);
- }
- }
- }
- }
-
- shrink();
- }
-
- /**
- * complicated red-black delete stuff. Based on Sun's TreeMap
- * implementation, though it's barely recognizeable any more. This
- * rebalances the tree (somewhat, as red-black trees are not
- * perfectly balanced -- perfect balancing takes longer)
- *
- * @param replacementNode the node being replaced
- * @param index KEY or VALUE
- */
- private void doRedBlackDeleteFixup(final Node replacementNode,
- final int index) {
-
- Node currentNode = replacementNode;
-
- while ((currentNode != rootNode[index])
- && (isBlack(currentNode, index))) {
- if (isLeftChild(currentNode, index)) {
- Node siblingNode =
- getRightChild(getParent(currentNode, index), index);
-
- if (isRed(siblingNode, index)) {
- makeBlack(siblingNode, index);
- makeRed(getParent(currentNode, index), index);
- rotateLeft(getParent(currentNode, index), index);
-
- siblingNode = getRightChild(getParent(currentNode,
-index),
- index);
- }
-
- if (isBlack(getLeftChild(siblingNode, index), index)
- && isBlack(getRightChild(siblingNode, index),
- index)) {
- makeRed(siblingNode, index);
-
- currentNode = getParent(currentNode, index);
- } else {
- if (isBlack(getRightChild(siblingNode, index), index)) {
- makeBlack(getLeftChild(siblingNode, index), index);
- makeRed(siblingNode, index);
- rotateRight(siblingNode, index);
-
- siblingNode =
- getRightChild(getParent(currentNode, index),
- index);
- }
-
- copyColor(getParent(currentNode, index), siblingNode,
- index);
- makeBlack(getParent(currentNode, index), index);
- makeBlack(getRightChild(siblingNode, index), index);
- rotateLeft(getParent(currentNode, index), index);
-
- currentNode = rootNode[index];
- }
- } else {
- Node siblingNode = getLeftChild(getParent(currentNode,
-index),
- index);
-
- if (isRed(siblingNode, index)) {
- makeBlack(siblingNode, index);
- makeRed(getParent(currentNode, index), index);
- rotateRight(getParent(currentNode, index), index);
-
- siblingNode = getLeftChild(getParent(currentNode,
-index),
- index);
- }
-
- if (isBlack(getRightChild(siblingNode, index), index)
- && isBlack(getLeftChild(siblingNode, index), index))
-{
- makeRed(siblingNode, index);
-
- currentNode = getParent(currentNode, index);
- } else {
- if (isBlack(getLeftChild(siblingNode, index), index)) {
- makeBlack(getRightChild(siblingNode, index), index);
- makeRed(siblingNode, index);
- rotateLeft(siblingNode, index);
-
- siblingNode =
- getLeftChild(getParent(currentNode, index),
- index);
- }
-
- copyColor(getParent(currentNode, index), siblingNode,
- index);
- makeBlack(getParent(currentNode, index), index);
- makeBlack(getLeftChild(siblingNode, index), index);
- rotateRight(getParent(currentNode, index), index);
-
- currentNode = rootNode[index];
- }
- }
- }
-
- makeBlack(currentNode, index);
- }
-
- /**
- * swap two nodes (except for their content), taking care of
- * special cases where one is the other's parent ... hey, it
- * happens.
- *
- * @param x one node
- * @param y another node
- * @param index KEY or VALUE
- */
- private void swapPosition(final Node x, final Node y, final int index) {
-
- // Save initial values.
- Node xFormerParent = x.getParent(index);
- Node xFormerLeftChild = x.getLeft(index);
- Node xFormerRightChild = x.getRight(index);
- Node yFormerParent = y.getParent(index);
- Node yFormerLeftChild = y.getLeft(index);
- Node yFormerRightChild = y.getRight(index);
- boolean xWasLeftChild =
- (x.getParent(index) != null)
- && (x == x.getParent(index).getLeft(index));
- boolean yWasLeftChild =
- (y.getParent(index) != null)
- && (y == y.getParent(index).getLeft(index));
-
- // Swap, handling special cases of one being the other's parent.
- if (x == yFormerParent) { // x was y's parent
- x.setParent(y, index);
-
- if (yWasLeftChild) {
- y.setLeft(x, index);
- y.setRight(xFormerRightChild, index);
- } else {
- y.setRight(x, index);
- y.setLeft(xFormerLeftChild, index);
- }
- } else {
- x.setParent(yFormerParent, index);
-
- if (yFormerParent != null) {
- if (yWasLeftChild) {
- yFormerParent.setLeft(x, index);
- } else {
- yFormerParent.setRight(x, index);
- }
- }
-
- y.setLeft(xFormerLeftChild, index);
- y.setRight(xFormerRightChild, index);
- }
-
- if (y == xFormerParent) { // y was x's parent
- y.setParent(x, index);
-
- if (xWasLeftChild) {
- x.setLeft(y, index);
- x.setRight(yFormerRightChild, index);
- } else {
- x.setRight(y, index);
- x.setLeft(yFormerLeftChild, index);
- }
- } else {
- y.setParent(xFormerParent, index);
-
- if (xFormerParent != null) {
- if (xWasLeftChild) {
- xFormerParent.setLeft(y, index);
- } else {
- xFormerParent.setRight(y, index);
- }
- }
-
- x.setLeft(yFormerLeftChild, index);
- x.setRight(yFormerRightChild, index);
- }
-
- // Fix children's parent pointers
- if (x.getLeft(index) != null) {
- x.getLeft(index).setParent(x, index);
- }
-
- if (x.getRight(index) != null) {
- x.getRight(index).setParent(x, index);
- }
-
- if (y.getLeft(index) != null) {
- y.getLeft(index).setParent(y, index);
- }
-
- if (y.getRight(index) != null) {
- y.getRight(index).setParent(y, index);
- }
-
- x.swapColors(y, index);
-
- // Check if root changed
- if (rootNode[index] == x) {
- rootNode[index] = y;
- } else if (rootNode[index] == y) {
- rootNode[index] = x;
- }
- }
-
- /**
- * check if an object is fit to be proper input ... has to be
- * Comparable and non-null
- *
- * @param o the object being checked
- * @param index KEY or VALUE (used to put the right word in the
- * exception message)
- *
- * @exception NullPointerException if o is null
- * @exception ClassCastException if o is not Comparable
- */
- private static void checkNonNullComparable(final Object o,
- final int index) {
-
- if (o == null) {
- throw new NullPointerException(dataName[index]
- + " cannot be null");
- }
-
- if (!(o instanceof Comparable)) {
- throw new ClassCastException(dataName[index]
- + " must be Comparable");
- }
- }
-
- /**
- * check a key for validity (non-null and implements Comparable)
- *
- * @param key the key to be checked
- *
- * @exception NullPointerException if key is null
- * @exception ClassCastException if key is not Comparable
- */
- private static void checkKey(final Object key) {
- checkNonNullComparable(key, KEY);
- }
-
- /**
- * check a value for validity (non-null and implements Comparable)
- *
- * @param value the value to be checked
- *
- * @exception NullPointerException if value is null
- * @exception ClassCastException if value is not Comparable
- */
- private static void checkValue(final Object value) {
- checkNonNullComparable(value, VALUE);
- }
-
- /**
- * check a key and a value for validity (non-null and implements
- * Comparable)
- *
- * @param key the key to be checked
- * @param value the value to be checked
- *
- * @exception NullPointerException if key or value is null
- * @exception ClassCastException if key or value is not Comparable
- */
- private static void checkKeyAndValue(final Object key,
- final Object value) {
- checkKey(key);
- checkValue(value);
- }
-
- /**
- * increment the modification count -- used to check for
- * concurrent modification of the map through the map and through
- * an Iterator from one of its Set or Collection views
- */
- private void modify() {
- modifications++;
- }
-
- /**
- * bump up the size and note that the map has changed
- */
- private void grow() {
-
- modify();
-
- nodeCount++;
- }
-
- /**
- * decrement the size and note that the map has changed
- */
- private void shrink() {
-
- modify();
-
- nodeCount--;
- }
-
- /**
- * insert a node by its value
- *
- * @param newNode the node to be inserted
- *
- * @exception IllegalArgumentException if the node already exists
- * in the value mapping
- */
- private void insertValue(final Node newNode)
- throws IllegalArgumentException {
-
- Node node = rootNode[VALUE];
-
- while (true) {
- int cmp = compare(newNode.getData(VALUE), node.getData(VALUE));
-
- if (cmp == 0) {
- throw new IllegalArgumentException(
- "Cannot store a duplicate value (\""
- + newNode.getData(VALUE) + "\") in this Map");
- } else if (cmp < 0) {
- if (node.getLeft(VALUE) != null) {
- node = node.getLeft(VALUE);
- } else {
- node.setLeft(newNode, VALUE);
- newNode.setParent(node, VALUE);
- doRedBlackInsert(newNode, VALUE);
-
- break;
- }
- } else { // cmp > 0
- if (node.getRight(VALUE) != null) {
- node = node.getRight(VALUE);
- } else {
- node.setRight(newNode, VALUE);
- newNode.setParent(node, VALUE);
- doRedBlackInsert(newNode, VALUE);
-
- break;
- }
- }
- }
- }
-
- /* ********** START implementation of Map ********** */
-
- /**
- * Returns the number of key-value mappings in this map. If the
- * map contains more than Integer.MAXVALUE elements, returns
- * Integer.MAXVALUE.
- *
- * @return the number of key-value mappings in this map.
- */
- public int size() {
- return nodeCount;
- }
-
- /**
- * Returns true if this map contains a mapping for the specified
- * key.
- *
- * @param key key whose presence in this map is to be tested.
- *
- * @return true if this map contains a mapping for the specified
- * key.
- *
- * @exception ClassCastException if the key is of an inappropriate
- * type for this map.
- * @exception NullPointerException if the key is null
- */
- public boolean containsKey(final Object key)
- throws ClassCastException, NullPointerException {
-
- checkKey(key);
-
- return lookup((Comparable) key, KEY) != null;
- }
-
- /**
- * Returns true if this map maps one or more keys to the
- * specified value.
- *
- * @param value value whose presence in this map is to be tested.
- *
- * @return true if this map maps one or more keys to the specified
- * value.
- */
- public boolean containsValue(final Object value) {
-
- checkValue(value);
-
- return lookup((Comparable) value, VALUE) != null;
- }
-
- /**
- * Returns the value to which this map maps the specified
- * key. Returns null if the map contains no mapping for this key.
- *
- * @param key key whose associated value is to be returned.
- *
- * @return the value to which this map maps the specified key, or
- * null if the map contains no mapping for this key.
- *
- * @exception ClassCastException if the key is of an inappropriate
- * type for this map.
- * @exception NullPointerException if the key is null
- */
- public Object get(final Object key)
- throws ClassCastException, NullPointerException {
- return doGet((Comparable) key, KEY);
- }
-
- /**
- * Associates the specified value with the specified key in this
- * map.
- *
- * @param key key with which the specified value is to be
- * associated.
- * @param value value to be associated with the specified key.
- *
- * @return null
- *
- * @exception ClassCastException if the class of the specified key
- * or value prevents it from being
- * stored in this map.
- * @exception NullPointerException if the specified key or value
- * is null
- * @exception IllegalArgumentException if the key duplicates an
- * existing key, or if the
- * value duplicates an
- * existing value
- */
- public Object put(final Object key, final Object value)
- throws ClassCastException, NullPointerException,
- IllegalArgumentException {
-
- checkKeyAndValue(key, value);
-
- Node node = rootNode[KEY];
-
- if (node == null) {
- Node root = new Node((Comparable) key, (Comparable) value);
-
- rootNode[KEY] = root;
- rootNode[VALUE] = root;
-
- grow();
- } else {
- while (true) {
- int cmp = compare((Comparable) key, node.getData(KEY));
-
- if (cmp == 0) {
- throw new IllegalArgumentException(
- "Cannot store a duplicate key (\"" + key
- + "\") in this Map");
- } else if (cmp < 0) {
- if (node.getLeft(KEY) != null) {
- node = node.getLeft(KEY);
- } else {
- Node newNode = new Node((Comparable) key,
- (Comparable) value);
-
- insertValue(newNode);
- node.setLeft(newNode, KEY);
- newNode.setParent(node, KEY);
- doRedBlackInsert(newNode, KEY);
- grow();
-
- break;
- }
- } else { // cmp > 0
- if (node.getRight(KEY) != null) {
- node = node.getRight(KEY);
- } else {
- Node newNode = new Node((Comparable) key,
- (Comparable) value);
-
- insertValue(newNode);
- node.setRight(newNode, KEY);
- newNode.setParent(node, KEY);
- doRedBlackInsert(newNode, KEY);
- grow();
-
- break;
- }
- }
- }
- }
-
- return null;
- }
-
- /**
- * Removes the mapping for this key from this map if present
- *
- * @param key key whose mapping is to be removed from the map.
- *
- * @return previous value associated with specified key, or null
- * if there was no mapping for key.
- */
- public Object remove(final Object key) {
- return doRemove((Comparable) key, KEY);
- }
-
- /**
- * Removes all mappings from this map
- */
- public void clear() {
-
- modify();
-
- nodeCount = 0;
- rootNode[KEY] = null;
- rootNode[VALUE] = null;
- }
-
- /**
- * Returns a set view of the keys contained in this map. The set
- * is backed by the map, so changes to the map are reflected in
- * the set, and vice-versa. If the map is modified while an
- * iteration over the set is in progress, the results of the
- * iteration are undefined. The set supports element removal,
- * which removes the corresponding mapping from the map, via the
- * Iterator.remove, Set.remove, removeAll, retainAll, and clear
- * operations. It does not support the add or addAll operations.
- *
- * @return a set view of the keys contained in this map.
- */
- public Set keySet() {
-
- if (setOfKeys[KEY] == null) {
- setOfKeys[KEY] = new AbstractSet() {
-
- public Iterator iterator() {
-
- return new DoubleOrderedMapIterator(KEY) {
-
- protected Object doGetNext() {
- return lastReturnedNode.getData(KEY);
- }
- };
- }
-
- public int size() {
- return DoubleOrderedMap.this.size();
- }
-
- public boolean contains(Object o) {
- return containsKey(o);
- }
-
- public boolean remove(Object o) {
-
- int oldNodeCount = nodeCount;
-
- DoubleOrderedMap.this.remove(o);
-
- return nodeCount != oldNodeCount;
- }
-
- public void clear() {
- DoubleOrderedMap.this.clear();
- }
- };
- }
-
- return setOfKeys[KEY];
- }
-
- /**
- * Returns a collection view of the values contained in this
- * map. The collection is backed by the map, so changes to the map
- * are reflected in the collection, and vice-versa. If the map is
- * modified while an iteration over the collection is in progress,
- * the results of the iteration are undefined. The collection
- * supports element removal, which removes the corresponding
- * mapping from the map, via the Iterator.remove,
- * Collection.remove, removeAll, retainAll and clear operations.
- * It does not support the add or addAll operations.
- *
- * @return a collection view of the values contained in this map.
- */
- public Collection values() {
-
- if (collectionOfValues[KEY] == null) {
- collectionOfValues[KEY] = new AbstractCollection() {
-
- public Iterator iterator() {
-
- return new DoubleOrderedMapIterator(KEY) {
-
- protected Object doGetNext() {
- return lastReturnedNode.getData(VALUE);
- }
- };
- }
-
- public int size() {
- return DoubleOrderedMap.this.size();
- }
-
- public boolean contains(Object o) {
- return containsValue(o);
- }
-
- public boolean remove(Object o) {
-
- int oldNodeCount = nodeCount;
-
- removeValue(o);
-
- return nodeCount != oldNodeCount;
- }
-
- public boolean removeAll(Collection c) {
-
- boolean modified = false;
- Iterator iter = c.iterator();
-
- while (iter.hasNext()) {
- if (removeValue(iter.next()) != null) {
- modified = true;
- }
- }
-
- return modified;
- }
-
- public void clear() {
- DoubleOrderedMap.this.clear();
- }
- };
- }
-
- return collectionOfValues[KEY];
- }
-
- /**
- * Returns a set view of the mappings contained in this map. Each
- * element in the returned set is a Map.Entry. The set is backed
- * by the map, so changes to the map are reflected in the set, and
- * vice-versa. If the map is modified while an iteration over the
- * set is in progress, the results of the iteration are
- * undefined. The set supports element removal, which removes the
- * corresponding mapping from the map, via the Iterator.remove,
- * Set.remove, removeAll, retainAll and clear operations. It does
- * not support the add or addAll operations.
- *
- * @return a set view of the mappings contained in this map.
- */
- public Set entrySet() {
-
- if (setOfEntries[KEY] == null) {
- setOfEntries[KEY] = new AbstractSet() {
-
- public Iterator iterator() {
-
- return new DoubleOrderedMapIterator(KEY) {
-
- protected Object doGetNext() {
- return lastReturnedNode;
- }
- };
- }
-
- public boolean contains(Object o) {
-
- if (!(o instanceof Map.Entry)) {
- return false;
- }
-
- Map.Entry entry = (Map.Entry) o;
- Object value = entry.getValue();
- Node node = lookup((Comparable) entry.getKey(),
- KEY);
-
- return (node != null)
- && node.getData(VALUE).equals(value);
- }
-
- public boolean remove(Object o) {
-
- if (!(o instanceof Map.Entry)) {
- return false;
- }
-
- Map.Entry entry = (Map.Entry) o;
- Object value = entry.getValue();
- Node node = lookup((Comparable) entry.getKey(),
- KEY);
-
- if ((node != null) && node.getData(VALUE).equals(value))
-{
- doRedBlackDelete(node);
-
- return true;
- }
-
- return false;
- }
-
- public int size() {
- return DoubleOrderedMap.this.size();
- }
-
- public void clear() {
- DoubleOrderedMap.this.clear();
- }
- };
- }
-
- return setOfEntries[KEY];
- }
-
- /* ********** END implementation of Map ********** */
- private abstract class DoubleOrderedMapIterator implements Iterator {
-
- private int expectedModifications;
- protected Node lastReturnedNode;
- private Node nextNode;
- private int iteratorType;
-
- /**
- * Constructor
- *
- * @param type
- */
- DoubleOrderedMapIterator(final int type) {
-
- iteratorType = type;
- expectedModifications = DoubleOrderedMap.this.modifications;
- lastReturnedNode = null;
- nextNode = leastNode(rootNode[iteratorType],
- iteratorType);
- }
-
- /**
- * @return 'next', whatever that means for a given kind of
- * DoubleOrderedMapIterator
- */
- protected abstract Object doGetNext();
-
- /* ********** START implementation of Iterator ********** */
-
- /**
- * @return true if the iterator has more elements.
- */
- public final boolean hasNext() {
- return nextNode != null;
- }
-
- /**
- * @return the next element in the iteration.
- *
- * @exception NoSuchElementException if iteration has no more
- * elements.
- * @exception ConcurrentModificationException if the
- * DoubleOrderedMap is
- * modified behind
- * the iterator's
- * back
- */
- public final Object next()
- throws NoSuchElementException,
- ConcurrentModificationException {
-
- if (nextNode == null) {
- throw new NoSuchElementException();
- }
-
- if (modifications != expectedModifications) {
- throw new ConcurrentModificationException();
- }
-
- lastReturnedNode = nextNode;
- nextNode = nextGreater(nextNode, iteratorType);
-
- return doGetNext();
- }
-
- /**
- * Removes from the underlying collection the last element
- * returned by the iterator. This method can be called only
- * once per call to next. The behavior of an iterator is
- * unspecified if the underlying collection is modified while
- * the iteration is in progress in any way other than by
- * calling this method.
- *
- * @exception IllegalStateException if the next method has not
- * yet been called, or the
- * remove method has already
- * been called after the last
- * call to the next method.
- * @exception ConcurrentModificationException if the
- * DoubleOrderedMap is
- * modified behind
- * the iterator's
- * back
- */
- public final void remove()
- throws IllegalStateException,
- ConcurrentModificationException {
-
- if (lastReturnedNode == null) {
- throw new IllegalStateException();
- }
-
- if (modifications != expectedModifications) {
- throw new ConcurrentModificationException();
- }
-
- doRedBlackDelete(lastReturnedNode);
-
- expectedModifications++;
-
- lastReturnedNode = null;
- }
-
- /* ********** END implementation of Iterator ********** */
- } // end private abstract class DoubleOrderedMapIterator
-
- // final for performance
- private static final class Node implements Map.Entry {
-
- private Comparable[] data;
- private Node[] leftNode;
- private Node[] rightNode;
- private Node[] parentNode;
- private boolean[] blackColor;
- private int hashcodeValue;
- private boolean calculatedHashCode;
-
- /**
- * Make a new cell with given key and value, and with null
- * links, and black (true) colors.
- *
- * @param key
- * @param value
- */
- Node(final Comparable key, final Comparable value) {
-
- data = new Comparable[]{ key, value };
- leftNode = new Node[]{ null, null };
- rightNode = new Node[]{ null, null };
- parentNode = new Node[]{ null, null };
- blackColor = new boolean[]{ true, true };
- calculatedHashCode = false;
- }
-
- /**
- * get the specified data
- *
- * @param index KEY or VALUE
- *
- * @return the key or value
- */
- private Comparable getData(final int index) {
- return data[index];
- }
-
- /**
- * Set this node's left node
- *
- * @param node the new left node
- * @param index KEY or VALUE
- */
- private void setLeft(final Node node, final int index) {
- leftNode[index] = node;
- }
-
- /**
- * get the left node
- *
- * @param index KEY or VALUE
- *
- * @return the left node -- may be null
- */
- private Node getLeft(final int index) {
- return leftNode[index];
- }
-
- /**
- * Set this node's right node
- *
- * @param node the new right node
- * @param index KEY or VALUE
- */
- private void setRight(final Node node, final int index) {
- rightNode[index] = node;
- }
-
- /**
- * get the right node
- *
- * @param index KEY or VALUE
- *
- * @return the right node -- may be null
- */
- private Node getRight(final int index) {
- return rightNode[index];
- }
-
- /**
- * Set this node's parent node
- *
- * @param node the new parent node
- * @param index KEY or VALUE
- */
- private void setParent(final Node node, final int index) {
- parentNode[index] = node;
- }
-
- /**
- * get the parent node
- *
- * @param index KEY or VALUE
- *
- * @return the parent node -- may be null
- */
- private Node getParent(final int index) {
- return parentNode[index];
- }
-
- /**
- * exchange colors with another node
- *
- * @param node the node to swap with
- * @param index KEY or VALUE
- */
- private void swapColors(final Node node, final int index) {
-
- // Swap colors -- old hacker's trick
- blackColor[index] ^= node.blackColor[index];
- node.blackColor[index] ^= blackColor[index];
- blackColor[index] ^= node.blackColor[index];
- }
-
- /**
- * is this node black?
- *
- * @param index KEY or VALUE
- *
- * @return true if black (which is represented as a true boolean)
- */
- private boolean isBlack(final int index) {
- return blackColor[index];
- }
-
- /**
- * is this node red?
- *
- * @param index KEY or VALUE
- *
- * @return true if non-black
- */
- private boolean isRed(final int index) {
- return !blackColor[index];
- }
-
- /**
- * make this node black
- *
- * @param index KEY or VALUE
- */
- private void setBlack(final int index) {
- blackColor[index] = true;
- }
-
- /**
- * make this node red
- *
- * @param index KEY or VALUE
- */
- private void setRed(final int index) {
- blackColor[index] = false;
- }
-
- /**
- * make this node the same color as another
- *
- * @param node the node whose color we're adopting
- * @param index KEY or VALUE
- */
- private void copyColor(final Node node, final int index) {
- blackColor[index] = node.blackColor[index];
- }
-
- /* ********** START implementation of Map.Entry ********** */
-
- /**
- * @return the key corresponding to this entry.
- */
- public Object getKey() {
- return data[KEY];
- }
-
- /**
- * @return the value corresponding to this entry.
- */
- public Object getValue() {
- return data[VALUE];
- }
-
- /**
- * Optional operation that is not permitted in this
- * implementation
- *
- * @param ignored
- *
- * @return does not return
- *
- * @exception UnsupportedOperationException
- */
- public Object setValue(Object ignored)
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException(
- "Map.Entry.setValue is not supported");
- }
-
- /**
- * Compares the specified object with this entry for equality.
- * Returns true if the given object is also a map entry and
- * the two entries represent the same mapping.
- *
- * @param o object to be compared for equality with this map
- * entry.
- * @return true if the specified object is equal to this map
- * entry.
- */
- public boolean equals(Object o) {
-
- if (this == o) {
- return true;
- }
-
- if (!(o instanceof Map.Entry)) {
- return false;
- }
-
- Map.Entry e = (Map.Entry) o;
-
- return data[KEY].equals(e.getKey())
- && data[VALUE].equals(e.getValue());
- }
-
- /**
- * @return the hash code value for this map entry.
- */
- public int hashCode() {
-
- if (!calculatedHashCode) {
- hashcodeValue = data[KEY].hashCode()
- ^ data[VALUE].hashCode();
- calculatedHashCode = true;
- }
-
- return hashcodeValue;
- }
-
- /* ********** END implementation of Map.Entry ********** */
- }
-} // end public class DoubleOrderedMap
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/HashBag.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/HashBag.java b/src/java/org/apache/commons/collections/HashBag.java
deleted file mode 100644
index bb1f7df..0000000
--- a/src/java/org/apache/commons/collections/HashBag.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/HashBag.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.Collection;
-import java.util.HashMap;
-
-/**
- * An implementation of {@link Bag} that is backed by a {@link
- * HashMap}.
- *
- * @author Chuck Burdick
- **/
-public class HashBag extends AbstractBag implements Bag {
- public HashBag() {
- setMap(new HashMap());
- }
-
- /**
- * New {@link Bag} containing all the members of the given
- * collection.
- * @see #addAll
- **/
- public HashBag(Collection c) {
- this();
- addAll(c);
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/ListUtils.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/ListUtils.java b/src/java/org/apache/commons/collections/ListUtils.java
deleted file mode 100644
index 55f5ad3..0000000
--- a/src/java/org/apache/commons/collections/ListUtils.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/ListUtils.java,v 1.3 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.3 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Miscelaneous utilities to manipulate Lists.
- *
- * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
- * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
- * @deprecated See {@link org.apache.commons.collections.CollectionUtils}.
- */
-public class ListUtils
-{
- public static List intersection( final List list1, final List list2 )
- {
- final ArrayList result = new ArrayList();
- final Iterator iterator = list2.iterator();
-
- while( iterator.hasNext() )
- {
- final Object o = iterator.next();
-
- if ( list1.contains( o ) )
- {
- result.add( o );
- }
- }
-
- return result;
- }
-
- public static List subtract( final List list1, final List list2 )
- {
- final ArrayList result = new ArrayList( list1 );
- final Iterator iterator = list2.iterator();
-
- while( iterator.hasNext() )
- {
- result.remove( iterator.next() );
- }
-
- return result;
- }
-
- public static List sum( final List list1, final List list2 )
- {
- return subtract( union( list1, list2 ),
- intersection( list1, list2 ) );
- }
-
- public static List union( final List list1, final List list2 )
- {
- final ArrayList result = new ArrayList( list1 );
- result.addAll( list2 );
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/MultiHashMap.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/MultiHashMap.java b/src/java/org/apache/commons/collections/MultiHashMap.java
deleted file mode 100644
index 0bed923..0000000
--- a/src/java/org/apache/commons/collections/MultiHashMap.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/MultiHashMap.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.*;
-import java.io.*;
-
-/** see MultiMap for details of an important semantic difference
- * between this and a typical HashMap
- *
- * @author Christopher Berry
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-public class MultiHashMap extends HashMap implements MultiMap
-{
- //----------------- Data
- private static int sCount = 0;
- private String mName = null;
-
- public MultiHashMap()
- {
- super();
- setName();
- }
-
- public MultiHashMap( int initialCapacity )
- {
- super( initialCapacity );
- setName();
- }
-
- public MultiHashMap(int initialCapacity, float loadFactor )
- {
- super( initialCapacity, loadFactor);
- setName();
- }
-
- public MultiHashMap( Map mapToCopy )
- {
- super( mapToCopy );
- }
-
- private void setName()
- {
- sCount++;
- mName = "MultiMap-" + sCount;
- }
-
- public String getName()
- { return mName; }
-
- public Object put( Object key, Object value )
- {
- // NOTE:: put might be called during deserialization !!!!!!
- // so we must provide a hook to handle this case
- // This means that we cannot make MultiMaps of ArrayLists !!!
-
- if ( value instanceof ArrayList ) {
- return ( super.put( key, value ) );
- }
-
- ArrayList keyList = (ArrayList)(super.get( key ));
- if ( keyList == null ) {
- keyList = new ArrayList(10);
-
- super.put( key, keyList );
- }
-
- boolean results = keyList.add( value );
-
- return ( results ? value : null );
- }
-
- public boolean containsValue( Object value )
- {
- Set pairs = super.entrySet();
-
- if ( pairs == null )
- return false;
-
- Iterator pairsIterator = pairs.iterator();
- while ( pairsIterator.hasNext() ) {
- Map.Entry keyValuePair = (Map.Entry)(pairsIterator.next());
- ArrayList list = (ArrayList)(keyValuePair.getValue());
- if( list.contains( value ) )
- return true;
- }
- return false;
- }
-
- public Object remove( Object key, Object item )
- {
- ArrayList valuesForKey = (ArrayList) super.get( key );
-
- if ( valuesForKey == null )
- return null;
-
- valuesForKey.remove( item );
- return item;
- }
-
- public void clear()
- {
- Set pairs = super.entrySet();
- Iterator pairsIterator = pairs.iterator();
- while ( pairsIterator.hasNext() ) {
- Map.Entry keyValuePair = (Map.Entry)(pairsIterator.next());
- ArrayList list = (ArrayList)(keyValuePair.getValue());
- list.clear();
- }
- super.clear();
- }
-
- public void putAll( Map mapToPut )
- {
- super.putAll( mapToPut );
- }
-
- public Collection values()
- {
- ArrayList returnList = new ArrayList( super.size() );
-
- Set pairs = super.entrySet();
- Iterator pairsIterator = pairs.iterator();
- while ( pairsIterator.hasNext() ) {
- Map.Entry keyValuePair = (Map.Entry)(pairsIterator.next());
- ArrayList list = (ArrayList)(keyValuePair.getValue());
-
- Object[] values = list.toArray();
- for( int ii=0; ii < values.length; ii++ ) {
- boolean successfulAdd = returnList.add( values[ii] );
- }
- }
- return returnList;
- }
-
- // FIXME:: do we need to implement this??
- // public boolean equals( Object obj ) {}
-
- // --------------- From Cloneable
- public Object clone()
- {
- MultiHashMap obj = (MultiHashMap)(super.clone());
- obj.mName = mName;
- return obj;
- }
-
-}
[18/18] commons-collections git commit: Moving to TLP
Posted by ch...@apache.org.
Moving to TLP
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/branches/collections_1_x_branch@560660 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/88d84e95
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/88d84e95
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/88d84e95
Branch: refs/heads/collections_1_x_branch
Commit: 88d84e95ecdb1188a9fe07ca9be8562a7a69e1f5
Parents: ae8c0fa
Author: Henri Yandell <ba...@apache.org>
Authored: Sun Jul 29 03:42:34 2007 +0000
Committer: Henri Yandell <ba...@apache.org>
Committed: Sun Jul 29 03:42:34 2007 +0000
----------------------------------------------------------------------
----------------------------------------------------------------------
[08/18] commons-collections git commit: remove test class,
which was based on code never released in Collections 1.0
Posted by ch...@apache.org.
remove test class, which was based on code never released in Collections
1.0
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130592 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/205c1a3f
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/205c1a3f
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/205c1a3f
Branch: refs/heads/collections_1_x_branch
Commit: 205c1a3f340b686cf5e239c0256ac8a706c2c013
Parents: 03ef316
Author: Morgan James Delagrange <mo...@apache.org>
Authored: Tue Feb 26 05:44:14 2002 +0000
Committer: Morgan James Delagrange <mo...@apache.org>
Committed: Tue Feb 26 05:44:14 2002 +0000
----------------------------------------------------------------------
.../org/apache/commons/collections/TestAll.java | 9 +-
.../commons/collections/TestArrayIterator2.java | 114 -------------------
2 files changed, 4 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/205c1a3f/src/test/org/apache/commons/collections/TestAll.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestAll.java b/src/test/org/apache/commons/collections/TestAll.java
index dc87876..5c138e3 100644
--- a/src/test/org/apache/commons/collections/TestAll.java
+++ b/src/test/org/apache/commons/collections/TestAll.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestAll.java,v 1.15.2.1 2002/02/26 00:58:29 morgand Exp $
- * $Revision: 1.15.2.1 $
- * $Date: 2002/02/26 00:58:29 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestAll.java,v 1.15.2.2 2002/02/26 05:44:14 morgand Exp $
+ * $Revision: 1.15.2.2 $
+ * $Date: 2002/02/26 05:44:14 $
*
* ====================================================================
*
@@ -66,7 +66,7 @@ import junit.framework.*;
/**
* Entry point for all Collections tests.
* @author Rodney Waldhoff
- * @version $Id: TestAll.java,v 1.15.2.1 2002/02/26 00:58:29 morgand Exp $
+ * @version $Id: TestAll.java,v 1.15.2.2 2002/02/26 05:44:14 morgand Exp $
*/
public class TestAll extends TestCase {
public TestAll(String testName) {
@@ -76,7 +76,6 @@ public class TestAll extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(TestArrayIterator.suite());
- suite.addTest(TestArrayIterator2.suite());
suite.addTest(TestArrayList.suite());
suite.addTest(TestArrayStack.suite());
suite.addTest(TestCollectionUtils.suite());
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/205c1a3f/src/test/org/apache/commons/collections/TestArrayIterator2.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestArrayIterator2.java b/src/test/org/apache/commons/collections/TestArrayIterator2.java
deleted file mode 100644
index 0a04205..0000000
--- a/src/test/org/apache/commons/collections/TestArrayIterator2.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestArrayIterator2.java,v 1.1 2001/08/23 12:04:40 jstrachan Exp $
- * $Revision: 1.1 $
- * $Date: 2001/08/23 12:04:40 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import junit.framework.*;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * Tests the ArrayIterator with primitive type arrays
- *
- * @author James Strachan
- * @version $Id: TestArrayIterator2.java,v 1.1 2001/08/23 12:04:40 jstrachan Exp $
- */
-public class TestArrayIterator2 extends TestObject {
-
- protected int[] testArray = {
- 2, 4, 6, 8
- };
-
- public static Test suite() {
- return new TestSuite(TestArrayIterator2.class);
- }
-
- public TestArrayIterator2(String testName) {
- super(testName);
- }
-
- /**
- * Return a new, empty {@link Object} to used for testing.
- */
- public Object makeObject() {
- return new ArrayIterator( testArray );
- }
-
- public void testIterator() {
- Iterator iter = (Iterator) makeObject();
- for ( int i = 0; i < testArray.length; i++ ) {
- Integer testValue = new Integer( testArray[i] );
- Number iterValue = (Number) iter.next();
-
- assertEquals( "Iteration value is correct", testValue, iterValue );
- }
-
- assertTrue("Iterator should now be empty", ! iter.hasNext() );
-
- try {
- Object testValue = iter.next();
- } catch (Exception e) {
- assertTrue("NoSuchElementException must be thrown",
- e.getClass().equals((new NoSuchElementException()).getClass()));
- }
- }
-}
-
[13/18] commons-collections git commit: This commit was manufactured
by cvs2svn to create branch 'collections_1_x_branch'.
Posted by ch...@apache.org.
This commit was manufactured by cvs2svn to create branch
'collections_1_x_branch'.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130603 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/37f759c0
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/37f759c0
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/37f759c0
Branch: refs/heads/collections_1_x_branch
Commit: 37f759c0a87423d53444f8454df7ab11e801befe
Parents: d15d67b
Author: No Author <de...@apache.org>
Authored: Tue Feb 26 18:08:58 2002 +0000
Committer: No Author <de...@apache.org>
Committed: Tue Feb 26 18:08:58 2002 +0000
----------------------------------------------------------------------
data/test/FastHashMap.emptyCollection.version1.obj | Bin 0 -> 200 bytes
data/test/FastHashMap.fullCollection.version1.obj | Bin 0 -> 451 bytes
data/test/FastTreeMap.emptyCollection.version1.obj | Bin 0 -> 191 bytes
data/test/FastTreeMap.fullCollection.version1.obj | Bin 0 -> 630 bytes
4 files changed, 0 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/37f759c0/data/test/FastHashMap.emptyCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastHashMap.emptyCollection.version1.obj b/data/test/FastHashMap.emptyCollection.version1.obj
new file mode 100644
index 0000000..113e5cc
Binary files /dev/null and b/data/test/FastHashMap.emptyCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/37f759c0/data/test/FastHashMap.fullCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastHashMap.fullCollection.version1.obj b/data/test/FastHashMap.fullCollection.version1.obj
new file mode 100644
index 0000000..3e8dff1
Binary files /dev/null and b/data/test/FastHashMap.fullCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/37f759c0/data/test/FastTreeMap.emptyCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastTreeMap.emptyCollection.version1.obj b/data/test/FastTreeMap.emptyCollection.version1.obj
new file mode 100644
index 0000000..ad18ca8
Binary files /dev/null and b/data/test/FastTreeMap.emptyCollection.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/37f759c0/data/test/FastTreeMap.fullCollection.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastTreeMap.fullCollection.version1.obj b/data/test/FastTreeMap.fullCollection.version1.obj
new file mode 100644
index 0000000..32ef3e3
Binary files /dev/null and b/data/test/FastTreeMap.fullCollection.version1.obj differ
[12/18] commons-collections git commit: Serialized copies of
Collections 1.0 objects
Posted by ch...@apache.org.
Serialized copies of Collections 1.0 objects
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130596 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/d15d67b3
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/d15d67b3
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/d15d67b3
Branch: refs/heads/collections_1_x_branch
Commit: d15d67b3e0932e9415ed01e0a4fd81eb3c73c7a2
Parents: 84e9b7d
Author: Morgan James Delagrange <mo...@apache.org>
Authored: Tue Feb 26 06:33:28 2002 +0000
Committer: Morgan James Delagrange <mo...@apache.org>
Committed: Tue Feb 26 06:33:28 2002 +0000
----------------------------------------------------------------------
data/test/FastHashMap.emptyMap.version1.obj | Bin 0 -> 200 bytes
data/test/FastHashMap.fullMap.version1.obj | Bin 0 -> 451 bytes
data/test/FastTreeMap.emptyMap.version1.obj | Bin 0 -> 191 bytes
data/test/FastTreeMap.fullMap.version1.obj | Bin 0 -> 630 bytes
data/test/LRUMap.emptyMap.version1.obj | Bin 0 -> 126 bytes
data/test/LRUMap.fullMap.version1.obj | Bin 0 -> 663 bytes
data/test/LRUMapVersion1.obj | Bin 266 -> 0 bytes
7 files changed, 0 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/d15d67b3/data/test/FastHashMap.emptyMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastHashMap.emptyMap.version1.obj b/data/test/FastHashMap.emptyMap.version1.obj
new file mode 100644
index 0000000..113e5cc
Binary files /dev/null and b/data/test/FastHashMap.emptyMap.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/d15d67b3/data/test/FastHashMap.fullMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastHashMap.fullMap.version1.obj b/data/test/FastHashMap.fullMap.version1.obj
new file mode 100644
index 0000000..3e8dff1
Binary files /dev/null and b/data/test/FastHashMap.fullMap.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/d15d67b3/data/test/FastTreeMap.emptyMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastTreeMap.emptyMap.version1.obj b/data/test/FastTreeMap.emptyMap.version1.obj
new file mode 100644
index 0000000..ad18ca8
Binary files /dev/null and b/data/test/FastTreeMap.emptyMap.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/d15d67b3/data/test/FastTreeMap.fullMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/FastTreeMap.fullMap.version1.obj b/data/test/FastTreeMap.fullMap.version1.obj
new file mode 100644
index 0000000..32ef3e3
Binary files /dev/null and b/data/test/FastTreeMap.fullMap.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/d15d67b3/data/test/LRUMap.emptyMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/LRUMap.emptyMap.version1.obj b/data/test/LRUMap.emptyMap.version1.obj
new file mode 100644
index 0000000..c235e33
Binary files /dev/null and b/data/test/LRUMap.emptyMap.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/d15d67b3/data/test/LRUMap.fullMap.version1.obj
----------------------------------------------------------------------
diff --git a/data/test/LRUMap.fullMap.version1.obj b/data/test/LRUMap.fullMap.version1.obj
new file mode 100644
index 0000000..417b1fa
Binary files /dev/null and b/data/test/LRUMap.fullMap.version1.obj differ
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/d15d67b3/data/test/LRUMapVersion1.obj
----------------------------------------------------------------------
diff --git a/data/test/LRUMapVersion1.obj b/data/test/LRUMapVersion1.obj
deleted file mode 100644
index a520cee..0000000
Binary files a/data/test/LRUMapVersion1.obj and /dev/null differ
[07/18] commons-collections git commit: to ease maintenance,
removed all unreleased classes from the 1.x branch
Posted by ch...@apache.org.
to ease maintenance, removed all unreleased classes from the 1.x branch
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130591 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/03ef3163
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/03ef3163
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/03ef3163
Branch: refs/heads/collections_1_x_branch
Commit: 03ef31630037d07ad1e89c7fe7fb98e5716bf0db
Parents: 6a2c9bf
Author: Morgan James Delagrange <mo...@apache.org>
Authored: Tue Feb 26 00:58:29 2002 +0000
Committer: Morgan James Delagrange <mo...@apache.org>
Committed: Tue Feb 26 00:58:29 2002 +0000
----------------------------------------------------------------------
.../apache/commons/collections/AbstractBag.java | 335 ---
.../org/apache/commons/collections/Bag.java | 181 --
.../commons/collections/DoubleOrderedMap.java | 2046 -------------
.../org/apache/commons/collections/HashBag.java | 89 -
.../apache/commons/collections/ListUtils.java | 119 -
.../commons/collections/MultiHashMap.java | 206 --
.../apache/commons/collections/MultiMap.java | 80 -
.../commons/collections/SequencedHashMap.java | 888 ------
.../commons/collections/SingletonIterator.java | 98 -
.../apache/commons/collections/SortedBag.java | 88 -
.../org/apache/commons/collections/TreeBag.java | 117 -
.../org/apache/commons/collections/TestAll.java | 14 +-
.../org/apache/commons/collections/TestBag.java | 251 --
.../collections/TestDoubleOrderedMap.java | 2798 ------------------
.../apache/commons/collections/TestHashBag.java | 90 -
.../commons/collections/TestMultiHashMap.java | 226 --
.../collections/TestSequencedHashMap.java | 177 --
.../collections/TestSingletonIterator.java | 112 -
.../apache/commons/collections/TestTreeBag.java | 119 -
19 files changed, 4 insertions(+), 8030 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/AbstractBag.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/AbstractBag.java b/src/java/org/apache/commons/collections/AbstractBag.java
deleted file mode 100644
index 864aeee..0000000
--- a/src/java/org/apache/commons/collections/AbstractBag.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/AbstractBag.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-/**
- * This class provides a skeletal implementation of the {@link Bag}
- * interface to minimize the effort required for target implementations.
- *
- * @author Chuck Burdick
- **/
-public abstract class AbstractBag implements Bag {
- private Map _map = null;
- private int _total = 0;
- private int _mods = 0;
-
- public boolean add(Object o) {
- return add(o, 1);
- }
-
- public boolean add(Object o, int i) {
- _mods++;
- if (i > 0) {
- int count = (i + getCount(o));
- _map.put(o, new Integer(count));
- _total += i;
- return (getCount(o) == i);
- } else {
- return false;
- }
- }
-
- public boolean addAll(Collection c) {
- boolean changed = false;
- Iterator i = c.iterator();
- while (i.hasNext()) {
- boolean added = add(i.next());
- changed = changed || added;
- }
- return changed;
- }
-
- public void clear() {
- _mods++;
- _map.clear();
- _total = 0;
- }
-
- public boolean contains(Object o) {
- return _map.containsKey(o);
- }
-
- public boolean containsAll(Collection c) {
- return containsAll(new HashBag(c));
- }
-
- /**
- * Returns <code>true</code> if the bag contains all elements in
- * the given collection, respecting cardinality.
- * @see #containsAll(Collection)
- **/
- public boolean containsAll(Bag other) {
- boolean result = true;
- Iterator i = other.uniqueSet().iterator();
- while (i.hasNext()) {
- Object current = i.next();
- boolean contains =
- getCount(current) >= ((Bag)other).getCount(current);
- result = result && contains;
- }
- return result;
- }
-
- public boolean equals(Object o) {
- boolean result = false;
- if (o instanceof AbstractBag) {
- result = _map.equals(((AbstractBag)o).getMap());
- } else if (o instanceof Map) {
- result = _map.equals((Map)o);
- }
- return result;
- }
-
- public int hashCode() {
- return _map.hashCode();
- }
-
- public boolean isEmpty() {
- return _map.isEmpty();
- }
-
- public Iterator iterator() {
- return new BagIterator(this, extractList().iterator());
- }
-
- private class BagIterator implements Iterator {
- private AbstractBag _parent = null;
- private Iterator _support = null;
- private Object _current = null;
- private int _mods = 0;
-
- public BagIterator(AbstractBag parent, Iterator support) {
- _parent = parent;
- _support = support;
- _current = null;
- _mods = parent.modCount();
- }
-
- public boolean hasNext() {
- return _support.hasNext();
- }
-
- public Object next() {
- if (_parent.modCount() != _mods) {
- throw new ConcurrentModificationException();
- }
- _current = _support.next();
- return _current;
- }
-
- public void remove() {
- if (_parent.modCount() != _mods) {
- throw new ConcurrentModificationException();
- }
- _support.remove();
- _parent.remove(_current, 1);
- _mods++;
- }
- }
-
- public boolean remove (Object o) {
- return remove(o, getCount(o));
- }
-
- public boolean remove (Object o, int i) {
- _mods++;
- boolean result = false;
- int count = getCount(o);
- if (count > i) {
- _map.put(o, new Integer(count - i));
- result = true;
- _total -= i;
- } else {
- result = uniqueSet().remove(o);
- _total -= count;
- }
- return result;
- }
-
- public boolean removeAll(Collection c) {
- boolean result = false;
- if (c != null) {
- Iterator i = c.iterator();
- while (i.hasNext()) {
- boolean changed = remove(i.next(), 1);
- result = result || changed;
- }
- }
- return result;
- }
-
- public boolean retainAll(Collection c) {
- return retainAll(new HashBag(c));
- }
-
- /**
- * Remove any members of the bag that are not in the given
- * bag, respecting cardinality.
- * @see #retainAll(Collection)
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean retainAll(Bag other) {
- boolean result = false;
- Bag excess = new HashBag();
- Iterator i = uniqueSet().iterator();
- while (i.hasNext()) {
- Object current = i.next();
- int myCount = getCount(current);
- int otherCount = other.getCount(current);
- if (1 <= otherCount && otherCount <= myCount) {
- excess.add(current, myCount - otherCount);
- } else {
- excess.add(current, myCount);
- }
- }
- if (!excess.isEmpty()) {
- result = removeAll(excess);
- }
- return result;
- }
-
- public Object[] toArray() {
- return extractList().toArray();
- }
-
- public Object[] toArray(Object[] a) {
- return extractList().toArray(a);
- }
-
- public int getCount(Object o) {
- int result = 0;
- Integer count = MapUtils.getInteger(_map, o);
- if (count != null) {
- result = count.intValue();
- }
- return result;
- }
-
- public Set uniqueSet() {
- return _map.keySet();
- }
-
- public int size() {
- return _total;
- }
-
- /**
- * Actually walks the bag to make sure the count is correct and
- * resets the running total
- **/
- protected int calcTotalSize() {
- _total = extractList().size();
- return _total;
- }
-
- /**
- * Utility method for implementations to set the map that backs
- * this bag. Not intended for interactive use outside of
- * subclasses.
- **/
- protected void setMap(Map m) {
- _map = m;
- }
-
- /**
- * Utility method for implementations to access the map that backs
- * this bag. Not intended for interactive use outside of
- * subclasses.
- **/
- protected Map getMap() {
- return _map;
- }
-
- /**
- * Create a list for use in iteration, etc.
- **/
- private List extractList() {
- List result = new ArrayList();
- Iterator i = uniqueSet().iterator();
- while (i.hasNext()) {
- Object current = i.next();
- for (int index = 0; index < getCount(current); index++) {
- result.add(current);
- }
- }
- return result;
- }
-
- /**
- * Return number of modifications for iterator
- **/
- private int modCount() {
- return _mods;
- }
-}
-
-
-
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/java/org/apache/commons/collections/Bag.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/collections/Bag.java b/src/java/org/apache/commons/collections/Bag.java
deleted file mode 100644
index 560f5d8..0000000
--- a/src/java/org/apache/commons/collections/Bag.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Bag.java,v 1.2 2002/02/10 08:07:42 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/10 08:07:42 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A {@link Collection} that keeps a count of its members of the same
- * type, using <code>hashCode</code> to check for equality. Suppose
- * you have a Bag that contains <code>{a, a, b, c}</code>. Calling
- * {@link #getCount} on <code>a</code> would return 2, while calling
- * {@link #uniqueSet} would return <code>{a, b, c}</code>.
- *
- * @author Chuck Burdick
- **/
-public interface Bag extends Collection {
- /**
- * Return the number of occurrences (cardinality) of the given
- * object currently in the bag. If the object does not exist in the
- * bag, return 0.
- **/
- public int getCount(Object o);
-
- /**
- * Add the given object to the bag and keep a count. If the object
- * is already in the {@link #uniqueSet} then increment its count as
- * reported by {@link #getCount}. Otherwise add it to the {@link
- * #uniqueSet} and report its count as 1.
- * @return <code>true</code> if the object was not already in the
- * <code>uniqueSet</code>
- * @see #getCount
- **/
- public boolean add(Object o);
-
- /**
- * Add <code>i</code> copies of the given object to the bag and
- * keep a count.
- * @return <code>true</code> if the object was not already in the
- * <code>uniqueSet</code>
- * @see #add(Object)
- * @see #getCount
- **/
- public boolean add(Object o, int i);
-
- /**
- * Remove all occurrences of the given object from the bag, and do
- * not represent the object in the {@link #uniqueSet}.
- * @see #remove(Object, int)
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean remove(Object o);
-
- /**
- * Remove the given number of occurrences from the bag. If the bag
- * contains less than <code>i</code> occurrences, the item will be
- * removed from the {@link #uniqueSet}.
- * @see #getCount
- * @see #remove(Object)
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean remove(Object o, int i);
-
- /**
- * The {@link Set} of unique members that represent all members in
- * the bag. Uniqueness constraints are the same as those in {@link
- * Set}.
- **/
- public Set uniqueSet();
-
- /**
- * Returns the total number of items in the bag across all types.
- * @see #size
- **/
- public int size();
-
- /**
- * Returns <code>true</code> if the bag contains all elements in
- * the given collection, respecting cardinality. That is, if the
- * given collection <code>C</code> contains <code>n</code> copies
- * of a given object, calling {@link #getCount} on that object must
- * be >= <code>n</code> for all <code>n</code> in <code>C</code>.
- **/
- public boolean containsAll(Collection c);
-
- /**
- * Remove all elements represented in the given collection,
- * respecting cardinality. That is, if the given collection
- * <code>C</code> contains <code>n</code> copies of a given object,
- * the bag will have <code>n</code> fewer copies, assuming the bag
- * had at least <code>n</code> copies to begin with.
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean removeAll(Collection c);
-
- /**
- * Remove any members of the bag that are not in the given
- * collection, respecting cardinality. That is, if the given
- * collection <code>C</code> contains <code>n</code> copies of a
- * given object and the bag has <code>m > n</code> copies, then
- * delete <code>m - n</code> copies from the bag. In addition, if
- * <code>e</code> is an object in the bag but
- * <code>!C.contains(e)</code>, then remove <code>e</code> and any
- * of its copies.
- *
- * @return <code>true</code> if this call changed the collection
- **/
- public boolean retainAll(Collection c);
-
- /**
- * Returns an {@link Iterator} over the entire set of members,
- * including copies due to cardinality. This iterator is fail-fast
- * and will not tolerate concurrent modifications.
- **/
- public Iterator iterator();
-}
-
-
-
-
-
[03/18] commons-collections git commit: to ease maintenance,
removed all unreleased classes from the 1.x branch
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/test/org/apache/commons/collections/TestSequencedHashMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestSequencedHashMap.java b/src/test/org/apache/commons/collections/TestSequencedHashMap.java
deleted file mode 100644
index d213624..0000000
--- a/src/test/org/apache/commons/collections/TestSequencedHashMap.java
+++ /dev/null
@@ -1,177 +0,0 @@
-package org.apache.commons.collections;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001 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 acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache Turbine" 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",
- * "Apache Turbine", nor may "Apache" appear in their name, 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/>.
- */
-
-import java.util.Iterator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Unit tests {@link org.apache.commons.collections.SequencedHashMap}.
- *
- * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
- * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
- * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- */
-public class TestSequencedHashMap extends TestHashMap
-{
- /**
- * The instance to experiment on.
- */
- protected SequencedHashMap labRat;
-
- public TestSequencedHashMap(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(TestSequencedHashMap.class);
- }
-
- public static void main(String[] args[]) {
- String[] testCaseName = { TestSequencedHashMap.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- public void setUp() {
- super.setUp();
- labRat = new SequencedHashMap();
- }
-
- public Map makeMap() {
- return new SequencedHashMap();
- }
-
- protected Object[] getKeys() {
- return new Object[] { "foo", "baz", "eek" };
- }
-
- protected Object[] getValues() {
- return new Object[] { "bar", "frob", new Object() };
- }
-
- public void testSequenceMap() throws Throwable {
- Object[] keys = getKeys();
- int expectedSize = keys.length;
- Object[] values = getValues();
- for (int i = 0; i < expectedSize; i++) {
- labRat.put(keys[i], values[i]);
- }
-
- // Test size().
- assertEquals("size() does not match expected size",
- expectedSize, labRat.size());
-
- // Test clone(), iterator(), and get(Object).
- SequencedHashMap clone = (SequencedHashMap) labRat.clone();
- assertEquals("Size of clone does not match original",
- labRat.size(), clone.size());
- Iterator origKeys = labRat.keySet().iterator();
- Iterator copiedKeys = clone.keySet().iterator();
- while (origKeys.hasNext()) {
- Object origKey = origKeys.next();
- Object copiedKey = copiedKeys.next();
- assertEquals("Cloned key does not match orginal",
- origKey, copiedKey);
- assertEquals("Cloned value does not match original",
- labRat.get(origKey), clone.get(copiedKey));
- }
- assertTrue("iterator() returned different number of elements than keys()",
- !copiedKeys.hasNext());
-
- // Test sequence()
- List seq = labRat.sequence();
- assertEquals("sequence() returns more keys than in the Map",
- expectedSize, seq.size());
-
- for (int i = 0; i < seq.size(); i++) {
- assertEquals("Key " + i + " is not the same as the key in the Map",
- keys[i], seq.get(i));
- }
- }
-
- public void testYoungest() {
- labRat.put(new Integer(1),"foo");
- labRat.put(new Integer(2),"bar");
- assertTrue("first key is correct",labRat.get(0).equals(new Integer(1)));
- labRat.put(new Integer(1),"boo");
- assertTrue("second key is reassigned to first",labRat.get(0).equals(new Integer(2)));
- }
-
- public void testYoungestReplaceNullWithValue() {
- labRat.put(new Integer(1),null);
- labRat.put(new Integer(2),"foo");
- assertTrue("first key is correct",labRat.get(0).equals(new Integer(1)));
- labRat.put(new Integer(1),"bar");
- assertTrue("second key is reassigned to first",labRat.get(0).equals(new Integer(2)));
- }
-
- public void testYoungestReplaceValueWithNull() {
- labRat.put(new Integer(1),"bar");
- labRat.put(new Integer(2),"foo");
- assertTrue("first key is correct",labRat.get(0).equals(new Integer(1)));
- labRat.put(new Integer(1),null);
- assertTrue("second key is reassigned to first",labRat.get(0).equals(new Integer(2)));
- }
-
- protected void tearDown() {
- labRat = null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/test/org/apache/commons/collections/TestSingletonIterator.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestSingletonIterator.java b/src/test/org/apache/commons/collections/TestSingletonIterator.java
deleted file mode 100644
index b6d0b95..0000000
--- a/src/test/org/apache/commons/collections/TestSingletonIterator.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestSingletonIterator.java,v 1.1 2001/08/22 07:43:53 jstrachan Exp $
- * $Revision: 1.1 $
- * $Date: 2001/08/22 07:43:53 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import junit.framework.*;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * Tests the SingletonIterator to ensure that the next() method will actually
- * perform the iteration rather than the hasNext() method.
- *
- * @author James Strachan
- * @version $Id: TestSingletonIterator.java,v 1.1 2001/08/22 07:43:53 jstrachan Exp $
- */
-public class TestSingletonIterator extends TestObject {
-
- private static final Object testValue = "foo";
-
- public static Test suite() {
- return new TestSuite(TestSingletonIterator.class);
- }
-
- public TestSingletonIterator(String testName) {
- super(testName);
- }
-
- /**
- * Return a new, empty {@link Object} to used for testing.
- */
- public Object makeObject() {
- return new SingletonIterator( testValue );
- }
-
- public void testIterator() {
- Iterator iter = (Iterator) makeObject();
- assertTrue( "Iterator has a first item", iter.hasNext() );
-
- Object iterValue = iter.next();
- assertEquals( "Iteration value is correct", testValue, iterValue );
-
- assertTrue("Iterator should now be empty", ! iter.hasNext() );
-
- try {
- Object testValue = iter.next();
- }
- catch (Exception e) {
- assertTrue("NoSuchElementException must be thrown",
- e.getClass().equals((new NoSuchElementException()).getClass()));
- }
- }
-}
-
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/test/org/apache/commons/collections/TestTreeBag.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestTreeBag.java b/src/test/org/apache/commons/collections/TestTreeBag.java
deleted file mode 100644
index 930bb77..0000000
--- a/src/test/org/apache/commons/collections/TestTreeBag.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestTreeBag.java,v 1.1 2001/08/29 15:28:07 jstrachan Exp $
- * $Revision: 1.1 $
- * $Date: 2001/08/29 15:28:07 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import junit.framework.*;
-
-/**
- * Extension of {@link TestBag} for exercising the {@link TreeBag}
- * implementation.
- *
- * @author Chuck Burdick
- * @version $Id: TestTreeBag.java,v 1.1 2001/08/29 15:28:07 jstrachan Exp $ */
-public class TestTreeBag extends TestBag {
- public TestTreeBag(String testName) {
- super(testName);
- }
-
- public static Test suite() {
- return new TestSuite(TestTreeBag.class);
- }
-
- public static void main(String args[]) {
- String[] testCaseName = { TestTreeBag.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- public Bag makeBag() {
- return new TreeBag();
- }
-
- public SortedBag setupBag() {
- SortedBag bag = (SortedBag)makeBag();
- bag.add("C");
- bag.add("A");
- bag.add("B");
- bag.add("D");
- return bag;
- }
-
- public void testOrdering() {
- Bag bag = setupBag();
- assertEquals("Should get elements in correct order",
- "A", bag.toArray()[0]);
- assertEquals("Should get elements in correct order",
- "B", bag.toArray()[1]);
- assertEquals("Should get elements in correct order",
- "C", bag.toArray()[2]);
- assertEquals("Should get first key",
- "A", ((SortedBag)bag).first());
- assertEquals("Should get last key",
- "D", ((SortedBag)bag).last());
- }
-}
-
-
-
-
-
-
-
[10/18] commons-collections git commit: removing some unwanted code
Posted by ch...@apache.org.
removing some unwanted code
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130594 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/97c3230e
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/97c3230e
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/97c3230e
Branch: refs/heads/collections_1_x_branch
Commit: 97c3230e8332fe8ca9e0667b356eda0a128f2727
Parents: 1411769
Author: Morgan James Delagrange <mo...@apache.org>
Authored: Tue Feb 26 06:28:41 2002 +0000
Committer: Morgan James Delagrange <mo...@apache.org>
Committed: Tue Feb 26 06:28:41 2002 +0000
----------------------------------------------------------------------
.../org/apache/commons/collections/TestMap.java | 21 ++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/97c3230e/src/test/org/apache/commons/collections/TestMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestMap.java b/src/test/org/apache/commons/collections/TestMap.java
index 5847898..7c18049 100644
--- a/src/test/org/apache/commons/collections/TestMap.java
+++ b/src/test/org/apache/commons/collections/TestMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.3.2.2 2002/02/26 06:17:51 morgand Exp $
- * $Revision: 1.3.2.2 $
- * $Date: 2002/02/26 06:17:51 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestMap.java,v 1.3.2.3 2002/02/26 06:28:41 morgand Exp $
+ * $Revision: 1.3.2.3 $
+ * $Date: 2002/02/26 06:28:41 $
*
* ====================================================================
*
@@ -87,7 +87,7 @@ import java.util.NoSuchElementException;
*
* @author Michael Smith
* @author Rodney Waldhoff
- * @version $Id: TestMap.java,v 1.3.2.2 2002/02/26 06:17:51 morgand Exp $
+ * @version $Id: TestMap.java,v 1.3.2.3 2002/02/26 06:28:41 morgand Exp $
*/
public abstract class TestMap extends TestObject {
@@ -959,10 +959,14 @@ public abstract class TestMap extends TestObject {
* against the canonical version in CVS.
*/
public void testEmptyMapCompatibility() throws IOException, ClassNotFoundException {
- Map map = makeEmptyMap();
+ Map map = null;
+ /**
+ * Create canonical objects with this code
+ map = makeEmptyMap();
if (!(map instanceof Serializable)) return;
writeExternalFormToDisk((Serializable) map, getCanonicalEmptyMapName(map));
+ */
// test to make sure the canonical form has been preserved
if (!(makeEmptyMap() instanceof Serializable)) return;
@@ -975,10 +979,15 @@ public abstract class TestMap extends TestObject {
* against the canonical version in CVS.
*/
public void testFullMapCompatibility() throws IOException, ClassNotFoundException {
- Map map = makeFullMap();
+
+ Map map = null;
+ /**
+ * Create canonical objects with this code
+ map = makeFullMap();
if (!(map instanceof Serializable)) return;
writeExternalFormToDisk((Serializable) map, getCanonicalFullMapName(map));
+ */
// test to make sure the canonical form has been preserved
if (!(makeFullMap() instanceof Serializable)) return;
[04/18] commons-collections git commit: to ease maintenance,
removed all unreleased classes from the 1.x branch
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/test/org/apache/commons/collections/TestDoubleOrderedMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestDoubleOrderedMap.java b/src/test/org/apache/commons/collections/TestDoubleOrderedMap.java
deleted file mode 100644
index dc61166..0000000
--- a/src/test/org/apache/commons/collections/TestDoubleOrderedMap.java
+++ /dev/null
@@ -1,2798 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestDoubleOrderedMap.java,v 1.1 2002/01/20 04:36:08 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2002/01/20 04:36:08 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2002 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-
-
-import junit.framework.*;
-
-import java.util.*;
-
-
-/**
-* Class TestDoubleOrderedMap
-*
-* Test cases for DoubleOrderedMap
-*
-* @author Marc Johnson (marcj at users dot sourceforge dot net)
-*/
-public class TestDoubleOrderedMap extends TestCase {
-
- /**
- * constructor
- *
- * @param name
- */
- public TestDoubleOrderedMap(final String name) {
- super(name);
- }
-
- /**
- * create a suite of the tests in this class
- *
- * @return the test suite
- */
- public static Test suite() {
- return new TestSuite(TestDoubleOrderedMap.class);
- }
-
- /**
- * test size() method
- */
- public void testSize() {
-
- Map m = new DoubleOrderedMap();
-
- assertEquals(0, m.size());
-
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k].getValue());
- assertEquals(k + 1, m.size());
- }
-
- int count = m.size();
-
- for (int k = 0; k < nodes.length; k++) {
- m.remove(nodes[k].getKey());
-
- --count;
-
- assertEquals(count, m.size());
-
- // failed remove should not affect size
- m.remove(nodes[k].getKey());
- assertEquals(count, m.size());
- }
- }
-
- /**
- * test IsEmpty() method
- */
- public void testIsEmpty() {
-
- Map m = new DoubleOrderedMap();
-
- assertTrue(m.isEmpty());
-
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k].getValue());
- assertTrue(!m.isEmpty());
- }
-
- int count = m.size();
-
- for (int k = 0; k < nodes.length; k++) {
- m.remove(nodes[k].getKey());
-
- --count;
-
- if (count == 0) {
- assertTrue(m.isEmpty());
- } else {
- assertTrue(!m.isEmpty());
- }
-
- // failed remove should not affect emptiness
- m.remove(nodes[k].getKey());
-
- if (count == 0) {
- assertTrue(m.isEmpty());
- } else {
- assertTrue(!m.isEmpty());
- }
- }
- }
-
- /**
- * test containsKey() method
- */
- public void testContainsKey() {
-
- Map m = new DoubleOrderedMap();
-
- try {
- m.containsKey(new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- try {
- m.containsKey(null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- assertTrue(!m.containsKey("foo"));
-
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- assertTrue(m.containsKey(nodes[k].getKey()));
- }
-
- assertTrue(!m.containsKey(new Integer(-1)));
-
- try {
- m.containsKey("foo");
- fail("Should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- for (int k = 0; k < nodes.length; k++) {
- m.remove(nodes[k].getKey());
- assertTrue(!m.containsKey(nodes[k].getKey()));
- }
- }
-
- /**
- * test containsValue() method
- */
- public void testContainsValue() {
-
- Map m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- assertTrue(m.containsValue(nodes[k]));
- }
-
- for (int k = 0; k < nodes.length; k++) {
- m.remove(nodes[k].getKey());
- assertTrue(!m.containsValue(nodes[k]));
- }
- }
-
- /**
- * test get() method
- */
- public void testGet() {
-
- Map m = new DoubleOrderedMap();
-
- try {
- m.get(new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- try {
- m.get(null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- assertNull(m.get("foo"));
-
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- assertSame(m.get(nodes[k].getKey()), nodes[k]);
- }
-
- assertNull(m.get(new Integer(-1)));
-
- try {
- m.get("foo");
- fail("Should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- for (int k = 0; k < nodes.length; k++) {
- assertNotNull(m.get(nodes[k].getKey()));
- m.remove(nodes[k].getKey());
- assertNull(m.get(nodes[k].getKey()));
- }
- }
-
- /**
- * test put() method
- */
- public void testPut() {
-
- Map m = new DoubleOrderedMap();
-
- try {
- m.put(new Object(), "foo");
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- try {
- m.put(null, "foo");
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- try {
- m.put("foo", null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- try {
- m.put("foo", new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- LocalTestNode[] nodes = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- assertNull(m.put(nodes[k].getKey(), nodes[k].getValue()));
-
- try {
- m.put(nodes[k].getKey(), "foo");
- } catch (IllegalArgumentException ignored) {}
- }
- }
-
- /**
- * test remove() method
- */
- public void testRemove() {
-
- DoubleOrderedMap m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- try {
- m.remove(null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- try {
- m.remove(new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- assertNull(m.remove(new Integer(-1)));
-
- try {
- m.remove("foo");
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- for (int k = 0; k < nodes.length; k += 2) {
- Comparable key = nodes[k].getKey();
-
- assertNotNull(m.get(key));
- assertSame(nodes[k], m.remove(key));
- assertNull(m.remove(key));
- assertNull(m.get(key));
- }
-
- for (int k = 1; k < nodes.length; k += 2) {
- Comparable key = nodes[k].getKey();
-
- assertNotNull(m.get(key));
- assertSame(nodes[k], m.remove(key));
- assertNull(m.remove(key));
- assertNull(m.get(key));
- }
-
- assertTrue(m.isEmpty());
- }
-
- /**
- * Method testPutAll
- */
- public void testPutAll() {
-
- Map m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- Map m1 = new HashMap();
-
- m1.put(null, "foo");
-
- try {
- m.putAll(m1);
- fail("Should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- m1 = new HashMap();
-
- m1.put(new Object(), "bar");
-
- try {
- m.putAll(m1);
- fail("Should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- m1 = new HashMap();
-
- m1.put("fubar", null);
-
- try {
- m.putAll(m1);
- fail("Should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- m1 = new HashMap();
-
- m1.put("fubar", new Object());
-
- try {
- m.putAll(m1);
- fail("Should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- assertEquals(nodes.length, m.size());
-
- m = new DoubleOrderedMap();
- m1 = new HashMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m1.put(nodes[k].getKey(), nodes[k].getValue());
- }
-
- m.putAll(m1);
- assertEquals(nodes.length, m.size());
-
- for (int k = 0; k < nodes.length; k++) {
- assertSame(nodes[k].getValue(), m.get(nodes[k].getKey()));
- }
- }
-
- /**
- * test clear() method
- */
- public void testClear() {
-
- Map m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k].getValue());
- assertTrue(!m.isEmpty());
- }
-
- assertTrue(!m.isEmpty());
-
- for (int k = 0; k < nodes.length; k++) {
- assertTrue(m.containsKey(nodes[k].getKey()));
- assertTrue(m.containsValue(nodes[k].getValue()));
- }
-
- m.clear();
- assertTrue(m.isEmpty());
-
- for (int k = 0; k < nodes.length; k++) {
- assertTrue(!m.containsKey(nodes[k].getKey()));
- assertTrue(!m.containsValue(nodes[k].getValue()));
- }
- }
-
- /**
- * test keySet() method
- */
- public void testKeySet() {
-
- testKeySet(new DoubleOrderedMap());
-
- Map m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- testKeySet(m);
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- int count = m.size();
-
- for (Iterator iter = m.keySet().iterator(); iter.hasNext(); ) {
- iter.next();
- iter.remove();
-
- --count;
-
- assertEquals(count, m.size());
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- Set s = m.keySet();
-
- try {
- s.remove(null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- try {
- s.remove(new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- for (int k = 0; k < nodes.length; k++) {
- Comparable key = nodes[k].getKey();
-
- assertTrue(s.remove(key));
- assertTrue(!s.contains(key));
- assertTrue(!m.containsKey(key));
- assertTrue(!m.containsValue(nodes[k]));
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- Collection c1 = new LinkedList();
- Collection c2 = new LinkedList();
-
- c2.add(new Integer(-99));
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k].getKey());
- c2.add(nodes[k].getKey());
- }
-
- assertTrue(m.keySet().containsAll(c1));
- assertTrue(!m.keySet().containsAll(c2));
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- c1.add(new Integer(-55));
-
- try {
- m.keySet().addAll(c1);
- fail("should have caught exception of addAll()");
- } catch (UnsupportedOperationException ignored) {}
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k].getKey());
- }
-
- assertTrue(!m.keySet().retainAll(c1));
- assertEquals(nodes.length, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
-
- if (k % 2 == 1) {
- c1.add(nodes[k].getKey());
- }
- }
-
- assertTrue(m.keySet().retainAll(c1));
- assertEquals(nodes.length / 2, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(m.keySet().retainAll(c1));
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(!m.keySet().removeAll(c1));
- assertEquals(nodes.length, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
-
- if (k % 2 == 0) {
- c1.add(nodes[k].getKey());
- }
- }
-
- assertTrue(m.keySet().removeAll(c1));
- assertEquals(nodes.length / 2, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k].getKey());
- }
-
- assertTrue(m.keySet().removeAll(c1));
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- m.keySet().clear();
- assertEquals(0, m.size());
- }
-
- /**
- * test values() method
- */
- public void testValues() {
-
- testValues(new DoubleOrderedMap());
-
- Map m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- testValues(m);
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- int count = m.size();
-
- for (Iterator iter = m.values().iterator(); iter.hasNext(); ) {
- iter.next();
- iter.remove();
-
- --count;
-
- assertEquals(count, m.size());
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- count = m.size();
-
- Collection s = m.values();
-
- for (int k = 0; k < count; k++) {
- assertTrue(s.remove(nodes[k]));
- assertTrue(!s.contains(nodes[k]));
- assertTrue(!m.containsKey(nodes[k].getKey()));
- assertTrue(!m.containsValue(nodes[k]));
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- Collection c1 = new LinkedList();
- Collection c2 = new LinkedList();
-
- c2.add(new LocalTestNode(-123));
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k]);
- c2.add(nodes[k]);
- }
-
- assertTrue(m.values().containsAll(c1));
- assertTrue(!m.values().containsAll(c2));
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k]);
- }
-
- try {
- m.values().addAll(c1);
- fail("should have caught exception of addAll()");
- } catch (UnsupportedOperationException ignored) {}
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k]);
- }
-
- assertTrue(!m.values().retainAll(c1));
- assertEquals(nodes.length, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
-
- if (k % 2 == 1) {
- c1.add(nodes[k]);
- }
- }
-
- assertTrue(m.values().retainAll(c1));
- assertEquals(nodes.length / 2, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(m.values().retainAll(c1));
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(!m.values().removeAll(c1));
- assertEquals(nodes.length, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
-
- if (k % 2 == 0) {
- c1.add(nodes[k]);
- }
- }
-
- assertTrue(m.values().removeAll(c1));
- assertEquals(nodes.length / 2, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k]);
- }
-
- assertTrue(m.values().removeAll(c1));
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- m.values().clear();
- assertEquals(0, m.size());
- }
-
- /**
- * test entrySet() method
- */
- public void testEntrySet() {
-
- testEntrySet(new DoubleOrderedMap());
-
- Map m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- testEntrySet(m);
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- try {
- ((Map.Entry) m.entrySet().iterator().next())
- .setValue(new LocalTestNode(-1));
- fail("Should have caught UnsupportedOperationException");
- } catch (UnsupportedOperationException ignored) {}
-
- int count = m.size();
-
- for (Iterator iter = m.entrySet().iterator(); iter.hasNext(); ) {
- iter.next();
- iter.remove();
-
- --count;
-
- assertEquals(count, m.size());
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- Collection c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k].getKey());
- }
-
- try {
- m.entrySet().addAll(c1);
- fail("should have caught exception of addAll()");
- } catch (UnsupportedOperationException ignored) {}
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- m.entrySet().clear();
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- int x = 0;
-
- for (Iterator iter = m.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
-
- assertSame(entry.getKey(), nodes[x].getKey());
- assertSame(entry.getValue(), nodes[x]);
-
- x++;
- }
- }
-
- /**
- * Method testEquals
- */
- public void testEquals() {
-
- Map m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(!m.equals(null));
- assertEquals(m, m);
-
- Map m1 = new HashMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m1.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertEquals(m, m1);
-
- m1 = new DoubleOrderedMap();
-
- for (int k = 0; k < (nodes.length - 1); k++) {
- m1.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(!m.equals(m1));
-
- m1 = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m1.put(nodes[k].getKey(), nodes[k]);
- }
-
- LocalTestNode node1 = new LocalTestNode(-1000);
-
- m1.put(node1.getKey(), node1);
- assertTrue(!m.equals(m1));
-
- m1 = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m1.put(nodes[k].getKey(), nodes[nodes.length - (k + 1)]);
- }
-
- assertTrue(!m.equals(m1));
-
- m1 = new DoubleOrderedMap();
-
- for (int k = nodes.length - 1; k >= 0; k--) {
- m1.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertEquals(m, m1);
- }
-
- /**
- * test hashCode() method
- */
- public void testHashCode() {
-
- Map m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- Map m1 = new DoubleOrderedMap();
-
- for (int k = nodes.length - 1; k >= 0; k--) {
- m1.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertEquals(m.hashCode(), m1.hashCode());
- }
-
- /**
- * test constructors
- */
- public void testConstructors() {
-
- DoubleOrderedMap m = new DoubleOrderedMap();
-
- assertTrue(m.isEmpty());
-
- DoubleOrderedMap m1 = new DoubleOrderedMap(m);
-
- assertTrue(m1.isEmpty());
-
- m1 = new DoubleOrderedMap();
-
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m1.put(nodes[k].getKey(), nodes[k]);
- }
-
- m = new DoubleOrderedMap(m1);
-
- assertEquals(m, m1);
-
- Map m2 = new HashMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m2.put(nodes[k].getKey(), nodes[k]);
- }
-
- m = new DoubleOrderedMap(m2);
-
- assertEquals(m, m2);
-
- // reject duplicated values
- m2 = new HashMap();
-
- m2.put("1", "foo");
- m2.put("2", "foo");
-
- try {
- m = new DoubleOrderedMap(m2);
-
- fail("Should have caught IllegalArgumentException");
- } catch (IllegalArgumentException ignored) {}
-
- // reject null values
- m2.put("2", null);
-
- try {
- m = new DoubleOrderedMap(m2);
-
- fail("Should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- // reject non-Comparable values
- m2.put("2", new Object());
-
- try {
- m = new DoubleOrderedMap(m2);
-
- fail("Should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- // reject incompatible values
- m2.put("2", new Integer(2));
-
- try {
- m = new DoubleOrderedMap(m2);
-
- fail("Should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- // reject incompatible keys
- m2.remove("2");
- m2.put(new Integer(2), "bad key");
-
- try {
- m = new DoubleOrderedMap(m2);
-
- fail("Should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- // reject non-Comparable keys
- m2.clear();
- m2.put("1", "foo");
- m2.put(new Object(), "bad key");
-
- try {
- m = new DoubleOrderedMap(m2);
-
- fail("Should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
- }
-
- /**
- * test getKeyForValue() method
- */
- public void testGetKeyForValue() {
-
- DoubleOrderedMap m = new DoubleOrderedMap();
-
- try {
- m.getKeyForValue(new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- try {
- m.getKeyForValue(null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- assertNull(m.getKeyForValue("foo"));
-
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- assertSame(m.getKeyForValue(nodes[k]), nodes[k].getKey());
- }
-
- assertNull(m.getKeyForValue(new LocalTestNode(-1)));
-
- try {
- m.getKeyForValue("foo");
- fail("Should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- for (int k = 0; k < nodes.length; k++) {
- assertNotNull(m.getKeyForValue(nodes[k]));
- m.remove(nodes[k].getKey());
- assertNull(m.getKeyForValue(nodes[k]));
- }
- }
-
- /**
- * test removeValue() method
- */
- public void testRemoveValue() {
-
- DoubleOrderedMap m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- try {
- m.removeValue(null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- try {
- m.removeValue(new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- assertNull(m.remove(new Integer(-1)));
-
- try {
- m.removeValue("foo");
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- for (int k = 0; k < nodes.length; k += 2) {
- assertNotNull(m.getKeyForValue(nodes[k]));
- assertSame(nodes[k].getKey(), m.removeValue(nodes[k]));
- assertNull(m.removeValue(nodes[k]));
- assertNull(m.getKeyForValue(nodes[k]));
- }
-
- for (int k = 1; k < nodes.length; k += 2) {
- assertNotNull(m.getKeyForValue(nodes[k]));
- assertSame(nodes[k].getKey(), m.removeValue(nodes[k]));
- assertNull(m.removeValue(nodes[k]));
- assertNull(m.getKeyForValue(nodes[k]));
- }
-
- assertTrue(m.isEmpty());
- }
-
- /**
- * test entrySetByValue() method
- */
- public void testEntrySetByValue() {
-
- testEntrySetByValue(new DoubleOrderedMap());
-
- DoubleOrderedMap m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- testEntrySetByValue(m);
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- try {
- ((Map.Entry) m.entrySetByValue().iterator().next())
- .setValue(new LocalTestNode(-1));
- fail("Should have caught UnsupportedOperationException");
- } catch (UnsupportedOperationException ignored) {}
-
- int count = m.size();
-
- for (Iterator iter = m.entrySetByValue().iterator();
- iter.hasNext(); ) {
- iter.next();
- iter.remove();
-
- --count;
-
- assertEquals(count, m.size());
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- Collection c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k].getKey());
- }
-
- try {
- m.entrySetByValue().addAll(c1);
- fail("should have caught exception of addAll()");
- } catch (UnsupportedOperationException ignored) {}
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- m.entrySetByValue().clear();
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- int x = 0;
-
- for (Iterator iter = m.entrySetByValue().iterator();
- iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
-
- assertSame(entry.getKey(), nodes[x].getKey());
- assertSame(entry.getValue(), nodes[x]);
-
- x++;
- }
- }
-
- /**
- * test keySetByValue() method
- */
- public void testKeySetByValue() {
-
- testKeySetByValue(new DoubleOrderedMap());
-
- DoubleOrderedMap m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- testKeySetByValue(m);
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- int count = m.size();
-
- for (Iterator iter = m.keySetByValue().iterator(); iter.hasNext(); )
-{
- iter.next();
- iter.remove();
-
- --count;
-
- assertEquals(count, m.size());
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- Set s = m.keySetByValue();
-
- try {
- s.remove(null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- try {
- s.remove(new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- for (int k = 0; k < nodes.length; k++) {
- Comparable key = nodes[k].getKey();
-
- assertTrue(s.remove(key));
- assertTrue(!s.contains(key));
- assertTrue(!m.containsKey(key));
- assertTrue(!m.containsValue(nodes[k]));
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- Collection c1 = new LinkedList();
- Collection c2 = new LinkedList();
-
- c2.add(new Integer(-99));
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k].getKey());
- c2.add(nodes[k].getKey());
- }
-
- assertTrue(m.keySetByValue().containsAll(c1));
- assertTrue(!m.keySetByValue().containsAll(c2));
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- c1.add(new Integer(-55));
-
- try {
- m.keySetByValue().addAll(c1);
- fail("should have caught exception of addAll()");
- } catch (UnsupportedOperationException ignored) {}
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k].getKey());
- }
-
- assertTrue(!m.keySetByValue().retainAll(c1));
- assertEquals(nodes.length, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
-
- if (k % 2 == 1) {
- c1.add(nodes[k].getKey());
- }
- }
-
- assertTrue(m.keySetByValue().retainAll(c1));
- assertEquals(nodes.length / 2, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(m.keySetByValue().retainAll(c1));
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(!m.keySetByValue().removeAll(c1));
- assertEquals(nodes.length, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
-
- if (k % 2 == 0) {
- c1.add(nodes[k].getKey());
- }
- }
-
- assertTrue(m.keySetByValue().removeAll(c1));
- assertEquals(nodes.length / 2, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k].getKey());
- }
-
- assertTrue(m.keySetByValue().removeAll(c1));
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- m.keySetByValue().clear();
- assertEquals(0, m.size());
- }
-
- /**
- * test valuesByValue() method
- */
- public void testValuesByValue() {
-
- testValuesByValue(new DoubleOrderedMap());
-
- DoubleOrderedMap m = new DoubleOrderedMap();
- LocalTestNode nodes[] = makeLocalNodes();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- testValuesByValue(m);
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- int count = m.size();
-
- for (Iterator iter = m.valuesByValue().iterator(); iter.hasNext(); )
-{
- iter.next();
- iter.remove();
-
- --count;
-
- assertEquals(count, m.size());
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- count = m.size();
-
- Collection s = m.valuesByValue();
-
- for (int k = 0; k < count; k++) {
- assertTrue(s.remove(nodes[k]));
- assertTrue(!s.contains(nodes[k]));
- assertTrue(!m.containsKey(nodes[k].getKey()));
- assertTrue(!m.containsValue(nodes[k]));
- }
-
- assertTrue(m.isEmpty());
-
- m = new DoubleOrderedMap();
-
- Collection c1 = new LinkedList();
- Collection c2 = new LinkedList();
-
- c2.add(new LocalTestNode(-123));
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k]);
- c2.add(nodes[k]);
- }
-
- assertTrue(m.valuesByValue().containsAll(c1));
- assertTrue(!m.valuesByValue().containsAll(c2));
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k]);
- }
-
- try {
- m.valuesByValue().addAll(c1);
- fail("should have caught exception of addAll()");
- } catch (UnsupportedOperationException ignored) {}
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k]);
- }
-
- assertTrue(!m.valuesByValue().retainAll(c1));
- assertEquals(nodes.length, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
-
- if (k % 2 == 1) {
- c1.add(nodes[k]);
- }
- }
-
- assertTrue(m.valuesByValue().retainAll(c1));
- assertEquals(nodes.length / 2, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(m.valuesByValue().retainAll(c1));
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- assertTrue(!m.valuesByValue().removeAll(c1));
- assertEquals(nodes.length, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
-
- if (k % 2 == 0) {
- c1.add(nodes[k]);
- }
- }
-
- assertTrue(m.valuesByValue().removeAll(c1));
- assertEquals(nodes.length / 2, m.size());
-
- m = new DoubleOrderedMap();
- c1 = new LinkedList();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- c1.add(nodes[k]);
- }
-
- assertTrue(m.valuesByValue().removeAll(c1));
- assertEquals(0, m.size());
-
- m = new DoubleOrderedMap();
-
- for (int k = 0; k < nodes.length; k++) {
- m.put(nodes[k].getKey(), nodes[k]);
- }
-
- m.valuesByValue().clear();
- assertEquals(0, m.size());
- }
-
- /* ********** START helper methods ********** */
- private void testKeySet(final Map m) {
-
- Set s = m.keySet();
-
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- LocalTestNode node = new LocalTestNode(-1);
-
- m.put(node.getKey(), node);
- assertTrue(s.contains(node.getKey()));
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
- m.remove(node.getKey());
- assertTrue(!s.contains(node.getKey()));
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- try {
- s.contains(null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- try {
- s.contains(new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- for (int k = 0; k < m.size(); k++) {
- assertTrue(s.contains(new Integer(k)));
- }
-
- int count = 0;
-
- for (Iterator iter = s.iterator(); iter.hasNext(); ) {
- iter.next();
-
- ++count;
- }
-
- assertEquals(count, s.size());
-
- // force the map to have some content
- m.put(node.getKey(), node);
-
- Iterator iter = m.keySet().iterator();
- LocalTestNode node2 = new LocalTestNode(-2);
-
- m.put(node2.getKey(), node2);
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a put");
- } catch (ConcurrentModificationException ignored) {}
-
- m.remove(node2.getKey());
-
- iter = s.iterator();
-
- m.remove(node.getKey());
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Map remove");
- } catch (ConcurrentModificationException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
-
- s.remove(node.getKey());
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Set remove");
- } catch (ConcurrentModificationException ignored) {}
-
- iter = s.iterator();
- count = 0;
-
- boolean terminated = false;
-
- try {
- while (true) {
- iter.next();
-
- ++count;
- }
- } catch (NoSuchElementException ignored) {
- terminated = true;
- }
-
- assertTrue(terminated);
- assertEquals(m.size(), count);
-
- iter = s.iterator();
-
- try {
- iter.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
-
- iter.next();
- m.put(node2.getKey(), node2);
-
- try {
- iter.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- Iterator iter2 = s.iterator();
-
- iter2.next();
-
- LocalTestNode node3 = new LocalTestNode(-3);
-
- m.put(node3.getKey(), node3);
-
- try {
- iter2.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- int removalCount = 0;
-
- for (iter = s.iterator(); iter.hasNext(); ) {
- if (iter.next().equals(node.getKey())) {
- try {
- iter.remove();
-
- ++removalCount;
-
- iter.remove();
- fail("2nd remove should have failed");
- } catch (IllegalStateException ignored) {
- assertEquals(1, removalCount);
- }
- }
- }
-
- assertEquals(1, removalCount);
- assertTrue(!s.contains(node.getKey()));
-
- removalCount = 0;
-
- m.put(node.getKey(), node);
-
- Object[] a1 = s.toArray();
-
- assertEquals(s.size(), a1.length);
-
- if (a1.length > 1) {
- Comparable first = (Comparable) a1[0];
-
- for (int k = 1; k < a1.length; k++) {
- Comparable second = (Comparable) a1[k];
-
- assertTrue(first.compareTo(second) < 0);
-
- first = second;
- }
-
- iter = s.iterator();
- first = (Comparable) iter.next();
-
- for (; iter.hasNext(); ) {
- Comparable second = (Comparable) iter.next();
-
- assertTrue(first.compareTo(second) < 0);
-
- first = second;
- }
- }
-
- try {
- String array2[] = (String[]) s.toArray(new String[0]);
-
- if (s.size() != 0) {
- fail("should have caught exception creating an invalid array");
- }
- } catch (ArrayStoreException ignored) {}
-
- Comparable array2[] = (Comparable[]) s.toArray(new Comparable[0]);
- Integer array3[] = (Integer[]) s.toArray(new Integer[s.size()]);
-
- if (array3.length > 1) {
- Integer first = array3[0];
-
- for (int k = 1; k < array3.length; k++) {
- Integer second = array3[k];
-
- assertTrue(first.compareTo(second) < 0);
-
- first = second;
- }
- }
-
- try {
- s.add("foo");
- fail("should have thrown an exception");
- } catch (UnsupportedOperationException ignored) {}
-
- assertTrue(!s.equals(null));
- assertEquals(s, s);
-
- Set hs = new HashSet(s);
-
- assertEquals(s, hs);
- assertEquals(hs, s);
- assertEquals(s.hashCode(), hs.hashCode());
- }
-
- private void testKeySetByValue(final DoubleOrderedMap m) {
-
- Set s = m.keySetByValue();
-
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- LocalTestNode node = new LocalTestNode(-1);
-
- m.put(node.getKey(), node);
- assertTrue(s.contains(node.getKey()));
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
- m.remove(node.getKey());
- assertTrue(!s.contains(node.getKey()));
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- try {
- s.contains(null);
- fail("should have caught NullPointerException");
- } catch (NullPointerException ignored) {}
-
- try {
- s.contains(new Object());
- fail("should have caught ClassCastException");
- } catch (ClassCastException ignored) {}
-
- for (int k = 0; k < m.size(); k++) {
- assertTrue(s.contains(new Integer(k)));
- }
-
- int count = 0;
-
- for (Iterator iter = s.iterator(); iter.hasNext(); ) {
- iter.next();
-
- ++count;
- }
-
- assertEquals(count, s.size());
-
- // force the map to have some content
- m.put(node.getKey(), node);
-
- Iterator iter = m.keySetByValue().iterator();
- LocalTestNode node2 = new LocalTestNode(-2);
-
- m.put(node2.getKey(), node2);
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a put");
- } catch (ConcurrentModificationException ignored) {}
-
- m.remove(node2.getKey());
-
- iter = s.iterator();
-
- m.remove(node.getKey());
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Map remove");
- } catch (ConcurrentModificationException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
-
- s.remove(node.getKey());
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Set remove");
- } catch (ConcurrentModificationException ignored) {}
-
- iter = s.iterator();
- count = 0;
-
- boolean terminated = false;
-
- try {
- while (true) {
- iter.next();
-
- ++count;
- }
- } catch (NoSuchElementException ignored) {
- terminated = true;
- }
-
- assertTrue(terminated);
- assertEquals(m.size(), count);
-
- iter = s.iterator();
-
- try {
- iter.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
-
- iter.next();
- m.put(node2.getKey(), node2);
-
- try {
- iter.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- Iterator iter2 = s.iterator();
-
- iter2.next();
-
- LocalTestNode node3 = new LocalTestNode(-3);
-
- m.put(node3.getKey(), node3);
-
- try {
- iter2.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- int removalCount = 0;
-
- for (iter = s.iterator(); iter.hasNext(); ) {
- if (iter.next().equals(node.getKey())) {
- try {
- iter.remove();
-
- ++removalCount;
-
- iter.remove();
- fail("2nd remove should have failed");
- } catch (IllegalStateException ignored) {
- assertEquals(1, removalCount);
- }
- }
- }
-
- assertEquals(1, removalCount);
- assertTrue(!s.contains(node.getKey()));
-
- removalCount = 0;
-
- m.put(node.getKey(), node);
-
- Object[] a1 = s.toArray();
-
- assertEquals(s.size(), a1.length);
-
- // if (a1.length > 1)
- // {
- // Comparable first = ( Comparable ) a1[ 0 ];
- // for (int k = 1; k < a1.length; k++)
- // {
- // Comparable second = ( Comparable ) a1[ k ];
- // assertTrue(first.compareTo(second) < 0);
- // first = second;
- // }
- // iter = s.iterator();
- // first = ( Comparable ) iter.next();
- // for (; iter.hasNext(); )
- // {
- // Comparable second = ( Comparable ) iter.next();
- // assertTrue(first.compareTo(second) < 0);
- // first = second;
- // }
- // }
- try {
- String array2[] = (String[]) s.toArray(new String[0]);
-
- if (s.size() != 0) {
- fail("should have caught exception creating an invalid array");
- }
- } catch (ArrayStoreException ignored) {}
-
- Comparable array2[] = (Comparable[]) s.toArray(new Comparable[0]);
- Integer array3[] = (Integer[]) s.toArray(new Integer[s.size()]);
-
- // if (array3.length > 1)
- // {
- // Integer first = array3[ 0 ];
- // for (int k = 1; k < array3.length; k++)
- // {
- // Integer second = array3[ k ];
- // assertTrue(first.compareTo(second) < 0);
- // first = second;
- // }
- // }
- try {
- s.add("foo");
- fail("should have thrown an exception");
- } catch (UnsupportedOperationException ignored) {}
-
- assertTrue(!s.equals(null));
- assertEquals(s, s);
-
- Set hs = new HashSet(s);
-
- assertEquals(s, hs);
- assertEquals(hs, s);
- assertEquals(s.hashCode(), hs.hashCode());
- }
-
- private void testValues(Map m) {
-
- Collection s = m.values();
-
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- LocalTestNode node = new LocalTestNode(-1);
-
- m.put(node.getKey(), node);
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
- m.remove(node.getKey());
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
- assertTrue(!s.contains(node));
-
- for (int k = 0; k < m.size(); k++) {
- assertTrue(s.contains(new LocalTestNode(k)));
- }
-
- m.put(node.getKey(), node);
- assertTrue(s.contains(node));
- m.remove(node.getKey());
- assertTrue(!s.contains(node));
-
- int count = 0;
-
- for (Iterator iter = s.iterator(); iter.hasNext(); ) {
- iter.next();
-
- ++count;
- }
-
- assertEquals(s.size(), count);
-
- LocalTestNode node4 = new LocalTestNode(-4);
-
- m.put(node4.getKey(), node4);
-
- Iterator iter = s.iterator();
-
- m.put(node.getKey(), node);
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a put");
- } catch (ConcurrentModificationException ignored) {}
-
- iter = s.iterator();
-
- m.remove(node.getKey());
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Map remove");
- } catch (ConcurrentModificationException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
-
- s.remove(node);
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Set remove");
- } catch (ConcurrentModificationException ignored) {}
-
- iter = s.iterator();
- count = 0;
-
- boolean terminated = false;
-
- try {
- while (true) {
- iter.next();
-
- ++count;
- }
- } catch (NoSuchElementException ignored) {
- terminated = true;
- }
-
- assertTrue(terminated);
- assertEquals(m.size(), count);
-
- iter = s.iterator();
-
- try {
- iter.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- Iterator iter2 = s.iterator();
-
- try {
- iter2.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
-
- iter.next();
-
- LocalTestNode node2 = new LocalTestNode(-2);
-
- m.put(node2.getKey(), node2);
-
- try {
- iter.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- LocalTestNode node3 = new LocalTestNode(-3);
-
- m.put(node3.getKey(), node3);
-
- iter2 = s.iterator();
-
- while (iter2.hasNext()) {
- iter2.next();
- }
-
- int removalCount = 0;
-
- for (iter = s.iterator(); iter.hasNext(); ) {
- if (iter.next().equals(node3)) {
- try {
- iter.remove();
-
- ++removalCount;
-
- iter.remove();
- fail("2nd remove should have failed");
- } catch (IllegalStateException ignored) {
- assertEquals(1, removalCount);
- }
- }
- }
-
- assertEquals(1, removalCount);
- assertTrue(!s.contains(node3));
-
- Object[] a1 = s.toArray();
-
- assertEquals(s.size(), a1.length);
-
- if (a1.length > 1) {
- Comparable first = (Comparable) a1[0];
-
- for (int k = 1; k < a1.length; k++) {
- Comparable second = (Comparable) a1[k];
-
- assertTrue(first.compareTo(second) < 0);
-
- first = second;
- }
-
- iter = s.iterator();
- first = (Comparable) iter.next();
-
- for (; iter.hasNext(); ) {
- Comparable second = (Comparable) iter.next();
-
- assertTrue(first.compareTo(second) < 0);
-
- first = second;
- }
- }
-
- try {
- String array2[] = (String[]) s.toArray(new String[0]);
-
- if (s.size() != 0) {
- fail("should have caught exception creating an invalid array");
- }
- } catch (ArrayStoreException ignored) {}
-
- m.remove(node.getKey());
- m.remove(node2.getKey());
- m.remove(node3.getKey());
-
- LocalTestNode array2[] =
- (LocalTestNode[]) s.toArray(new LocalTestNode[0]);
- LocalTestNode array3[] =
- (LocalTestNode[]) s.toArray(new LocalTestNode[s.size()]);
-
- if (array3.length > 1) {
- LocalTestNode first = array3[0];
-
- for (int k = 1; k < array3.length; k++) {
- LocalTestNode second = array3[k];
-
- assertTrue(first.compareTo(second) < 0);
-
- first = second;
- }
- }
-
- try {
- s.add(node.getKey());
- fail("should have thrown an exception");
- } catch (UnsupportedOperationException ignored) {}
-
- assertTrue(!s.equals(null));
- assertEquals(s, s);
-
- Set hs = new HashSet(s);
-
- assertTrue(!s.equals(hs));
- assertTrue(!hs.equals(s));
- }
-
- private void testValuesByValue(DoubleOrderedMap m) {
-
- Collection s = m.valuesByValue();
-
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- LocalTestNode node = new LocalTestNode(-1);
-
- m.put(node.getKey(), node);
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
- m.remove(node.getKey());
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
- assertTrue(!s.contains(node));
-
- for (int k = 0; k < m.size(); k++) {
- assertTrue(s.contains(new LocalTestNode(k)));
- }
-
- m.put(node.getKey(), node);
- assertTrue(s.contains(node));
- m.remove(node.getKey());
- assertTrue(!s.contains(node));
-
- int count = 0;
-
- for (Iterator iter = s.iterator(); iter.hasNext(); ) {
- iter.next();
-
- ++count;
- }
-
- assertEquals(s.size(), count);
-
- LocalTestNode node4 = new LocalTestNode(-4);
-
- m.put(node4.getKey(), node4);
-
- Iterator iter = s.iterator();
-
- m.put(node.getKey(), node);
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a put");
- } catch (ConcurrentModificationException ignored) {}
-
- iter = s.iterator();
-
- m.remove(node.getKey());
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Map remove");
- } catch (ConcurrentModificationException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
-
- s.remove(node);
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Set remove");
- } catch (ConcurrentModificationException ignored) {}
-
- iter = s.iterator();
- count = 0;
-
- boolean terminated = false;
-
- try {
- while (true) {
- iter.next();
-
- ++count;
- }
- } catch (NoSuchElementException ignored) {
- terminated = true;
- }
-
- assertTrue(terminated);
- assertEquals(m.size(), count);
-
- iter = s.iterator();
-
- try {
- iter.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- Iterator iter2 = s.iterator();
-
- try {
- iter2.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
-
- iter.next();
-
- LocalTestNode node2 = new LocalTestNode(-2);
-
- m.put(node2.getKey(), node2);
-
- try {
- iter.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- LocalTestNode node3 = new LocalTestNode(-3);
-
- m.put(node3.getKey(), node3);
-
- iter2 = s.iterator();
-
- while (iter2.hasNext()) {
- iter2.next();
- }
-
- int removalCount = 0;
-
- for (iter = s.iterator(); iter.hasNext(); ) {
- if (iter.next().equals(node3)) {
- try {
- iter.remove();
-
- ++removalCount;
-
- iter.remove();
- fail("2nd remove should have failed");
- } catch (IllegalStateException ignored) {
- assertEquals(1, removalCount);
- }
- }
- }
-
- assertEquals(1, removalCount);
- assertTrue(!s.contains(node3));
-
- Object[] a1 = s.toArray();
-
- assertEquals(s.size(), a1.length);
-
- try {
- String array2[] = (String[]) s.toArray(new String[0]);
-
- if (s.size() != 0) {
- fail("should have caught exception creating an invalid array");
- }
- } catch (ArrayStoreException ignored) {}
-
- m.remove(node.getKey());
- m.remove(node2.getKey());
- m.remove(node3.getKey());
-
- LocalTestNode array2[] =
- (LocalTestNode[]) s.toArray(new LocalTestNode[0]);
- LocalTestNode array3[] =
- (LocalTestNode[]) s.toArray(new LocalTestNode[s.size()]);
-
- try {
- s.add(node.getKey());
- fail("should have thrown an exception");
- } catch (UnsupportedOperationException ignored) {}
-
- assertTrue(!s.equals(null));
- assertEquals(s, s);
-
- Set hs = new HashSet(s);
-
- assertTrue(!s.equals(hs));
- assertTrue(!hs.equals(s));
- }
-
- private void testEntrySet(Map m) {
-
- Set s = m.entrySet();
-
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- LocalTestNode node = new LocalTestNode(-1);
-
- m.put(node.getKey(), node);
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
- m.remove(node.getKey());
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- int count = 0;
-
- for (Iterator iter = s.iterator(); iter.hasNext(); ) {
- iter.next();
-
- ++count;
- }
-
- assertEquals(s.size(), count);
-
- LocalTestNode node2 = new LocalTestNode(-2);
-
- if (m.size() == 0) {
- m.put(node2.getKey(), node2);
- }
-
- Iterator iter = s.iterator();
-
- m.put(node.getKey(), node);
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a put");
- } catch (ConcurrentModificationException ignored) {}
-
- m.remove(node2.getKey());
-
- iter = s.iterator();
-
- m.remove(node.getKey());
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Map remove");
- } catch (ConcurrentModificationException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
- count = 0;
-
- boolean terminated = false;
-
- try {
- while (true) {
- iter.next();
-
- ++count;
- }
- } catch (NoSuchElementException ignored) {
- terminated = true;
- }
-
- assertTrue(terminated);
- assertEquals(m.size(), count);
-
- iter = s.iterator();
-
- try {
- iter.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- iter = s.iterator();
-
- iter.next();
-
- LocalTestNode node3 = new LocalTestNode(-3);
-
- m.put(node3.getKey(), node3);
-
- try {
- iter.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- int removalCount = 0;
- int when = m.size() / 2;
- int timer = 0;
-
- for (iter = s.iterator(); iter.hasNext(); ) {
- iter.next();
-
- if (timer == when) {
- try {
- iter.remove();
-
- ++removalCount;
-
- iter.remove();
- fail("2nd remove should have failed");
- } catch (IllegalStateException ignored) {
- assertEquals(1, removalCount);
- }
- }
-
- timer++;
- }
-
- assertEquals(1, removalCount);
-
- Iterator iter2 = s.iterator();
-
- try {
- iter2.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- iter2 = s.iterator();
-
- while (iter2.hasNext()) {
- iter2.next();
- }
-
- LocalTestNode node4 = new LocalTestNode(-4);
-
- m.put(node4.getKey(), node4);
-
- try {
- iter2.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- Object[] a1 = s.toArray();
-
- assertEquals(s.size(), a1.length);
-
- if (a1.length > 1) {
- Map.Entry first = (Map.Entry) a1[0];
-
- for (int k = 1; k < a1.length; k++) {
- Map.Entry second = (Map.Entry) a1[k];
-
- assertTrue(((Comparable) first.getKey())
- .compareTo((Comparable) second.getKey()) < 0);
-
- first = second;
- }
-
- iter = s.iterator();
- first = (Map.Entry) iter.next();
-
- for (; iter.hasNext(); ) {
- Map.Entry second = (Map.Entry) iter.next();
-
- assertTrue(((Comparable) first.getKey())
- .compareTo((Comparable) second.getKey()) < 0);
-
- first = second;
- }
- }
-
- try {
- Integer array2[] = (Integer[]) s.toArray(new Integer[0]);
-
- if (s.size() != 0) {
- fail("should have caught exception creating an invalid array");
- }
- } catch (ArrayStoreException ignored) {}
-
- Map.Entry array2[] = (Map.Entry[]) s.toArray(new Map.Entry[0]);
- Map.Entry array3[] = (Map.Entry[]) s.toArray(new Map.Entry[s.size()]);
-
- if (array3.length > 1) {
- Comparable first = (Comparable) ((Map.Entry) array3[0]).getKey();
-
- for (int k = 1; k < array3.length; k++) {
- Comparable second =
- (Comparable) ((Map.Entry) array3[k]).getKey();
-
- assertTrue(first.compareTo(second) < 0);
-
- first = second;
- }
- }
-
- try {
- s.add(node.getKey());
- fail("should have thrown an exception");
- } catch (UnsupportedOperationException ignored) {}
-
- assertTrue(!s.equals(null));
- assertEquals("SetEquality 1", s, s);
-
- Set hs = new HashSet(s);
-
- assertEquals("SetEquality 2", s, hs);
- assertEquals("SetEquality 3", hs, s);
- assertEquals(s.hashCode(), hs.hashCode());
- }
-
- private void testEntrySetByValue(DoubleOrderedMap m) {
-
- Set s = m.entrySetByValue();
-
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- LocalTestNode node = new LocalTestNode(-1);
-
- m.put(node.getKey(), node);
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
- m.remove(node.getKey());
- assertEquals(m.size(), s.size());
- assertEquals(m.isEmpty(), s.isEmpty());
-
- int count = 0;
-
- for (Iterator iter = s.iterator(); iter.hasNext(); ) {
- iter.next();
-
- ++count;
- }
-
- assertEquals(s.size(), count);
-
- LocalTestNode node2 = new LocalTestNode(-2);
-
- if (m.size() == 0) {
- m.put(node2.getKey(), node2);
- }
-
- Iterator iter = s.iterator();
-
- m.put(node.getKey(), node);
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a put");
- } catch (ConcurrentModificationException ignored) {}
-
- m.remove(node2.getKey());
-
- iter = s.iterator();
-
- m.remove(node.getKey());
-
- try {
- iter.next();
- fail("next() should have thrown an exception after a Map remove");
- } catch (ConcurrentModificationException ignored) {}
-
- m.put(node.getKey(), node);
-
- iter = s.iterator();
- count = 0;
-
- boolean terminated = false;
-
- try {
- while (true) {
- iter.next();
-
- ++count;
- }
- } catch (NoSuchElementException ignored) {
- terminated = true;
- }
-
- assertTrue(terminated);
- assertEquals(m.size(), count);
-
- iter = s.iterator();
-
- try {
- iter.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- iter = s.iterator();
-
- iter.next();
-
- LocalTestNode node3 = new LocalTestNode(-3);
-
- m.put(node3.getKey(), node3);
-
- try {
- iter.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- int removalCount = 0;
- int when = m.size() / 2;
- int timer = 0;
-
- for (iter = s.iterator(); iter.hasNext(); ) {
- iter.next();
-
- if (timer == when) {
- try {
- iter.remove();
-
- ++removalCount;
-
- iter.remove();
- fail("2nd remove should have failed");
- } catch (IllegalStateException ignored) {
- assertEquals(1, removalCount);
- }
- }
-
- timer++;
- }
-
- assertEquals(1, removalCount);
-
- Iterator iter2 = s.iterator();
-
- try {
- iter2.remove();
- fail("Should have thrown exception");
- } catch (IllegalStateException ignored) {}
-
- iter2 = s.iterator();
-
- while (iter2.hasNext()) {
- iter2.next();
- }
-
- LocalTestNode node4 = new LocalTestNode(-4);
-
- m.put(node4.getKey(), node4);
-
- try {
- iter2.remove();
- fail("should have thrown exception");
- } catch (ConcurrentModificationException ignored) {}
-
- Object[] a1 = s.toArray();
-
- assertEquals(s.size(), a1.length);
-
- if (a1.length > 1) {
- Map.Entry first = (Map.Entry) a1[0];
-
- for (int k = 1; k < a1.length; k++) {
- Map.Entry second = (Map.Entry) a1[k];
-
- assertTrue(((Comparable) first.getKey())
- .compareTo((Comparable) second.getKey()) < 0);
-
- first = second;
- }
-
- iter = s.iterator();
- first = (Map.Entry) iter.next();
-
- for (; iter.hasNext(); ) {
- Map.Entry second = (Map.Entry) iter.next();
-
- assertTrue(((Comparable) first.getKey())
- .compareTo((Comparable) second.getKey()) < 0);
-
- first = second;
- }
- }
-
- try {
- Integer array2[] = (Integer[]) s.toArray(new Integer[0]);
-
- if (s.size() != 0) {
- fail("should have caught exception creating an invalid array");
- }
- } catch (ArrayStoreException ignored) {}
-
- Map.Entry array2[] = (Map.Entry[]) s.toArray(new Map.Entry[0]);
- Map.Entry array3[] = (Map.Entry[]) s.toArray(new Map.Entry[s.size()]);
-
- if (array3.length > 1) {
- Comparable first =
- (Comparable) ((Map.Entry) array3[0]).getValue();
-
- for (int k = 1; k < array3.length; k++) {
- Comparable second =
- (Comparable) ((Map.Entry) array3[k]).getValue();
-
- assertTrue(first.compareTo(second) < 0);
-
- first = second;
- }
- }
-
- try {
- s.add(node.getKey());
- fail("should have thrown an exception");
- } catch (UnsupportedOperationException ignored) {}
-
- assertTrue(!s.equals(null));
- assertEquals("SetEquality 1", s, s);
-
- Set hs = new HashSet(s);
-
- assertEquals("SetEquality 2", s, hs);
- assertEquals("SetEquality 3", hs, s);
- assertEquals(s.hashCode(), hs.hashCode());
- }
-
- private LocalTestNode[] makeLocalNodes() {
-
- LocalTestNode nodes[] = new LocalTestNode[1023];
-
- for (int k = 0; k < nodes.length; k++) {
- nodes[k] = new LocalTestNode(k);
- }
-
- return nodes;
- }
-
- /* ********** END helper methods ********** */
-
- /**
- * Method main
- *
- * @param unusedArgs
- */
- public static void main(final String unusedArgs[]) {
- junit.textui.TestRunner.run(TestDoubleOrderedMap.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/test/org/apache/commons/collections/TestHashBag.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestHashBag.java b/src/test/org/apache/commons/collections/TestHashBag.java
deleted file mode 100644
index 403d1a7..0000000
--- a/src/test/org/apache/commons/collections/TestHashBag.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestHashBag.java,v 1.1 2001/08/29 15:28:07 jstrachan Exp $
- * $Revision: 1.1 $
- * $Date: 2001/08/29 15:28:07 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import junit.framework.*;
-
-/**
- * Extension of {@link TestBag} for exercising the {@link HashBag}
- * implementation.
- *
- * @author Chuck Burdick
- * @version $Id: TestHashBag.java,v 1.1 2001/08/29 15:28:07 jstrachan Exp $ */
-public class TestHashBag extends TestBag {
- public TestHashBag(String testName) {
- super(testName);
- }
-
- public static Test suite() {
- return new TestSuite(TestHashBag.class);
- }
-
- public static void main(String args[]) {
- String[] testCaseName = { TestHashBag.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- public Bag makeBag() {
- return new HashBag();
- }
-}
-
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/03ef3163/src/test/org/apache/commons/collections/TestMultiHashMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestMultiHashMap.java b/src/test/org/apache/commons/collections/TestMultiHashMap.java
deleted file mode 100644
index bc7ed85..0000000
--- a/src/test/org/apache/commons/collections/TestMultiHashMap.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestMultiHashMap.java,v 1.1.2.1 2002/02/26 00:51:21 morgand Exp $
- * $Revision: 1.1.2.1 $
- * $Date: 2002/02/26 00:51:21 $
- *
- * ====================================================================
- *
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 1999-2001 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 acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements 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 Group.
- *
- * 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;
-
-import java.util.*;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-
-/**
- * Unit Tests for <code>MultiHashMap</code>.
- *
- */
-public class TestMultiHashMap extends TestMap
-{
- public TestMultiHashMap(String testName)
- {
- super(testName);
- }
-
- public static Test suite()
- {
- return new TestSuite(TestMultiHashMap.class);
- }
-
- public static void main(String args[])
- {
- String[] testCaseName = { TestMultiHashMap.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- public Map makeEmptyMap() {
- return new MultiHashMap();
- }
-
- //----------------------------
- // Tests
- //----------------------------
- public void testPutNGet()
- {
- MultiHashMap map = new MultiHashMap();
- loadMap( map );
- checkMap( map );
-
- assertTrue( map.get(new Integer(99)) == null );
-
- map.clear();
- assertTrue( map.size() == 0 );
- }
-
- public void testContainsValue()
- {
- MultiHashMap map = new MultiHashMap();
- loadMap( map );
-
- assertTrue( map.containsValue( "uno" ) );
- assertTrue( map.containsValue( "quatro" ) );
- assertTrue( map.containsValue( "two" ) );
-
- assertTrue( ! map.containsValue( "uggaBugga" ) );
-
- map.clear();
- }
-
- public void testValues()
- {
- MultiHashMap map = new MultiHashMap();
- loadMap( map );
-
- Collection vals = map.values();
- assertTrue( vals.size() == getFullSize() );
-
- map.clear();
- }
-
-
- static private class MapPair
- {
- MapPair( int key, String val )
- {
- mKey = new Integer( key );
- mValue = val;
- }
-
- Integer mKey = null;
- String mValue = null;
- }
-
- static private MapPair[][] sMapPairs =
- {
- {new MapPair(0,"zero")},
- {new MapPair(1,"one"), new MapPair(1,"ONE"), new MapPair(1,"uno")},
- {new MapPair(2,"two"), new MapPair(2,"two") },
- {new MapPair(3,"three"), new MapPair(3,"THREE"), new MapPair(3,"tres")},
- {new MapPair(4,"four"), new MapPair(4,"quatro")}
- };
-
- private void loadMap( MultiHashMap map )
- {
- // Set up so that we load the keys "randomly"
- // (i.e. we don't want to load int row-order, so that all like keys
- // load together. We want to mix it up...)
-
- int numRows = sMapPairs.length;
- int maxCols = 0;
- for( int ii=0; ii < sMapPairs.length; ii++ ){
- if ( sMapPairs[ii].length > maxCols )
- maxCols = sMapPairs[ii].length;
- }
- for( int ii=0; ii < maxCols; ii++ ){
- for( int jj=0; jj < numRows; jj++ ){
- if ( ii < sMapPairs[jj].length ) {
- map.put( sMapPairs[jj][ii].mKey, sMapPairs[jj][ii].mValue);
- //---------------------------------------------------------
- }
- }
- }
- assertTrue( map.size() == sMapPairs.length );
- }
-
- private void checkMap( MultiHashMap map )
- {
- for( int ii=0; ii < sMapPairs.length; ii++ ){
- checkKeyList( map, ii );
- }
- }
-
- private void checkKeyList( MultiHashMap map, int index )
- {
- assertTrue( index < sMapPairs.length );
- Integer key = sMapPairs[index][0].mKey ;
-
- Object obj = map.get( key );
- //--------------------------
-
- assertTrue( obj != null );
- assertTrue( obj instanceof Collection );
- Collection keyList = (Collection)obj;
-
- assertTrue( keyList.size() == sMapPairs[index].length );
- Iterator iter = keyList.iterator();
- while ( iter.hasNext() ) {
- Object oval = iter.next();
- assertTrue( oval != null );
- assertTrue( oval instanceof String );
- String val = (String)oval;
- boolean foundIt = false;
- for( int ii=0; ii < sMapPairs[index].length; ii++ ){
- if( val.equals( sMapPairs[index][ii].mValue ) )
- foundIt = true;
- }
- assertTrue( foundIt );
- }
- }
-
- public int getFullSize()
- {
- int len = 0;
- for( int ii=0; ii < sMapPairs.length; ii++ ){
- len += sMapPairs[ii].length;
- }
- return len;
- }
-
-}
[11/18] commons-collections git commit: use default size for LRUMap
Posted by ch...@apache.org.
use default size for LRUMap
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_1_x_branch@130595 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/84e9b7d1
Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/84e9b7d1
Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/84e9b7d1
Branch: refs/heads/collections_1_x_branch
Commit: 84e9b7d19d9a5681da8dac716abe5f109daf48d1
Parents: 97c3230
Author: Morgan James Delagrange <mo...@apache.org>
Authored: Tue Feb 26 06:31:13 2002 +0000
Committer: Morgan James Delagrange <mo...@apache.org>
Committed: Tue Feb 26 06:31:13 2002 +0000
----------------------------------------------------------------------
src/test/org/apache/commons/collections/TestLRUMap.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/84e9b7d1/src/test/org/apache/commons/collections/TestLRUMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestLRUMap.java b/src/test/org/apache/commons/collections/TestLRUMap.java
index 3b022da..bee9a73 100644
--- a/src/test/org/apache/commons/collections/TestLRUMap.java
+++ b/src/test/org/apache/commons/collections/TestLRUMap.java
@@ -1,7 +1,7 @@
/*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.11.2.2 2002/02/26 06:17:51 morgand Exp $
- * $Revision: 1.11.2.2 $
- * $Date: 2002/02/26 06:17:51 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestLRUMap.java,v 1.11.2.3 2002/02/26 06:31:13 morgand Exp $
+ * $Revision: 1.11.2.3 $
+ * $Date: 2002/02/26 06:31:13 $
*
* ====================================================================
*
@@ -76,7 +76,7 @@ import java.util.HashMap;
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author <a href="mailto:morgand@apache.org">Morgan Delagrange</a>
- * @version $Id: TestLRUMap.java,v 1.11.2.2 2002/02/26 06:17:51 morgand Exp $
+ * @version $Id: TestLRUMap.java,v 1.11.2.3 2002/02/26 06:31:13 morgand Exp $
*/
public class TestLRUMap extends TestMap
{
@@ -94,7 +94,7 @@ public class TestLRUMap extends TestMap
}
public Map makeEmptyMap() {
- LRUMap map = new LRUMap(10);
+ LRUMap map = new LRUMap();
return map;
}