git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@190 f203690c-595d-4dc9-a70b-905162fa7fd2tags/rel_1_1_10
@@ -583,38 +583,38 @@ public abstract class Cursor implements Iterable<Map<String, Object>> | |||
} | |||
/** | |||
* Skips as many rows as possible up to the given number of rows. | |||
* @return the number of rows skipped. | |||
* Moves forward as many rows as possible up to the given number of rows. | |||
* @return the number of rows moved. | |||
*/ | |||
public int skipNextRows(int numRows) | |||
public int moveNextRows(int numRows) | |||
throws IOException | |||
{ | |||
return skipSomeRows(numRows, true); | |||
return moveSomeRows(numRows, true); | |||
} | |||
/** | |||
* Skips as many rows as possible up to the given number of rows. | |||
* @return the number of rows skipped. | |||
* Moves backward as many rows as possible up to the given number of rows. | |||
* @return the number of rows moved. | |||
*/ | |||
public int skipPreviousRows(int numRows) | |||
public int movePreviousRows(int numRows) | |||
throws IOException | |||
{ | |||
return skipSomeRows(numRows, false); | |||
return moveSomeRows(numRows, false); | |||
} | |||
/** | |||
* Skips as many rows as possible in the given direction up to the given | |||
* Moves as many rows as possible in the given direction up to the given | |||
* number of rows. | |||
* @return the number of rows skipped. | |||
* @return the number of rows moved. | |||
*/ | |||
private int skipSomeRows(int numRows, boolean moveForward) | |||
private int moveSomeRows(int numRows, boolean moveForward) | |||
throws IOException | |||
{ | |||
int numSkippedRows = 0; | |||
while((numSkippedRows < numRows) && moveToAnotherRow(moveForward)) { | |||
++numSkippedRows; | |||
int numMovedRows = 0; | |||
while((numMovedRows < numRows) && moveToAnotherRow(moveForward)) { | |||
++numMovedRows; | |||
} | |||
return numSkippedRows; | |||
return numMovedRows; | |||
} | |||
/** | |||
@@ -653,7 +653,13 @@ public abstract class Cursor implements Iterable<Map<String, Object>> | |||
protected boolean isUpToDate() { | |||
return _rowState.isUpToDate(); | |||
} | |||
@Override | |||
public String toString() { | |||
return getClass().getSimpleName() + " CurPosition " + _curPos + | |||
", PrevPosition " + _prevPos; | |||
} | |||
/** | |||
* Finds the next non-deleted row after the given row (as defined by this | |||
* cursor) and returns the id of the row, where "next" may be backwards if | |||
@@ -671,12 +677,6 @@ public abstract class Cursor implements Iterable<Map<String, Object>> | |||
*/ | |||
protected abstract DirHandler getDirHandler(boolean moveForward); | |||
@Override | |||
public String toString() { | |||
return getClass().getSimpleName() + " CurPosition " + _curPos + | |||
", PrevPosition " + _prevPos; | |||
} | |||
/** | |||
* Row iterator for this table, supports modification. | |||
*/ | |||
@@ -1087,6 +1087,11 @@ public abstract class Cursor implements Iterable<Map<String, Object>> | |||
protected Position() { | |||
} | |||
@Override | |||
public final int hashCode() { | |||
return getRowId().hashCode(); | |||
} | |||
@Override | |||
public final boolean equals(Object o) { | |||
return((this == o) || |
@@ -984,6 +984,11 @@ public class Index implements Comparable<Index> { | |||
return ("RowId = " + _rowId + ", Columns = " + _entryColumns + "\n"); | |||
} | |||
@Override | |||
public int hashCode() { | |||
return _rowId.hashCode(); | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
return((this == o) || | |||
@@ -1042,7 +1047,7 @@ public class Index implements Comparable<Index> { | |||
cmp = 1; | |||
invalid = other; | |||
} | |||
return (cmp * (invalid.equals(FIRST_ENTRY.getRowId()) ? 1 : -1)); | |||
return (cmp * (invalid.equals(FIRST_ENTRY) ? 1 : -1)); | |||
} | |||
@@ -1097,13 +1102,6 @@ public class Index implements Comparable<Index> { | |||
} | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
return((this == o) || | |||
((o != null) && (o != null) && (getClass() == o.getClass()) && | |||
(compareTo((EntryColumn)o) == 0))); | |||
} | |||
/** | |||
* Write this non-null entry column to a buffer | |||
*/ | |||
@@ -1455,7 +1453,6 @@ public class Index implements Comparable<Index> { | |||
} | |||
protected void reset(boolean moveForward) { | |||
DirHandler handler = getDirHandler(moveForward); | |||
_curPos = getDirHandler(moveForward).getBeginningPosition(); | |||
_prevPos = _curPos; | |||
_lastModCount = Index.this._modCount; | |||
@@ -1551,9 +1548,9 @@ public class Index implements Comparable<Index> { | |||
curIdx = missingIndexToInsertionPoint(idx); | |||
between = true; | |||
} | |||
} else if(rowId.equals(RowId.FIRST_ROW_ID)) { | |||
} else if(entry.equals(FIRST_ENTRY)) { | |||
curIdx = FIRST_ENTRY_IDX; | |||
} else if(rowId.equals(RowId.LAST_ROW_ID)) { | |||
} else if(entry.equals(LAST_ENTRY)) { | |||
curIdx = LAST_ENTRY_IDX; | |||
} else { | |||
throw new IllegalArgumentException("Invalid entry given: " + entry); | |||
@@ -1693,6 +1690,11 @@ public class Index implements Comparable<Index> { | |||
return _between; | |||
} | |||
@Override | |||
public int hashCode() { | |||
return _entry.hashCode(); | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
return((this == o) || |
@@ -784,7 +784,7 @@ public class UsageMap | |||
* After calling this method, getNextPage will return the first page in | |||
* the map | |||
*/ | |||
public final void reset() { | |||
public void reset() { | |||
beforeFirst(); | |||
} | |||
@@ -120,30 +120,36 @@ public class CursorTest extends TestCase { | |||
assertEquals(expectedRows, foundRows); | |||
} | |||
public void testSkip() throws Exception { | |||
public void testMove() throws Exception { | |||
Database db = createTestTable(); | |||
Table table = db.getTable("test"); | |||
Cursor cursor = Cursor.createCursor(table); | |||
doTestSkip(table, cursor); | |||
doTestMove(table, cursor); | |||
db.close(); | |||
} | |||
private void doTestSkip(Table table, Cursor cursor) throws Exception { | |||
private void doTestMove(Table table, Cursor cursor) throws Exception { | |||
List<Map<String,Object>> expectedRows = createTestTableData(); | |||
expectedRows.subList(1, 4).clear(); | |||
List<Map<String, Object>> foundRows = | |||
new ArrayList<Map<String, Object>>(); | |||
assertTrue(cursor.isBeforeFirst()); | |||
assertFalse(cursor.isAfterLast()); | |||
foundRows.add(cursor.getNextRow()); | |||
assertEquals(3, cursor.skipNextRows(3)); | |||
assertEquals(3, cursor.moveNextRows(3)); | |||
assertFalse(cursor.isBeforeFirst()); | |||
assertFalse(cursor.isAfterLast()); | |||
while(cursor.moveToNextRow()) { | |||
foundRows.add(cursor.getCurrentRow()); | |||
} | |||
assertEquals(expectedRows, foundRows); | |||
assertFalse(cursor.isBeforeFirst()); | |||
assertTrue(cursor.isAfterLast()); | |||
assertEquals(0, cursor.skipNextRows(3)); | |||
assertEquals(0, cursor.moveNextRows(3)); | |||
} | |||
public void testSearch() throws Exception { | |||
@@ -222,8 +228,8 @@ public class CursorTest extends TestCase { | |||
Cursor cursor1, | |||
Cursor cursor2) throws Exception | |||
{ | |||
cursor1.skipNextRows(11); | |||
cursor2.skipNextRows(11); | |||
cursor1.moveNextRows(11); | |||
cursor2.moveNextRows(11); | |||
assertTrue(cursor1.isAfterLast()); | |||
assertTrue(cursor2.isAfterLast()); | |||
@@ -265,10 +271,10 @@ public class CursorTest extends TestCase { | |||
Cursor cursor3, | |||
Cursor cursor4) throws Exception | |||
{ | |||
cursor1.skipNextRows(2); | |||
cursor2.skipNextRows(3); | |||
cursor3.skipNextRows(3); | |||
cursor4.skipNextRows(4); | |||
cursor1.moveNextRows(2); | |||
cursor2.moveNextRows(3); | |||
cursor3.moveNextRows(3); | |||
cursor4.moveNextRows(4); | |||
Map<String,Object> expectedPrevRow = | |||
createExpectedRow("id", 1, "value", "data" + 1); | |||
@@ -309,13 +315,13 @@ public class CursorTest extends TestCase { | |||
db.close(); | |||
} | |||
public void testSkipIndex() throws Exception { | |||
public void testMoveIndex() throws Exception { | |||
Database db = createTestIndexTable(); | |||
Table table = db.getTable("test"); | |||
Index idx = table.getIndexes().get(0); | |||
Cursor cursor = Cursor.createIndexCursor(table, idx); | |||
doTestSkip(table, cursor); | |||
doTestMove(table, cursor); | |||
db.close(); | |||
} |