directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r760415 - 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 Tue, 31 Mar 2009 12:37:47 GMT
Author: kayyagari
Date: Tue Mar 31 12:37:43 2009
New Revision: 760415

URL: http://svn.apache.org/viewvc?rev=760415&view=rev
Log:
o added a falg to allow duplicate keys
o fixed the testcase

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=760415&r1=760414&r2=760415&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
Tue Mar 31 12:37:43 2009
@@ -49,19 +49,29 @@
     
     /** node representing the end of the doubly linked list formed with the tree nodes */
     private LinkedAvlMapNode<K,V> last;
+    
+    /** flag to allow storing duplicate keys */
+    private boolean allowDuplicates;
 
 
     /**
-     * Creates a new instance of AVLTree.
+     * Creates a new instance of AVLTreeMap without support for duplicate keys.
      *
      * @param comparator1 the comparator to be used for comparing keys
      */
     public AvlTreeMap( Comparator<K> keyComparator, Comparator<V> valueComparator
)
     {
+        this( keyComparator, valueComparator, false );
+    }
+    
+
+    public AvlTreeMap( Comparator<K> keyComparator, Comparator<V> valueComparator,
boolean allowDuplicates )
+    {
         this.keyComparator = keyComparator;
         this.valueComparator = valueComparator;
+        this.allowDuplicates = allowDuplicates;
     }
-    
+
     
     /**
      * @return the key comparator associated with this tree 
@@ -117,7 +127,14 @@
             
             if( c == 0 )
             {
-                return insertDupKey( key, value, temp ); // key already exists add another
value
+                if( allowDuplicates )
+                {
+                    return insertDupKey( key, value, temp ); // key already exists add another
value
+                }
+                else
+                {
+                    return key;
+                }
             }
             
             if( c < 0 )
@@ -1077,4 +1094,10 @@
             visit( node.getLeft(), node );
         }
     }
+
+
+    public boolean isDupsAllowed()
+    {
+        return allowDuplicates;
+    }
 }

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=760415&r1=760414&r2=760415&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
Tue Mar 31 12:37:43 2009
@@ -63,13 +63,14 @@
 
         };
     
-        tree = new AvlTreeMap<Integer, Integer>( comparator, comparator );
+        tree = new AvlTreeMap<Integer, Integer>( comparator, comparator, true );
     }
 
 
     @Test
     public void testEmpty()
     {
+        assertTrue( tree.isDupsAllowed() );
         assertTrue( tree.isEmpty() );
         assertNull( tree.getFirst() );
         assertNull( tree.getLast() );



Mime
View raw message