diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2007-11-29 15:11:08 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2007-11-29 15:11:08 +0000 |
commit | ff8135d7a347bace914dbb4b8a7d4393d00b2bbf (patch) | |
tree | 096c839195eece68ccfb1b866caed8483093d727 | |
parent | 286378cc0c135252bac0fc31f861fe21f8bfe77b (diff) | |
download | jackcess-ff8135d7a347bace914dbb4b8a7d4393d00b2bbf.tar.gz jackcess-ff8135d7a347bace914dbb4b8a7d4393d00b2bbf.zip |
rename skip methods; minor code cleanups
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@190 f203690c-595d-4dc9-a70b-905162fa7fd2
4 files changed, 60 insertions, 47 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Cursor.java b/src/java/com/healthmarketscience/jackcess/Cursor.java index 1838be7..901019c 100644 --- a/src/java/com/healthmarketscience/jackcess/Cursor.java +++ b/src/java/com/healthmarketscience/jackcess/Cursor.java @@ -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. */ @@ -1088,6 +1088,11 @@ public abstract class Cursor implements Iterable<Map<String, Object>> } @Override + public final int hashCode() { + return getRowId().hashCode(); + } + + @Override public final boolean equals(Object o) { return((this == o) || ((o != null) && (getClass() == o.getClass()) && equalsImpl(o))); diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java index 11d6330..fcfade3 100644 --- a/src/java/com/healthmarketscience/jackcess/Index.java +++ b/src/java/com/healthmarketscience/jackcess/Index.java @@ -985,6 +985,11 @@ public class Index implements Comparable<Index> { } @Override + public int hashCode() { + return _rowId.hashCode(); + } + + @Override public boolean equals(Object o) { return((this == o) || ((o != null) && (getClass() == o.getClass()) && @@ -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); @@ -1694,6 +1691,11 @@ public class Index implements Comparable<Index> { } @Override + public int hashCode() { + return _entry.hashCode(); + } + + @Override public boolean equals(Object o) { return((this == o) || ((o != null) && (getClass() == o.getClass()) && diff --git a/src/java/com/healthmarketscience/jackcess/UsageMap.java b/src/java/com/healthmarketscience/jackcess/UsageMap.java index 4b1c76d..231267a 100644 --- a/src/java/com/healthmarketscience/jackcess/UsageMap.java +++ b/src/java/com/healthmarketscience/jackcess/UsageMap.java @@ -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(); } diff --git a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java index d10d2b7..c87b29e 100644 --- a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java @@ -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(); } |