directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r761490 - in /directory/apacheds/branches/ldif-partition/core-avl/src: main/java/org/apache/directory/server/core/avltree/ test/java/org/apache/directory/server/core/avltree/
Date Fri, 03 Apr 2009 00:30:10 GMT
Author: akarasulu
Date: Fri Apr  3 00:30:09 2009
New Revision: 761490

URL: http://svn.apache.org/viewvc?rev=761490&view=rev
Log:
fixed a few issues and bugs associated with types and the fact that we changed the way we
handle the value now

Added:
    directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlSingletonOrOrderedSetCursor.java
      - copied, changed from r761433, directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java
    directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsWrapperCursor.java
Removed:
    directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java
Modified:
    directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursorTest.java

Copied: directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlSingletonOrOrderedSetCursor.java
(from r761433, directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlSingletonOrOrderedSetCursor.java?p2=directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlSingletonOrOrderedSetCursor.java&p1=directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java&r1=761433&r2=761490&rev=761490&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursor.java
(original)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlSingletonOrOrderedSetCursor.java
Fri Apr  3 00:30:09 2009
@@ -31,22 +31,23 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
-public class AvlTreeMapNoDupsCursor<K,V> extends AbstractTupleCursor<K,V>
+public class AvlSingletonOrOrderedSetCursor<K,V> extends AbstractTupleCursor<K,SingletonOrOrderedSet<V>>
 {
     private AvlTreeMap<K, V> tree;
     private LinkedAvlMapNode<K,V> node;
     private boolean onNode = false;
     private boolean isAfterLast = false;
     private boolean isBeforeFirst = true;
-    private Tuple<K,V> returnedTuple = new Tuple<K,V>();
+    private Tuple<K,SingletonOrOrderedSet<V>> returnedTuple = new Tuple<K,
SingletonOrOrderedSet<V>>();
     
-    public AvlTreeMapNoDupsCursor( AvlTreeMap<K, V> tree )
+    
+    public AvlSingletonOrOrderedSetCursor( AvlTreeMap<K, V> tree )
     {
         this.tree = tree;
     }
 
     
-    public void after( Tuple<K,V> element ) throws Exception 
+    public void after( Tuple<K,SingletonOrOrderedSet<V>> element ) throws Exception

     {
         afterKey( element.getKey() );
     }
@@ -68,7 +69,7 @@
     }
 
 
-    public void before( Tuple<K,V> element ) throws Exception 
+    public void before( Tuple<K,SingletonOrOrderedSet<V>> element ) throws Exception

     {
         beforeKey( element.getKey() );
     }
@@ -94,13 +95,13 @@
     }
 
 
-    public Tuple<K,V> get() throws Exception 
+    public Tuple<K,SingletonOrOrderedSet<V>> get() throws Exception 
     {
         checkNotClosed( "get" );
         if ( onNode )
         {
             returnedTuple.setKey( node.key );
-            returnedTuple.setValue( node.value.getSingleton() );
+            returnedTuple.setValue( node.value );
             return returnedTuple;
         }
         
@@ -233,7 +234,7 @@
     }
 
 
-    public void afterValue( K key, V value ) throws Exception
+    public void afterValue( K key, SingletonOrOrderedSet<V> value ) throws Exception
     {
         throw new UnsupportedOperationException( "This Cursor does not support duplicate
keys." );
     }
@@ -266,7 +267,7 @@
     }
 
 
