summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-05-11 15:38:06 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-05-11 15:38:06 +0000
commitffce296621efb35505b889c75d3cd326bda85d66 (patch)
tree2502b1cb6813089e6fef0255695e977a5586eb64
parente82efda6a2f6571bf14a0c43412e33b00143123b (diff)
Simplify and fix count calculation.
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java10
-rw-r--r--src/main/java/com/amazon/carbonado/cursor/SingletonCursor.java3
2 files changed, 7 insertions, 6 deletions
diff --git a/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java b/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java
index 5fb0fa8..9a31412 100644
--- a/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java
@@ -38,11 +38,12 @@ public abstract class AbstractCursor<S> implements Cursor<S> {
public int copyInto(Collection<? super S> c) throws FetchException {
try {
- int originalSize = c.size();
+ int count = 0;
while (hasNext()) {
c.add(next());
+ count++;
}
- return c.size() - originalSize;
+ return count;
} catch (FetchException e) {
try {
close();
@@ -55,11 +56,12 @@ public abstract class AbstractCursor<S> implements Cursor<S> {
public int copyInto(Collection<? super S> c, int limit) throws FetchException {
try {
- int originalSize = c.size();
+ int count = 0;
while (--limit >= 0 && hasNext()) {
c.add(next());
+ count++;
}
- return c.size() - originalSize;
+ return count;
} catch (FetchException e) {
try {
close();
diff --git a/src/main/java/com/amazon/carbonado/cursor/SingletonCursor.java b/src/main/java/com/amazon/carbonado/cursor/SingletonCursor.java
index 55b6cb6..f6cd142 100644
--- a/src/main/java/com/amazon/carbonado/cursor/SingletonCursor.java
+++ b/src/main/java/com/amazon/carbonado/cursor/SingletonCursor.java
@@ -80,9 +80,8 @@ public class SingletonCursor<S> implements Cursor<S> {
if (object == null) {
return 0;
}
- int originalSize = c.size();
c.add(object);
- return originalSize + 1;
+ return 1;
}
public int copyInto(Collection<? super S> c, int limit) {