commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections AbstractTestSortedBidiMap.java TestDualTreeBidiMap.java TestAll.java
Date Fri, 31 Oct 2003 01:26:25 GMT
scolebourne    2003/10/30 17:26:25

  Modified:    collections/src/test/org/apache/commons/collections/decorators
                        TestFixedSizeSortedMap.java
                        TestTransformedSortedMap.java
               collections/src/java/org/apache/commons/collections
                        AbstractDualBidiMap.java
               collections/src/test/org/apache/commons/collections
                        TestAll.java
  Added:       collections/src/java/org/apache/commons/collections
                        DualTreeBidiMap.java
               collections/src/test/org/apache/commons/collections
                        AbstractTestSortedBidiMap.java
                        TestDualTreeBidiMap.java
  Log:
  Add DualTreeBidiMap implementation and tests
  
  Revision  Changes    Path
  1.6       +4 -4      jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestFixedSizeSortedMap.java
  
  Index: TestFixedSizeSortedMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestFixedSizeSortedMap.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestFixedSizeSortedMap.java	7 Oct 2003 22:20:58 -0000	1.5
  +++ TestFixedSizeSortedMap.java	31 Oct 2003 01:26:25 -0000	1.6
  @@ -62,9 +62,9 @@
   import java.util.TreeMap;
   
   import junit.framework.Test;
  -import junit.framework.TestSuite;
   
   import org.apache.commons.collections.AbstractTestSortedMap;
  +import org.apache.commons.collections.BulkTest;
   
   /**
    * Extension of {@link TestSortedMap} for exercising the {@link FixedSizeSortedMap}
  @@ -82,7 +82,7 @@
       }
   
       public static Test suite() {
  -        return new TestSuite(TestFixedSizeSortedMap.class);
  +        return BulkTest.makeSuite(TestFixedSizeSortedMap.class);
       }
   
       public static void main(String args[]) {
  
  
  
  1.5       +4 -4      jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestTransformedSortedMap.java
  
  Index: TestTransformedSortedMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/TestTransformedSortedMap.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestTransformedSortedMap.java	6 Oct 2003 23:44:23 -0000	1.4
  +++ TestTransformedSortedMap.java	31 Oct 2003 01:26:25 -0000	1.5
  @@ -62,9 +62,9 @@
   import java.util.TreeMap;
   
   import junit.framework.Test;
  -import junit.framework.TestSuite;
   
   import org.apache.commons.collections.AbstractTestSortedMap;
  +import org.apache.commons.collections.BulkTest;
   
   /**
    * Extension of {@link AbstractTestSortedMap} for exercising the {@link TransformedSortedMap}
  @@ -82,7 +82,7 @@
       }
   
       public static Test suite() {
  -        return new TestSuite(TestTransformedSortedMap.class);
  +        return BulkTest.makeSuite(TestTransformedSortedMap.class);
       }
   
       public static void main(String args[]) {
  
  
  
  1.5       +82 -10    jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractDualBidiMap.java
  
  Index: AbstractDualBidiMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/AbstractDualBidiMap.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractDualBidiMap.java	29 Oct 2003 00:06:25 -0000	1.4
  +++ AbstractDualBidiMap.java	31 Oct 2003 01:26:25 -0000	1.5
  @@ -94,6 +94,10 @@
        */
       protected transient Set keySet = null;
       /**
  +     * View of the values.
  +     */
  +    protected transient Collection values = null;
  +    /**
        * View of the entries.
        */
       protected transient Set entrySet = null;
  @@ -248,7 +252,10 @@
       }
   
       public Collection values() {
  -        return inverseBidiMap().keySet();
  +        if (values == null) {
  +            values = new Values(this);
  +        }
  +        return values;
       }
   
       public Set entrySet() {
  @@ -304,12 +311,13 @@
               }
               return modified;
           }
  -
  +        
           public void clear() {
               map.clear();
           }
       }
       
  +    //-----------------------------------------------------------------------
       /**
        * Inner class KeySet.
        */
  @@ -323,8 +331,12 @@
               return new KeySetIterator(super.iterator(), map);
           }
           
  +        public boolean contains(Object key) {
  +            return map.maps[0].containsKey(key);
  +        }
  +
           public boolean remove(Object key) {
  -            if (contains(key)) {
  +            if (map.maps[0].containsKey(key)) {
                   Object value = map.maps[0].remove(key);
                   map.maps[1].remove(value);
                   return true;
  @@ -339,7 +351,7 @@
       protected static class KeySetIterator extends AbstractIteratorDecorator {
           
           private final AbstractDualBidiMap map;
  -        private Object last = null;
  +        private Object lastKey = null;
           private boolean canRemove = false;
           
           protected KeySetIterator(Iterator iterator, AbstractDualBidiMap map) {
  @@ -348,23 +360,83 @@
           }
           
           public Object next() {
  -            last = super.next();
  +            lastKey = super.next();
               canRemove = true;
  -            return last;
  +            return lastKey;
           }
           
           public void remove() {
               if (canRemove == false) {
                   throw new IllegalStateException("Iterator remove() can only be called once
after next()");
               }
  -            Object value = map.maps[0].get(last);
  +            Object value = map.maps[0].get(lastKey);
               super.remove();
               map.maps[1].remove(value);
  -            last = null;
  +            lastKey = null;
  +            canRemove = false;
  +        }
  +    }
  +
  +    //-----------------------------------------------------------------------
  +    /**
  +     * Inner class Values.
  +     */
  +    protected static class Values extends View implements Set {
  +        
  +        protected Values(AbstractDualBidiMap map) {
  +            super(map.maps[0].values(), map);
  +        }
  +
  +        public Iterator iterator() {
  +            return new ValuesIterator(super.iterator(), map);
  +        }
  +        
  +        public boolean contains(Object value) {
  +            return map.maps[1].containsKey(value);
  +        }
  +
  +        public boolean remove(Object value) {
  +            if (map.maps[1].containsKey(value)) {
  +                Object key = map.maps[1].remove(value);
  +                map.maps[0].remove(key);
  +                return true;
  +            }
  +            return false;
  +        }
  +    }
  +    
  +    /**
  +     * Inner class ValuesIterator.
  +     */
  +    protected static class ValuesIterator extends AbstractIteratorDecorator {
  +        
  +        private final AbstractDualBidiMap map;
  +        private Object lastValue = null;
  +        private boolean canRemove = false;
  +        
  +        protected ValuesIterator(Iterator iterator, AbstractDualBidiMap map) {
  +            super(iterator);
  +            this.map = map;
  +        }
  +        
  +        public Object next() {
  +            lastValue = super.next();
  +            canRemove = true;
  +            return lastValue;
  +        }
  +        
  +        public void remove() {
  +            if (canRemove == false) {
  +                throw new IllegalStateException("Iterator remove() can only be called once
after next()");
  +            }
  +            super.remove(); // removes from maps[0]
  +            map.maps[1].remove(lastValue);
  +            lastValue = null;
               canRemove = false;
           }
       }
   
  +    //-----------------------------------------------------------------------
       /**
        * Inner class EntrySet.
        */
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/DualTreeBidiMap.java
  
  Index: DualTreeBidiMap.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/DualTreeBidiMap.java,v
1.1 2003/10/31 01:26:25 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 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/>.
   *
   */
  package org.apache.commons.collections;
  
  import java.util.Comparator;
  import java.util.Map;
  import java.util.SortedMap;
  import java.util.TreeMap;
  
  import org.apache.commons.collections.decorators.AbstractSortedMapDecorator;
  
  /**
   * Implementation of <code>BidiMap</code> that uses two <code>TreeMap</code>
instances.
   * 
   * @since Commons Collections 3.0
   * @version $Id: DualTreeBidiMap.java,v 1.1 2003/10/31 01:26:25 scolebourne Exp $
   * 
   * @author Matthew Hawthorne
   * @author Stephen Colebourne
   */
  public class DualTreeBidiMap extends AbstractDualBidiMap implements SortedBidiMap {
  
      /**
       * Creates an empty <code>DualTreeBidiMap</code>
       */
      public DualTreeBidiMap() {
          super();
      }
  
      /** 
       * Constructs a <code>DualTreeBidiMap</code> and copies the mappings from
       * specified <code>Map</code>.  
       *
       * @param map  the map whose mappings are to be placed in this map
       */
      public DualTreeBidiMap(Map map) {
          super();
          putAll(map);
      }
  
      /** 
       * Constructs a <code>HashBidiMap</code> that decorates the specified maps.
       *
       * @param normalMap  the normal direction map
       * @param reverseMap  the reverse direction map
       * @param inverseBidiMap  the inverse BidiMap
       */
      protected DualTreeBidiMap(Map normalMap, Map reverseMap, BidiMap inverseBidiMap) {
          super(normalMap, reverseMap, inverseBidiMap);
      }
      
      /**
       * Creates a new instance of the map used by the subclass to store data.
       * 
       * @return the map to be used for internal storage
       */
      protected Map createMap() {
          return new TreeMap();
      }
  
      /**
       * Creates a new instance of this object.
       * 
       * @param normalMap  the normal direction map
       * @param reverseMap  the reverse direction map
       * @param inverseBidiMap  the inverse BidiMap
       * @return new bidi map
       */
      protected BidiMap createBidiMap(Map normalMap, Map reverseMap, BidiMap inverseMap) {
          return new DualTreeBidiMap(normalMap, reverseMap, inverseMap);
      }
  
      // SortedBidiMap
      //-----------------------------------------------------------------------
      public SortedBidiMap inverseSortedBidiMap() {
          return (SortedBidiMap) inverseBidiMap();
      }
  
      // SortedMap
      //-----------------------------------------------------------------------
      public Comparator comparator() {
          return ((SortedMap) maps[0]).comparator();
      }
  
      public Object firstKey() {
          return ((SortedMap) maps[0]).firstKey();
      }
  
      public Object lastKey() {
          return ((SortedMap) maps[0]).lastKey();
      }
  
      //-----------------------------------------------------------------------
      public SortedMap headMap(Object toKey) {
          SortedMap sub = ((SortedMap) maps[0]).headMap(toKey);
          return new ViewMap(this, sub);
      }
  
      public SortedMap tailMap(Object fromKey) {
          SortedMap sub = ((SortedMap) maps[0]).tailMap(fromKey);
          return new ViewMap(this, sub);
      }
  
      public SortedMap subMap(Object fromKey, Object toKey) {
          SortedMap sub = ((SortedMap) maps[0]).subMap(fromKey, toKey);
          return new ViewMap(this, sub);
      }
      
      protected static class ViewMap extends AbstractSortedMapDecorator {
          final DualTreeBidiMap bidi;
          
          protected ViewMap(DualTreeBidiMap bidi, SortedMap sm) {
              super((SortedMap) bidi.createBidiMap(sm, bidi.maps[1], bidi.inverseBidiMap));
              this.bidi = (DualTreeBidiMap) map;
          }
          
          public boolean containsValue(Object value) {
              // override as default implementation jumps to [1]
              return bidi.maps[0].containsValue(value);
          }
          
          public SortedMap headMap(Object toKey) {
              return new ViewMap(bidi, super.headMap(toKey));
          }
  
          public SortedMap tailMap(Object fromKey) {
              return new ViewMap(bidi, super.tailMap(fromKey));
          }
  
          public SortedMap subMap(Object fromKey, Object toKey) {
              return new ViewMap(bidi, super.subMap(fromKey, toKey));
          }
      }
  
  }
  
  
  
  1.52      +4 -3      jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestAll.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- TestAll.java	28 Oct 2003 18:56:12 -0000	1.51
  +++ TestAll.java	31 Oct 2003 01:26:25 -0000	1.52
  @@ -96,6 +96,8 @@
           suite.addTest(TestCommonsLinkedList.suite());
           suite.addTest(TestCursorableLinkedList.suite());
           suite.addTest(TestDoubleOrderedMap.suite());
  +        suite.addTest(TestDualHashBidiMap.suite());
  +        suite.addTest(TestDualTreeBidiMap.suite());
           suite.addTest(TestExtendedProperties.suite());
           suite.addTest(TestFastArrayList.suite());
           suite.addTest(TestFastArrayList1.suite());
  @@ -104,7 +106,6 @@
           suite.addTest(TestFastTreeMap.suite());
           suite.addTest(TestFastTreeMap1.suite());
           suite.addTest(TestHashBag.suite());
  -        suite.addTest(TestDualHashBidiMap.suite());
           suite.addTest(TestIteratorUtils.suite());
           suite.addTest(TestLRUMap.suite());
           suite.addTest(TestMultiHashMap.suite());
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/AbstractTestSortedBidiMap.java
  
  Index: AbstractTestSortedBidiMap.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/AbstractTestSortedBidiMap.java,v
1.1 2003/10/31 01:26:25 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 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/>.
   *
   */
  package org.apache.commons.collections;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.SortedMap;
  import java.util.SortedSet;
  import java.util.TreeMap;
  import java.util.TreeSet;
  
  import org.apache.commons.collections.pairs.DefaultMapEntry;
  
  /**
   * Abstract test class for {@link BidiMap} methods and contracts.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/10/31 01:26:25 $
   * 
   * @author Matthew Hawthorne
   * @author Stephen Colebourne
   */
  public abstract class AbstractTestSortedBidiMap extends AbstractTestBidiMap {
  
      protected List sortedKeys = new ArrayList();
      protected List sortedValues = new ArrayList();
      protected SortedSet sortedNewValues = new TreeSet();
  
      public AbstractTestSortedBidiMap(String testName) {
          super(testName);
          sortedKeys.addAll(Arrays.asList(getSampleKeys()));
          Collections.sort(sortedKeys);
          sortedKeys = Collections.unmodifiableList(sortedKeys);
          
          Map map = new TreeMap();
          for (int i = 0; i < getSampleKeys().length; i++) {
              map.put(getSampleKeys()[i], getSampleValues()[i]);
          }
          sortedValues.addAll(map.values());
          sortedValues = Collections.unmodifiableList(sortedValues);
          
          sortedNewValues.addAll(Arrays.asList(getNewSampleValues()));
      }
  
      public AbstractTestSortedBidiMap() {
          super();
          sortedKeys.addAll(Arrays.asList(getSampleValues()));
          Collections.sort(sortedKeys);
          sortedKeys = Collections.unmodifiableList(sortedKeys);
          
          Map map = new TreeMap();
          for (int i = 0; i < getSampleKeys().length; i++) {
              map.put(getSampleValues()[i], getSampleKeys()[i]);
          }
          sortedValues.addAll(map.values());
          sortedValues = Collections.unmodifiableList(sortedValues);
          
          sortedNewValues.addAll(Arrays.asList(getNewSampleValues()));
      }
  
      //-----------------------------------------------------------------------
      protected boolean isAllowNullKey() {
          return false;
      }
      protected boolean isAllowNullValue() {
          return false;
      }
      protected Map makeConfirmedMap() {
          return new TreeMap();
      }
  
      //-----------------------------------------------------------------------    
      public void testFirstKey() {
          SortedMap sm = (SortedMap) makeFullMap();
          assertSame(sm.keySet().iterator().next(), sm.firstKey());
      }
      
      public void testLastKey() {
          SortedMap sm = (SortedMap) makeFullMap();
          Object obj = null;
          for (Iterator it = sm.keySet().iterator(); it.hasNext();) {
              obj = (Object) it.next();
          }
          assertSame(obj, sm.lastKey());
      }
      
      //-----------------------------------------------------------------------
      public void testBidiHeadMapContains() {
          // extra test as other tests get complex
          SortedBidiMap sm = (SortedBidiMap) makeFullMap();
          Iterator it = sm.keySet().iterator();
          Object first = it.next();
          Object toKey = it.next();
          Object second = it.next();
          Object firstValue = sm.get(first);
          Object secondValue = sm.get(second);
          
          SortedMap head = sm.headMap(toKey);
          assertEquals(1, head.size());
          assertEquals(true, sm.containsKey(first));
          assertEquals(true, head.containsKey(first));
          assertEquals(true, sm.containsValue(firstValue));
          assertEquals(true, head.containsValue(firstValue));
          assertEquals(true, sm.containsKey(second));
          assertEquals(false, head.containsKey(second));
          assertEquals(true, sm.containsValue(secondValue));
          assertEquals(false, head.containsValue(secondValue));
      }
                  
      //-----------------------------------------------------------------------
      public void testBidiRemoveByHeadMap() {
          // extra test as other tests get complex
          SortedBidiMap sm = (SortedBidiMap) makeFullMap();
          Iterator it = sm.keySet().iterator();
          Object first = it.next();
          Object second = it.next();
          Object toKey = it.next();
          
          SortedMap head = sm.headMap(toKey);
          assertEquals(2, head.size());
          assertEquals(true, sm.containsKey(first));
          assertEquals(true, head.containsKey(first));
          assertEquals(true, sm.containsKey(second));
          assertEquals(true, head.containsKey(second));
          
          Object firstValue = head.remove(first);
          assertEquals(false, sm.containsKey(first));
          assertEquals(false, sm.containsValue(firstValue));
          assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
          assertEquals(false, sm.inverseBidiMap().containsValue(first));
          assertEquals(false, head.containsKey(first));
          assertEquals(false, head.containsValue(firstValue));
          assertEquals(1, head.size());
          
          Object secondValue = head.remove(second);
          assertEquals(false, sm.containsKey(second));
          assertEquals(false, sm.containsValue(secondValue));
          assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
          assertEquals(false, sm.inverseBidiMap().containsValue(second));
          assertEquals(false, head.containsKey(second));
          assertEquals(false, head.containsValue(secondValue));
          assertEquals(0, head.size());
      }
  
      //-----------------------------------------------------------------------
      public void testBidiRemoveByHeadMapEntrySet() {
          // extra test as other tests get complex
          SortedBidiMap sm = (SortedBidiMap) makeFullMap();
          Iterator it = sm.keySet().iterator();
          it.next();
          it.next();
          Object fromKey = it.next();
          Object first = it.next();
          Object second = it.next();
          Object toKey = it.next();
          
          SortedMap head = sm.headMap(toKey);
          Set set = head.entrySet();
          Iterator it2 = set.iterator();
          Object fromEntry = it2.next();
          Map.Entry firstEntry = new DefaultMapEntry((Map.Entry) it2.next());
          Map.Entry secondEntry = new DefaultMapEntry((Map.Entry) it2.next());
          assertEquals(true, sm.containsKey(first));
          assertEquals(true, head.containsKey(first));
          assertEquals(true, set.contains(firstEntry));
          assertEquals(true, sm.containsKey(second));
          assertEquals(true, head.containsKey(second));
          assertEquals(true, set.contains(secondEntry));
          
          set.remove(firstEntry);
          assertEquals(false, sm.containsKey(firstEntry.getKey()));
          assertEquals(false, sm.containsValue(firstEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsKey(firstEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsValue(firstEntry.getKey()));
          assertEquals(false, head.containsKey(firstEntry.getKey()));
          assertEquals(false, head.containsValue(firstEntry.getValue()));
          assertEquals(false, set.contains(firstEntry));
          
          set.remove(secondEntry);
          assertEquals(false, sm.containsKey(secondEntry.getKey()));
          assertEquals(false, sm.containsValue(secondEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsKey(secondEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsValue(secondEntry.getKey()));
          assertEquals(false, head.containsKey(secondEntry.getKey()));
          assertEquals(false, head.containsValue(secondEntry.getValue()));
          assertEquals(false, set.contains(secondEntry));
      }
  
      //-----------------------------------------------------------------------
      public void testBidiRemoveByTailMap() {
          // extra test as other tests get complex
          SortedBidiMap sm = (SortedBidiMap) makeFullMap();
          Iterator it = sm.keySet().iterator();
          it.next();
          it.next();
          Object fromKey = it.next();
          Object first = it.next();
          Object second = it.next();
          
          SortedMap tail = sm.tailMap(fromKey);
          assertEquals(true, sm.containsKey(first));
          assertEquals(true, tail.containsKey(first));
          assertEquals(true, sm.containsKey(second));
          assertEquals(true, tail.containsKey(second));
          
          Object firstValue = tail.remove(first);
          assertEquals(false, sm.containsKey(first));
          assertEquals(false, sm.containsValue(firstValue));
          assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
          assertEquals(false, sm.inverseBidiMap().containsValue(first));
          assertEquals(false, tail.containsKey(first));
          assertEquals(false, tail.containsValue(firstValue));
          
          Object secondValue = tail.remove(second);
          assertEquals(false, sm.containsKey(second));
          assertEquals(false, sm.containsValue(secondValue));
          assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
          assertEquals(false, sm.inverseBidiMap().containsValue(second));
          assertEquals(false, tail.containsKey(second));
          assertEquals(false, tail.containsValue(secondValue));
      }
  
      //-----------------------------------------------------------------------
      public void testBidiRemoveByTailMapEntrySet() {
          // extra test as other tests get complex
          SortedBidiMap sm = (SortedBidiMap) makeFullMap();
          Iterator it = sm.keySet().iterator();
          it.next();
          it.next();
          Object fromKey = it.next();
          Object first = it.next();
          Object second = it.next();
          Object toKey = it.next();
          
          SortedMap tail = sm.tailMap(fromKey);
          Set set = tail.entrySet();
          Iterator it2 = set.iterator();
          Object fromEntry = it2.next();
          Map.Entry firstEntry = new DefaultMapEntry((Map.Entry) it2.next());
          Map.Entry secondEntry = new DefaultMapEntry((Map.Entry) it2.next());
          assertEquals(true, sm.containsKey(first));
          assertEquals(true, tail.containsKey(first));
          assertEquals(true, set.contains(firstEntry));
          assertEquals(true, sm.containsKey(second));
          assertEquals(true, tail.containsKey(second));
          assertEquals(true, set.contains(secondEntry));
          
          set.remove(firstEntry);
          assertEquals(false, sm.containsKey(firstEntry.getKey()));
          assertEquals(false, sm.containsValue(firstEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsKey(firstEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsValue(firstEntry.getKey()));
          assertEquals(false, tail.containsKey(firstEntry.getKey()));
          assertEquals(false, tail.containsValue(firstEntry.getValue()));
          assertEquals(false, set.contains(firstEntry));
          
          set.remove(secondEntry);
          assertEquals(false, sm.containsKey(secondEntry.getKey()));
          assertEquals(false, sm.containsValue(secondEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsKey(secondEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsValue(secondEntry.getKey()));
          assertEquals(false, tail.containsKey(secondEntry.getKey()));
          assertEquals(false, tail.containsValue(secondEntry.getValue()));
          assertEquals(false, set.contains(secondEntry));
      }
  
      //-----------------------------------------------------------------------
      public void testBidiRemoveBySubMap() {
          // extra test as other tests get complex
          SortedBidiMap sm = (SortedBidiMap) makeFullMap();
          Iterator it = sm.keySet().iterator();
          it.next();
          it.next();
          Object fromKey = it.next();
          Object first = it.next();
          Object second = it.next();
          Object toKey = it.next();
          
          SortedMap sub = sm.subMap(fromKey, toKey);
          assertEquals(true, sm.containsKey(first));
          assertEquals(true, sub.containsKey(first));
          assertEquals(true, sm.containsKey(second));
          assertEquals(true, sub.containsKey(second));
          
          Object firstValue = sub.remove(first);
          assertEquals(false, sm.containsKey(first));
          assertEquals(false, sm.containsValue(firstValue));
          assertEquals(false, sm.inverseBidiMap().containsKey(firstValue));
          assertEquals(false, sm.inverseBidiMap().containsValue(first));
          assertEquals(false, sub.containsKey(first));
          assertEquals(false, sub.containsValue(firstValue));
          
          Object secondValue = sub.remove(second);
          assertEquals(false, sm.containsKey(second));
          assertEquals(false, sm.containsValue(secondValue));
          assertEquals(false, sm.inverseBidiMap().containsKey(secondValue));
          assertEquals(false, sm.inverseBidiMap().containsValue(second));
          assertEquals(false, sub.containsKey(second));
          assertEquals(false, sub.containsValue(secondValue));
      }
  
      //-----------------------------------------------------------------------
      public void testBidiRemoveBySubMapEntrySet() {
          // extra test as other tests get complex
          SortedBidiMap sm = (SortedBidiMap) makeFullMap();
          Iterator it = sm.keySet().iterator();
          it.next();
          it.next();
          Object fromKey = it.next();
          Object first = it.next();
          Object second = it.next();
          Object toKey = it.next();
          
          SortedMap sub = sm.subMap(fromKey, toKey);
          Set set = sub.entrySet();
          assertEquals(3, set.size());
          Iterator it2 = set.iterator();
          Object fromEntry = it2.next();
          Map.Entry firstEntry = new DefaultMapEntry((Map.Entry) it2.next());
          Map.Entry secondEntry = new DefaultMapEntry((Map.Entry) it2.next());
          assertEquals(true, sm.containsKey(first));
          assertEquals(true, sub.containsKey(first));
          assertEquals(true, set.contains(firstEntry));
          assertEquals(true, sm.containsKey(second));
          assertEquals(true, sub.containsKey(second));
          assertEquals(true, set.contains(secondEntry));
          
          set.remove(firstEntry);
          assertEquals(false, sm.containsKey(firstEntry.getKey()));
          assertEquals(false, sm.containsValue(firstEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsKey(firstEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsValue(firstEntry.getKey()));
          assertEquals(false, sub.containsKey(firstEntry.getKey()));
          assertEquals(false, sub.containsValue(firstEntry.getValue()));
          assertEquals(false, set.contains(firstEntry));
          
          set.remove(secondEntry);
          assertEquals(false, sm.containsKey(secondEntry.getKey()));
          assertEquals(false, sm.containsValue(secondEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsKey(secondEntry.getValue()));
          assertEquals(false, sm.inverseBidiMap().containsValue(secondEntry.getKey()));
          assertEquals(false, sub.containsKey(secondEntry.getKey()));
          assertEquals(false, sub.containsValue(secondEntry.getValue()));
          assertEquals(false, set.contains(secondEntry));
      }
  
      //-----------------------------------------------------------------------    
      public BulkTest bulkTestHeadMap() {
          return new AbstractTestSortedMap.TestHeadMap(this);
      }
  
      public BulkTest bulkTestTailMap() {
          return new AbstractTestSortedMap.TestTailMap(this);
      }
  
      public BulkTest bulkTestSubMap() {
          return new AbstractTestSortedMap.TestSubMap(this);
      }
  
  }
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/TestDualTreeBidiMap.java
  
  Index: TestDualTreeBidiMap.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestDualTreeBidiMap.java,v
1.1 2003/10/31 01:26:25 scolebourne Exp $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 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/>.
   *
   */
  package org.apache.commons.collections;
  
  import junit.framework.Test;
  import junit.textui.TestRunner;
  
  /**
   * JUnit tests.
   * 
   * @version $Revision: 1.1 $ $Date: 2003/10/31 01:26:25 $
   * 
   * @author Matthew Hawthorne
   * @author Stephen Colebourne
   */
  public class TestDualTreeBidiMap extends AbstractTestSortedBidiMap {
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
      
      public static Test suite() {
          return BulkTest.makeSuite(TestDualTreeBidiMap.class);
      }
  
      public TestDualTreeBidiMap(String testName) {
          super(testName);
      }
  
      protected BidiMap makeEmptyBidiMap() {
          return new DualTreeBidiMap();
      }
  
      /**
       * Override to prevent infinite recursion of tests.
       */
      protected String[] ignoredTests() {
          return new String[] {"TestDualTreeBidiMap.bulkTestInverseMap.bulkTestInverseMap"};
      }
      
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message