}
/**
- * 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;
}
/**
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
*/
protected abstract DirHandler getDirHandler(boolean moveForward);
- @Override
- public String toString() {
- return getClass().getSimpleName() + " CurPosition " + _curPos +
- ", PrevPosition " + _prevPos;
- }
-
/**
* Row iterator for this table, supports modification.
*/
protected Position() {
}
+ @Override
+ public final int hashCode() {
+ return getRowId().hashCode();
+ }
+
@Override
public final boolean equals(Object o) {
return((this == o) ||
return ("RowId = " + _rowId + ", Columns = " + _entryColumns + "\n");
}
+ @Override
+ public int hashCode() {
+ return _rowId.hashCode();
+ }
+
@Override
public boolean equals(Object o) {
return((this == o) ||
cmp = 1;
invalid = other;
}
- return (cmp * (invalid.equals(FIRST_ENTRY.getRowId()) ? 1 : -1));
+ return (cmp * (invalid.equals(FIRST_ENTRY) ? 1 : -1));
}
}
}
- @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
*/
}
protected void reset(boolean moveForward) {
- DirHandler handler = getDirHandler(moveForward);
_curPos = getDirHandler(moveForward).getBeginningPosition();
_prevPos = _curPos;
_lastModCount = Index.this._modCount;
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);
return _between;
}
+ @Override
+ public int hashCode() {
+ return _entry.hashCode();
+ }
+
@Override
public boolean equals(Object o) {
return((this == o) ||
* After calling this method, getNextPage will return the first page in
* the map
*/
- public final void reset() {
+ public void reset() {
beforeFirst();
}
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 {
Cursor cursor1,
Cursor cursor2) throws Exception
{
- cursor1.skipNextRows(11);
- cursor2.skipNextRows(11);
+ cursor1.moveNextRows(11);
+ cursor2.moveNextRows(11);
assertTrue(cursor1.isAfterLast());
assertTrue(cursor2.isAfterLast());
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);
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();
}