From ffce296621efb35505b889c75d3cd326bda85d66 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 11 May 2008 15:38:06 +0000 Subject: Simplify and fix count calculation. --- src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java | 10 ++++++---- src/main/java/com/amazon/carbonado/cursor/SingletonCursor.java | 3 +-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main/java') 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 implements Cursor { public int copyInto(Collection 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 implements Cursor { public int copyInto(Collection 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 implements Cursor { if (object == null) { return 0; } - int originalSize = c.size(); c.add(object); - return originalSize + 1; + return 1; } public int copyInto(Collection c, int limit) { -- cgit v1.2.3