diff options
Diffstat (limited to 'src/main/java/com/amazon/carbonado/cursor')
10 files changed, 166 insertions, 201 deletions
diff --git a/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java b/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java index cf64a24..fb34617 100644 --- a/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/AbstractCursor.java @@ -64,10 +64,7 @@ public abstract class AbstractCursor<S> implements Cursor<S> { return list;
}
- public synchronized int skipNext(int amount) throws FetchException {
- // This method is synchronized to avoid potential race conditions
- // between calls to hasNext and next in the loop below.
-
+ public int skipNext(int amount) throws FetchException {
if (amount <= 0) {
if (amount < 0) {
throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
diff --git a/src/main/java/com/amazon/carbonado/cursor/DifferenceCursor.java b/src/main/java/com/amazon/carbonado/cursor/DifferenceCursor.java index 39455c8..8b330ea 100644 --- a/src/main/java/com/amazon/carbonado/cursor/DifferenceCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/DifferenceCursor.java @@ -59,14 +59,14 @@ public class DifferenceCursor<S> extends AbstractCursor<S> { mOrder = order;
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mLeftCursor.close();
mRightCursor.close();
mNext = null;
mNextRight = null;
}
- public synchronized boolean hasNext() throws FetchException {
+ public boolean hasNext() throws FetchException {
if (mNext != null) {
return true;
}
@@ -109,7 +109,7 @@ public class DifferenceCursor<S> extends AbstractCursor<S> { }
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
if (hasNext()) {
S next = mNext;
mNext = null;
diff --git a/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java b/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java index 60b3c81..f426f36 100644 --- a/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/FilteredCursor.java @@ -82,61 +82,53 @@ public abstract class FilteredCursor<S> extends AbstractCursor<S> { protected abstract boolean isAllowed(S storable);
public void close() throws FetchException {
- synchronized (mCursor) {
- mCursor.close();
- mNext = null;
- }
+ mCursor.close();
+ mNext = null;
}
public boolean hasNext() throws FetchException {
- synchronized (mCursor) {
- if (mNext != null) {
- return true;
- }
- try {
- int count = 0;
- while (mCursor.hasNext()) {
- S next = mCursor.next();
- if (isAllowed(next)) {
- mNext = next;
- return true;
- }
- interruptCheck(++count);
+ if (mNext != null) {
+ return true;
+ }
+ try {
+ int count = 0;
+ while (mCursor.hasNext()) {
+ S next = mCursor.next();
+ if (isAllowed(next)) {
+ mNext = next;
+ return true;
}
- } catch (NoSuchElementException e) {
+ interruptCheck(++count);
}
- return false;
+ } catch (NoSuchElementException e) {
}
+ return false;
}
public S next() throws FetchException {
- synchronized (mCursor) {
- if (hasNext()) {
- S next = mNext;
- mNext = null;
- return next;
- }
- throw new NoSuchElementException();
+ if (hasNext()) {
+ S next = mNext;
+ mNext = null;
+ return next;
}
+ throw new NoSuchElementException();
}
public int skipNext(int amount) throws FetchException {
- synchronized (mCursor) {
- if (amount <= 0) {
- if (amount < 0) {
- throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
- }
- return 0;
- }
-
- int count = 0;
- while (--amount >= 0 && hasNext()) {
- interruptCheck(++count);
- mNext = null;
+ if (amount <= 0) {
+ if (amount < 0) {
+ throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
}
+ return 0;
+ }
- return count;
+ int count = 0;
+ while (--amount >= 0 && hasNext()) {
+ interruptCheck(++count);
+ mNext = null;
}
+
+ return count;
}
private void interruptCheck(int count) throws FetchException {
diff --git a/src/main/java/com/amazon/carbonado/cursor/GroupedCursor.java b/src/main/java/com/amazon/carbonado/cursor/GroupedCursor.java index 0b17e50..bf838b1 100644 --- a/src/main/java/com/amazon/carbonado/cursor/GroupedCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/GroupedCursor.java @@ -113,87 +113,79 @@ public abstract class GroupedCursor<S, G> extends AbstractCursor<G> { protected abstract G finishGroup() throws FetchException;
public void close() throws FetchException {
- synchronized (mCursor) {
- mCursor.close();
- mGroupLeader = null;
- mNextAggregate = null;
- }
+ mCursor.close();
+ mGroupLeader = null;
+ mNextAggregate = null;
}
public boolean hasNext() throws FetchException {
- synchronized (mCursor) {
- if (mNextAggregate != null) {
- return true;
- }
+ if (mNextAggregate != null) {
+ return true;
+ }
- try {
- int count = 0;
- if (mCursor.hasNext()) {
- if (mGroupLeader == null) {
- beginGroup(mGroupLeader = mCursor.next());
- }
+ try {
+ int count = 0;
+ if (mCursor.hasNext()) {
+ if (mGroupLeader == null) {
+ beginGroup(mGroupLeader = mCursor.next());
+ }
- while (mCursor.hasNext()) {
- S groupMember = mCursor.next();
+ while (mCursor.hasNext()) {
+ S groupMember = mCursor.next();
- if (mGroupComparator.compare(mGroupLeader, groupMember) == 0) {
- addToGroup(groupMember);
- } else {
- G aggregate = finishGroup();
+ if (mGroupComparator.compare(mGroupLeader, groupMember) == 0) {
+ addToGroup(groupMember);
+ } else {
+ G aggregate = finishGroup();
- beginGroup(mGroupLeader = groupMember);
+ beginGroup(mGroupLeader = groupMember);
- if (aggregate != null) {
- mNextAggregate = aggregate;
- return true;
- }
+ if (aggregate != null) {
+ mNextAggregate = aggregate;
+ return true;
}
-
- interruptCheck(++count);
}
- G aggregate = finishGroup();
+ interruptCheck(++count);
+ }
- if (aggregate != null) {
- mNextAggregate = aggregate;
- return true;
- }
+ G aggregate = finishGroup();
+
+ if (aggregate != null) {
+ mNextAggregate = aggregate;
+ return true;
}
- } catch (NoSuchElementException e) {
}
-
- return false;
+ } catch (NoSuchElementException e) {
}
+
+ return false;
}
public G next() throws FetchException {
- synchronized (mCursor) {
- if (hasNext()) {
- G next = mNextAggregate;
- mNextAggregate = null;
- return next;
- }
- throw new NoSuchElementException();
+ if (hasNext()) {
+ G next = mNextAggregate;
+ mNextAggregate = null;
+ return next;
}
+ throw new NoSuchElementException();
}
public int skipNext(int amount) throws FetchException {
- synchronized (mCursor) {
- if (amount <= 0) {
- if (amount < 0) {
- throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
- }
- return 0;
- }
-
- int count = 0;
- while (--amount >= 0 && hasNext()) {
- interruptCheck(++count);
- mNextAggregate = null;
+ if (amount <= 0) {
+ if (amount < 0) {
+ throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
}
+ return 0;
+ }
- return count;
+ int count = 0;
+ while (--amount >= 0 && hasNext()) {
+ interruptCheck(++count);
+ mNextAggregate = null;
}
+
+ return count;
}
private void interruptCheck(int count) throws FetchException {
diff --git a/src/main/java/com/amazon/carbonado/cursor/IntersectionCursor.java b/src/main/java/com/amazon/carbonado/cursor/IntersectionCursor.java index 9d11b2f..58aba0d 100644 --- a/src/main/java/com/amazon/carbonado/cursor/IntersectionCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/IntersectionCursor.java @@ -58,13 +58,13 @@ public class IntersectionCursor<S> extends AbstractCursor<S> { mOrder = order;
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mLeftCursor.close();
mRightCursor.close();
mNext = null;
}
- public synchronized boolean hasNext() throws FetchException {
+ public boolean hasNext() throws FetchException {
if (mNext != null) {
return true;
}
@@ -107,7 +107,7 @@ public class IntersectionCursor<S> extends AbstractCursor<S> { }
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
if (hasNext()) {
S next = mNext;
mNext = null;
diff --git a/src/main/java/com/amazon/carbonado/cursor/MultiTransformedCursor.java b/src/main/java/com/amazon/carbonado/cursor/MultiTransformedCursor.java index 0cfd197..feeb414 100644 --- a/src/main/java/com/amazon/carbonado/cursor/MultiTransformedCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/MultiTransformedCursor.java @@ -54,73 +54,65 @@ public abstract class MultiTransformedCursor<S, T> extends AbstractCursor<T> { protected abstract Cursor<T> transform(S storable) throws FetchException;
public void close() throws FetchException {
- synchronized (mCursor) {
- mCursor.close();
- if (mNextCursor != null) {
- mNextCursor.close();
- mNextCursor = null;
- }
+ mCursor.close();
+ if (mNextCursor != null) {
+ mNextCursor.close();
+ mNextCursor = null;
}
}
public boolean hasNext() throws FetchException {
- synchronized (mCursor) {
- if (mNextCursor != null) {
- if (mNextCursor.hasNext()) {
- return true;
- }
- mNextCursor.close();
- mNextCursor = null;
+ if (mNextCursor != null) {
+ if (mNextCursor.hasNext()) {
+ return true;
}
- try {
- int count = 0;
- while (mCursor.hasNext()) {
- Cursor<T> nextCursor = transform(mCursor.next());
- if (nextCursor != null) {
- if (nextCursor.hasNext()) {
- mNextCursor = nextCursor;
- return true;
- }
- nextCursor.close();
+ mNextCursor.close();
+ mNextCursor = null;
+ }
+ try {
+ int count = 0;
+ while (mCursor.hasNext()) {
+ Cursor<T> nextCursor = transform(mCursor.next());
+ if (nextCursor != null) {
+ if (nextCursor.hasNext()) {
+ mNextCursor = nextCursor;
+ return true;
}
- interruptCheck(++count);
+ nextCursor.close();
}
- } catch (NoSuchElementException e) {
+ interruptCheck(++count);
}
- return false;
+ } catch (NoSuchElementException e) {
}
+ return false;
}
public T next() throws FetchException {
- synchronized (mCursor) {
- if (hasNext()) {
- return mNextCursor.next();
- }
- throw new NoSuchElementException();
+ if (hasNext()) {
+ return mNextCursor.next();
}
+ throw new NoSuchElementException();
}
public int skipNext(int amount) throws FetchException {
- synchronized (mCursor) {
- if (amount <= 0) {
- if (amount < 0) {
- throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
- }
- return 0;
+ if (amount <= 0) {
+ if (amount < 0) {
+ throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
}
+ return 0;
+ }
- int count = 0;
- while (hasNext()) {
- int chunk = mNextCursor.skipNext(amount);
- count += chunk;
- if ((amount -= chunk) <= 0) {
- break;
- }
- interruptCheck(count);
+ int count = 0;
+ while (hasNext()) {
+ int chunk = mNextCursor.skipNext(amount);
+ count += chunk;
+ if ((amount -= chunk) <= 0) {
+ break;
}
-
- return count;
+ interruptCheck(count);
}
+
+ return count;
}
private void interruptCheck(int count) throws FetchException {
diff --git a/src/main/java/com/amazon/carbonado/cursor/SortedCursor.java b/src/main/java/com/amazon/carbonado/cursor/SortedCursor.java index 7a728bb..9cee89b 100644 --- a/src/main/java/com/amazon/carbonado/cursor/SortedCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/SortedCursor.java @@ -198,13 +198,13 @@ public class SortedCursor<S> extends AbstractCursor<S> { };
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mCursor.close();
mChunkIterator = null;
mChunkBuffer.close();
}
- public synchronized boolean hasNext() throws FetchException {
+ public boolean hasNext() throws FetchException {
prepareNextChunk();
try {
if (mChunkIterator.hasNext()) {
@@ -217,7 +217,7 @@ public class SortedCursor<S> extends AbstractCursor<S> { return false;
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
prepareNextChunk();
try {
return mChunkIterator.next();
@@ -233,7 +233,7 @@ public class SortedCursor<S> extends AbstractCursor<S> { }
}
- public synchronized int skipNext(int amount) throws FetchException {
+ public int skipNext(int amount) throws FetchException {
if (amount <= 0) {
if (amount < 0) {
throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
diff --git a/src/main/java/com/amazon/carbonado/cursor/SymmetricDifferenceCursor.java b/src/main/java/com/amazon/carbonado/cursor/SymmetricDifferenceCursor.java index 6851464..1f94e30 100644 --- a/src/main/java/com/amazon/carbonado/cursor/SymmetricDifferenceCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/SymmetricDifferenceCursor.java @@ -60,7 +60,7 @@ public class SymmetricDifferenceCursor<S> extends AbstractCursor<S> { mOrder = order;
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mLeftCursor.close();
mRightCursor.close();
mNextLeft = null;
@@ -76,7 +76,7 @@ public class SymmetricDifferenceCursor<S> extends AbstractCursor<S> { * left source cursor, and >0 if next element is from right source
* cursor.
*/
- public synchronized int compareNext() throws FetchException {
+ public int compareNext() throws FetchException {
if (mCompareResult != 0) {
return mCompareResult;
}
@@ -105,7 +105,7 @@ public class SymmetricDifferenceCursor<S> extends AbstractCursor<S> { }
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
S next;
int result = compareNext();
if (result < 0) {
diff --git a/src/main/java/com/amazon/carbonado/cursor/TransformedCursor.java b/src/main/java/com/amazon/carbonado/cursor/TransformedCursor.java index 0860cf0..9f9efe7 100644 --- a/src/main/java/com/amazon/carbonado/cursor/TransformedCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/TransformedCursor.java @@ -53,61 +53,53 @@ public abstract class TransformedCursor<S, T> extends AbstractCursor<T> { protected abstract T transform(S storable) throws FetchException;
public void close() throws FetchException {
- synchronized (mCursor) {
- mCursor.close();
- mNext = null;
- }
+ mCursor.close();
+ mNext = null;
}
public boolean hasNext() throws FetchException {
- synchronized (mCursor) {
- if (mNext != null) {
- return true;
- }
- try {
- int count = 0;
- while (mCursor.hasNext()) {
- T next = transform(mCursor.next());
- if (next != null) {
- mNext = next;
- return true;
- }
- interruptCheck(++count);
+ if (mNext != null) {
+ return true;
+ }
+ try {
+ int count = 0;
+ while (mCursor.hasNext()) {
+ T next = transform(mCursor.next());
+ if (next != null) {
+ mNext = next;
+ return true;
}
- } catch (NoSuchElementException e) {
+ interruptCheck(++count);
}
- return false;
+ } catch (NoSuchElementException e) {
}
+ return false;
}
public T next() throws FetchException {
- synchronized (mCursor) {
- if (hasNext()) {
- T next = mNext;
- mNext = null;
- return next;
- }
- throw new NoSuchElementException();
+ if (hasNext()) {
+ T next = mNext;
+ mNext = null;
+ return next;
}
+ throw new NoSuchElementException();
}
public int skipNext(int amount) throws FetchException {
- synchronized (mCursor) {
- if (amount <= 0) {
- if (amount < 0) {
- throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
- }
- return 0;
- }
-
- int count = 0;
- while (--amount >= 0 && hasNext()) {
- interruptCheck(++count);
- mNext = null;
+ if (amount <= 0) {
+ if (amount < 0) {
+ throw new IllegalArgumentException("Cannot skip negative amount: " + amount);
}
+ return 0;
+ }
- return count;
+ int count = 0;
+ while (--amount >= 0 && hasNext()) {
+ interruptCheck(++count);
+ mNext = null;
}
+
+ return count;
}
private void interruptCheck(int count) throws FetchException {
diff --git a/src/main/java/com/amazon/carbonado/cursor/UnionCursor.java b/src/main/java/com/amazon/carbonado/cursor/UnionCursor.java index 7a62678..7e4fde3 100644 --- a/src/main/java/com/amazon/carbonado/cursor/UnionCursor.java +++ b/src/main/java/com/amazon/carbonado/cursor/UnionCursor.java @@ -59,14 +59,14 @@ public class UnionCursor<S> extends AbstractCursor<S> { mOrder = order;
}
- public synchronized void close() throws FetchException {
+ public void close() throws FetchException {
mLeftCursor.close();
mRightCursor.close();
mNextLeft = null;
mNextRight = null;
}
- public synchronized boolean hasNext() throws FetchException {
+ public boolean hasNext() throws FetchException {
if (mNextLeft == null && mLeftCursor.hasNext()) {
mNextLeft = mLeftCursor.next();
}
@@ -76,7 +76,7 @@ public class UnionCursor<S> extends AbstractCursor<S> { return mNextLeft != null || mNextRight != null;
}
- public synchronized S next() throws FetchException {
+ public S next() throws FetchException {
if (hasNext()) {
S next;
if (mNextLeft == null) {
|