You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2015/02/28 16:58:06 UTC
svn commit: r1662953 - in /directory/mavibot/trunk/mavibot/src:
main/java/org/apache/directory/mavibot/btree/
test/java/org/apache/directory/mavibot/btree/
Author: elecharny
Date: Sat Feb 28 15:58:05 2015
New Revision: 1662953
URL: http://svn.apache.org/r1662953
Log:
o Fixed the EmptyTupleCursor class
Modified:
directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyTupleCursor.java
directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java
directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java?rev=1662953&r1=1662952&r2=1662953&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java Sat Feb 28 15:58:05 2015
@@ -131,7 +131,7 @@ import org.apache.directory.mavibot.btre
if ( transaction == null )
{
- return new EmptyTupleCursor<K, V>( 0L );
+ return new EmptyTupleCursor<K, V>();
}
else
{
@@ -162,7 +162,7 @@ import org.apache.directory.mavibot.btre
if ( transaction == null )
{
- return new EmptyTupleCursor<K, V>( revision );
+ return new EmptyTupleCursor<K, V>();
}
else
{
@@ -219,7 +219,7 @@ import org.apache.directory.mavibot.btre
if ( transaction == null )
{
- return new EmptyTupleCursor<K, V>( revision );
+ return new EmptyTupleCursor<K, V>();
}
else
{
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyTupleCursor.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyTupleCursor.java?rev=1662953&r1=1662952&r2=1662953&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyTupleCursor.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/EmptyTupleCursor.java Sat Feb 28 15:58:05 2015
@@ -23,12 +23,9 @@ package org.apache.directory.mavibot.btr
import java.io.IOException;
import java.util.NoSuchElementException;
-import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
-
/**
* A Cursor which is used when we have no element to return
- * <p>
*
* @param <K> The type for the Key
* @param <V> The type for the stored value
@@ -37,20 +34,20 @@ import org.apache.directory.mavibot.btre
*/
public class EmptyTupleCursor<K, V> extends TupleCursor<K, V>
{
- private long revision;
+ /** AN empty cursor does not have a revision */
+ private static final long NO_REVISION = -1L;
+
+ /** The creation date */
private long creationDate;
+
/**
- * Creates a new instance of Cursor, starting on a page at a given position.
- *
- * @param transaction The transaction this operation is protected by
- * @param stack The stack of parent's from root to this page
+ * Creates a new instance of EmptyTupleCursor. It will never return any result
*/
- public EmptyTupleCursor( long revision )
+ public EmptyTupleCursor()
{
super();
- this.revision = revision;
creationDate = System.currentTimeMillis();
}
@@ -72,50 +69,35 @@ public class EmptyTupleCursor<K, V> exte
/**
- * Tells if the cursor can return a next element
+ * Always return false.
*
- * @return true if there are some more elements
- * @throws IOException
- * @throws EndOfFileExceededException
+ * @return Always false
*/
- public boolean hasNext() throws EndOfFileExceededException, IOException
+ public boolean hasNext()
{
return false;
}
/**
- * Find the next key/value
+ * Always throws a NoSuchElementException.
*
- * @return A Tuple containing the found key and value
- * @throws IOException
- * @throws EndOfFileExceededException
+ * @return Nothing
+ * @throws NoSuchElementException There is no element in a EmptyTupleCursor
*/
- public Tuple<K, V> next() throws EndOfFileExceededException, IOException
+ public Tuple<K, V> next() throws NoSuchElementException
{
throw new NoSuchElementException( "No tuple present" );
}
/**
- * Get the next non-duplicate key.
- * If the BTree contains :
+ * Always throws a NoSuchElementException.
*
- * <ul>
- * <li><1,0></li>
- * <li><1,1></li>
- * <li><1,2></li>
- * <li><2,0></li>
- * <li><2,1></li>
- * </ul>
- *
- * and cursor is present at <1,1> then the returned tuple will be <2,0> (not <1,2>)
- *
- * @return A Tuple containing the found key and value
- * @throws EndOfFileExceededException
- * @throws IOException
+ * @return Nothing
+ * @throws NoSuchElementException There is no element in a EmptyTupleCursor
*/
- public Tuple<K, V> nextKey() throws EndOfFileExceededException, IOException
+ public Tuple<K, V> nextKey() throws NoSuchElementException
{
// This is the end : no more value
throw new NoSuchElementException( "No more tuples present" );
@@ -123,76 +105,57 @@ public class EmptyTupleCursor<K, V> exte
/**
- * Tells if the cursor can return a next key
+ * Always false
*
- * @return true if there are some more keys
- * @throws IOException
- * @throws EndOfFileExceededException
+ * @return false
*/
- public boolean hasNextKey() throws EndOfFileExceededException, IOException
+ public boolean hasNextKey()
{
return false;
}
/**
- * Tells if the cursor can return a previous element
- *
- * @return true if there are some more elements
- * @throws IOException
- * @throws EndOfFileExceededException
+ * Always false
+ *
+ * @return false
*/
- public boolean hasPrev() throws EndOfFileExceededException, IOException
+ public boolean hasPrev()
{
return false;
}
/**
- * Find the previous key/value
+ * Always throws a NoSuchElementException.
*
- * @return A Tuple containing the found key and value
- * @throws IOException
- * @throws EndOfFileExceededException
+ * @return Nothing
+ * @throws NoSuchElementException There is no element in a EmptyTupleCursor
*/
- public Tuple<K, V> prev() throws EndOfFileExceededException, IOException
+ public Tuple<K, V> prev() throws NoSuchElementException
{
throw new NoSuchElementException( "No more tuple present" );
}
/**
- * Get the previous non-duplicate key.
- * If the BTree contains :
+ * Always throws a NoSuchElementException.
*
- * <ul>
- * <li><1,0></li>
- * <li><1,1></li>
- * <li><1,2></li>
- * <li><2,0></li>
- * <li><2,1></li>
- * </ul>
- *
- * and cursor is present at <2,1> then the returned tuple will be <1,0> (not <2,0>)
- *
- * @return A Tuple containing the found key and value
- * @throws EndOfFileExceededException
- * @throws IOException
+ * @return Nothing
+ * @throws NoSuchElementException There is no element in a EmptyTupleCursor
*/
- public Tuple<K, V> prevKey() throws EndOfFileExceededException, IOException
+ public Tuple<K, V> prevKey() throws NoSuchElementException
{
throw new NoSuchElementException( "No more tuples present" );
}
/**
- * Tells if the cursor can return a previous key
- *
- * @return true if there are some more keys
- * @throws IOException
- * @throws EndOfFileExceededException
+ * Always false
+ *
+ * @return false
*/
- public boolean hasPrevKey() throws EndOfFileExceededException, IOException
+ public boolean hasPrevKey()
{
return false;
}
@@ -208,6 +171,7 @@ public class EmptyTupleCursor<K, V> exte
/**
* Get the creation date
+ *
* @return The creation date for this cursor
*/
public long getCreationDate()
@@ -217,16 +181,19 @@ public class EmptyTupleCursor<K, V> exte
/**
- * Get the current revision
+ * Always -1L for an empty cursor
*
- * @return The revision this cursor is based on
+ * @return -1L
*/
public long getRevision()
{
- return revision;
+ return NO_REVISION;
}
+ /**
+ * @see Object#toString()
+ */
public String toString()
{
return "EmptyTupleCursor";
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java?rev=1662953&r1=1662952&r2=1662953&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java Sat Feb 28 15:58:05 2015
@@ -740,7 +740,7 @@ import org.apache.directory.mavibot.btre
if ( nbElems == 0 )
{
// We have to return an empty cursor
- return new TupleCursor<K, V>( transaction, null, 0 );
+ return new EmptyTupleCursor<K, V>();
}
// Create the cursor we will use
Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java?rev=1662953&r1=1662952&r2=1662953&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java (original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBrowseTest.java Sat Feb 28 15:58:05 2015
@@ -814,7 +814,7 @@ public class PersistedBTreeBrowseTest
// Expected
}
- assertEquals( 0L, cursor.getRevision() );
+ assertEquals( -1L, cursor.getRevision() );
}