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:52 UTC
[04/18] commons-collections git commit: to ease maintenance,
removed all unreleased classes from the 1.x branch
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;
- }
-
-}