directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r761007 - in /directory/apacheds/branches/ldif-partition/core-avl/src: main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java
Date Wed, 01 Apr 2009 18:45:04 GMT
Author: kayyagari
Date: Wed Apr  1 18:45:03 2009
New Revision: 761007

URL: http://svn.apache.org/viewvc?rev=761007&view=rev
Log:
fixed a bug related to replacing an existing key's value when duplicate keys are not allowed

Modified:
    directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java
    directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java

Modified: directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java?rev=761007&r1=761006&r2=761007&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java
(original)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMap.java
Wed Apr  1 18:45:03 2009
@@ -97,8 +97,7 @@
      * @param key the item to be inserted
      * @return the replaced key if it already exists
      * TODO - should we not return the value if the key already existed?
-     * TODO - insert has no effect if the key already exists and dups are not allowed.
-     * Note: Ignores if a node with the given key already exists.
+     * Note: Replaces a nodes value if duplicate keys are not allowed.
      */
     public K insert( K key, V value )
     {
@@ -135,6 +134,8 @@
                 }
                 else
                 {
+                    // replcae the existing value with the new value
+                    temp.value = value;
                     return key;
                 }
             }

Modified: directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java?rev=761007&r1=761006&r2=761007&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java
(original)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapTest.java
Wed Apr  1 18:45:03 2009
@@ -31,7 +31,6 @@
 import java.util.List;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -50,20 +49,20 @@
 
     private static final Logger LOG = LoggerFactory.getLogger( AvlTreeTest.class );
 
-
-    @Before
-    public void createTree()
+    Comparator<Integer> comparator  = new Comparator<Integer>()
     {
-        Comparator<Integer> comparator = new Comparator<Integer>()
+
+        public int compare( Integer i1, Integer i2 )
         {
+            return i1.compareTo( i2 );
+        }
 
-            public int compare( Integer i1, Integer i2 )
-            {
-                return i1.compareTo( i2 );
-            }
+    };
 
-        };
     
+    @Before
+    public void createTree()
+    {
         tree = new AvlTreeMap<Integer, Integer>( comparator, comparator, true );
     }
 
@@ -115,9 +114,11 @@
 
 
     @Test
-    @Ignore ( "insert() contract is not observed on replacement" )
     public void testInsertWithReplace()
     {
+        // to override the value tree should disable duplicate keys
+        tree = new AvlTreeMap<Integer, Integer>( comparator, comparator, false );
+        
         assertNull( tree.insert( 43, 891 ) );
         assertEquals( 891, tree.find( 43 ).getValue().intValue() );
         



Mime
View raw message