-    public void beforeValue( K key, V value ) throws Exception
+    public void beforeValue( K key, SingletonOrOrderedSet<V> value ) throws Exception
     {
         throw new UnsupportedOperationException( "This Cursor does not support duplicate
keys." );
     }

Added: directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsWrapperCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsWrapperCursor.java?rev=761490&view=auto
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsWrapperCursor.java
(added)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/main/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsWrapperCursor.java
Fri Apr  3 00:30:09 2009
@@ -0,0 +1,149 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.server.core.avltree;
+
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
+import org.apache.directory.server.xdbm.AbstractTupleCursor;
+import org.apache.directory.server.xdbm.Tuple;
+
+
+/**
+ * A cursor that converts SingletonOrOrderedSet objects in the value from a
+ * AvlTreeMap into Tuples with just K and V presuming that all the keys have
+ * no duplicates. 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AvlTreeMapNoDupsWrapperCursor<K,V> extends AbstractTupleCursor<K, V>
+{
+    private final AvlSingletonOrOrderedSetCursor<K, V> wrapped;
+    private final Tuple<K,V> returnedTuple = new Tuple<K, V>();
+    
+    
+    public AvlTreeMapNoDupsWrapperCursor( AvlSingletonOrOrderedSetCursor<K, V> wrapped
)
+    {
+        this.wrapped = wrapped;
+    }
+    
+
+    public void afterKey( K key ) throws Exception
+    {
+        wrapped.afterKey( key );
+    }
+
+    
+    public void afterValue( K key, V value ) throws Exception
+    {
+        throw new UnsupportedOperationException( "This Cursor does not support duplicate
keys." );
+    }
+
+    
+    public void beforeKey( K key ) throws Exception
+    {
+        wrapped.beforeKey( key );
+    }
+
+    
+    public void beforeValue( K key, V value ) throws Exception
+    {
+        throw new UnsupportedOperationException( "This Cursor does not support duplicate
keys." );
+    }
+
+    
+    public void after( Tuple<K, V> element ) throws Exception
+    {
+        wrapped.afterKey( element.getKey() );
+    }
+
+    
+    public void afterLast() throws Exception
+    {
+        wrapped.afterLast();
+    }
+
+    
+    public boolean available()
+    {
+        return wrapped.available();
+    }
+
+    
+    public void before( Tuple<K, V> element ) throws Exception
+    {
+        wrapped.beforeKey( element.getKey() );
+    }
+
+    
+    public void beforeFirst() throws Exception
+    {
+        wrapped.beforeFirst();
+    }
+
+    
+    public boolean first() throws Exception
+    {
+        return wrapped.first();
+    }
+    
+
+    public Tuple<K, V> get() throws Exception
+    {
+        if ( wrapped.available() )
+        {
+            Tuple<K, SingletonOrOrderedSet<V>> tuple = wrapped.get();
+            
+            if ( tuple.getValue().isOrderedSet() )
+            {
+                System.out.println( "tuple key = " + tuple.getKey() );
+                tuple.getValue().getOrderedSet().printTree();
+            }
+            
+            returnedTuple.setBoth( tuple.getKey(), tuple.getValue().getSingleton() );
+            return returnedTuple;
+        }
+        
+        throw new InvalidCursorPositionException();
+    }
+
+    
+    public boolean isElementReused()
+    {
+        return true;
+    }
+
+    
+    public boolean last() throws Exception
+    {
+        return wrapped.last();
+    }
+
+    
+    public boolean next() throws Exception
+    {
+        return wrapped.next();
+    }
+
+    
+    public boolean previous() throws Exception
+    {
+        return wrapped.previous();
+    }
+}

Modified: directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursorTest.java?rev=761490&r1=761489&r2=761490&view=diff
==============================================================================
--- directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursorTest.java
(original)
+++ directory/apacheds/branches/ldif-partition/core-avl/src/test/java/org/apache/directory/server/core/avltree/AvlTreeMapNoDupsCursorTest.java
Fri Apr  3 00:30:09 2009
@@ -45,7 +45,7 @@
 {
     AvlTreeMap<Integer, Integer> tree;
 
-    AvlTreeMapNoDupsCursor<Integer, Integer> cursor;
+    AvlSingletonOrOrderedSetCursor<Integer, Integer> cursor;
 
 
     @Before
@@ -63,7 +63,7 @@
 
         tree = new AvlTreeMapImpl<Integer, Integer>( comparator, comparator, true );
 
-        cursor = new AvlTreeMapNoDupsCursor<Integer, Integer>( tree );
+        cursor = new AvlSingletonOrOrderedSetCursor<Integer, Integer>( tree );
     }
 
 
@@ -102,10 +102,10 @@
         assertFalse( cursor.previous() );
         assertFalse( cursor.available() );
 
-        cursor.before( new Tuple( 3, null ) );
+        cursor.before( new Tuple<Integer, SingletonOrOrderedSet<Integer>>( 3,
null ) );
         assertFalse( cursor.available() );
 
-        cursor.after( new Tuple( 3, null ) );
+        cursor.after( new Tuple<Integer, SingletonOrOrderedSet<Integer>>( 3,
null ) );
         assertFalse( cursor.available() );
 
         cursor.close();
@@ -137,7 +137,7 @@
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 7, ( int ) cursor.get().getKey() );
-        assertEquals( 7, ( int ) cursor.get().getValue() );
+        assertEquals( 7, ( int ) cursor.get().getValue().getSingleton() );
 
         cursor.afterLast();
         assertFalse( cursor.next() );
@@ -155,26 +155,26 @@
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
 
-        cursor.before( new Tuple( 3, null ) );
+        cursor.before( new Tuple<Integer, SingletonOrOrderedSet<Integer>>( 3,
null ) );
         assertFalse( cursor.available() );
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 7, ( int ) cursor.get().getKey() );
-        assertEquals( 7, ( int ) cursor.get().getValue() );
+        assertEquals( 7, ( int ) cursor.get().getValue().getSingleton() );
 
-        cursor.after( new Tuple( 3, null ) );
+        cursor.after( new Tuple<Integer, SingletonOrOrderedSet<Integer>>( 3,
null ) );
         assertFalse( cursor.available() );
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 7, ( int ) cursor.get().getKey() );
-        assertEquals( 7, ( int ) cursor.get().getValue() );
+        assertEquals( 7, ( int ) cursor.get().getValue().getSingleton() );
 
-        cursor.before( new Tuple( 7, null ) );
+        cursor.before( new Tuple<Integer, SingletonOrOrderedSet<Integer>>( 7,
null ) );
         assertFalse( cursor.available() );
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 7, ( int ) cursor.get().getKey() );
-        assertEquals( 7, ( int ) cursor.get().getValue() );
+        assertEquals( 7, ( int ) cursor.get().getValue().getSingleton() );
     }
 
 
@@ -206,22 +206,22 @@
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 3, ( int ) cursor.get().getKey() );
-        assertEquals( 3, ( int ) cursor.get().getValue() );
+        assertEquals( 3, ( int ) cursor.get().getValue().getSingleton() );
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 7, ( int ) cursor.get().getKey() );
-        assertEquals( 7, ( int ) cursor.get().getValue() );
+        assertEquals( 7, ( int ) cursor.get().getValue().getSingleton() );
 
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 10, ( int ) cursor.get().getKey() );
-        assertEquals( 10, ( int ) cursor.get().getValue() );
+        assertEquals( 10, ( int ) cursor.get().getValue().getSingleton() );
         
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 11, ( int ) cursor.get().getKey() );
-        assertEquals( 11, ( int ) cursor.get().getValue() );
+        assertEquals( 11, ( int ) cursor.get().getValue().getSingleton() );
         assertFalse( cursor.next() );
         assertFalse( cursor.available() );
 
@@ -230,21 +230,21 @@
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         assertEquals( 11, ( int ) cursor.get().getKey() );
-        assertEquals( 11, ( int ) cursor.get().getValue() );
+        assertEquals( 11, ( int ) cursor.get().getValue().getSingleton() );
         
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         assertEquals( 10, ( int ) cursor.get().getKey() );
-        assertEquals( 10, ( int ) cursor.get().getValue() );
+        assertEquals( 10, ( int ) cursor.get().getValue().getSingleton() );
         
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         assertEquals( 7, ( int ) cursor.get().getKey() );
-        assertEquals( 7, ( int ) cursor.get().getValue() );
+        assertEquals( 7, ( int ) cursor.get().getValue().getSingleton() );
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
         assertEquals( 3, ( int ) cursor.get().getKey() );
-        assertEquals( 3, ( int ) cursor.get().getValue() );
+        assertEquals( 3, ( int ) cursor.get().getValue().getSingleton() );
         assertFalse( cursor.previous() );
         assertFalse( cursor.available() );
 
@@ -260,31 +260,31 @@
         assertTrue( cursor.previous() );
         assertTrue( cursor.available() );
 
-        cursor.after( new Tuple( 5, null ) );
+        cursor.after( new Tuple<Integer, SingletonOrOrderedSet<Integer>>( 5,
null ) );
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 7, ( int ) cursor.get().getKey() );
-        assertEquals( 7, ( int ) cursor.get().getValue() );
+        assertEquals( 7, ( int ) cursor.get().getValue().getSingleton() );
         
-        cursor.before( new Tuple( 11, null ) );
+        cursor.before( new Tuple<Integer, SingletonOrOrderedSet<Integer>>( 11,
null ) );
         assertTrue( cursor.next() );
         assertTrue( cursor.available() );
         assertEquals( 11, ( int ) cursor.get().getKey() );
-        assertEquals( 11, ( int ) cursor.get().getValue() );
+        assertEquals( 11, ( int ) cursor.get().getValue().getSingleton() );
     }
 
 
     @Test(expected = UnsupportedOperationException.class)
     public void testAfterValue() throws Exception
     {
-        cursor.afterValue( 0, 0 );
+        cursor.afterValue( 0, null );
     }
 
 
     @Test(expected = UnsupportedOperationException.class)
     public void testBeforeValue() throws Exception
     {
-        cursor.beforeValue( 0, 0 );
+        cursor.beforeValue( 0, null );
     }
 
     
@@ -297,25 +297,25 @@
         tree.insert( 11, 11 );
 
         cursor.next();
-        Tuple t = cursor.get();
+        Tuple<Integer, SingletonOrOrderedSet<Integer>> t = cursor.get();
      
-        assertEquals( 3, t.getKey() );
+        assertEquals( 3, t.getKey().intValue() );
         
-        assertEquals( AvlTreeImpl.class, t.getValue().getClass() );
+        assertEquals( AvlTreeImpl.class, t.getValue().getOrderedSet().getClass() );
         
-        AvlTree dupsTree = ( AvlTree ) t.getValue();
+        AvlTree<Integer> dupsTree = t.getValue().getOrderedSet();
         assertEquals( 3, dupsTree.getSize() );
         
-        AvlTreeCursor valCursor = new AvlTreeCursor<Integer>( dupsTree );
+        AvlTreeCursor<Integer> valCursor = new AvlTreeCursor<Integer>( dupsTree
);
         
         assertTrue( valCursor.next() );
-        assertEquals( 3, valCursor.get() );
+        assertEquals( 3, valCursor.get().intValue() );
         
         assertTrue( valCursor.next() );
-        assertEquals( 7, valCursor.get() );
+        assertEquals( 7, valCursor.get().intValue() );
         
         assertTrue( valCursor.next() );
-        assertEquals( 10, valCursor.get() );
+        assertEquals( 10, valCursor.get().intValue() );
 
         assertFalse( valCursor.next() );
     }



Mime
View raw message