Skip to content

Commit 95dd395

Browse files
committed
refactoring: ArangoCursor default methods
1 parent 2954d71 commit 95dd395

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

core/src/main/java/com/arangodb/ArangoCursor.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import com.arangodb.entity.CursorStats;
2424
import com.arangodb.entity.CursorWarning;
2525
import com.arangodb.model.AqlQueryOptions;
26+
import org.slf4j.LoggerFactory;
2627

2728
import java.io.Closeable;
29+
import java.util.ArrayList;
2830
import java.util.Collection;
2931
import java.util.List;
3032
import java.util.NoSuchElementException;
@@ -70,7 +72,18 @@ public interface ArangoCursor<T> extends ArangoIterable<T>, ArangoIterator<T>, C
7072
/**
7173
* @return the remaining results as a {@code List}
7274
*/
73-
List<T> asListRemaining();
75+
default List<T> asListRemaining() {
76+
final List<T> remaining = new ArrayList<>();
77+
while (hasNext()) {
78+
remaining.add(next());
79+
}
80+
try {
81+
close();
82+
} catch (final Exception e) {
83+
LoggerFactory.getLogger(ArangoCursor.class).warn("Could not close cursor: ", e);
84+
}
85+
return remaining;
86+
}
7487

7588
/**
7689
* @return true if the result is a potential dirty read

core/src/main/java/com/arangodb/ArangoIterable.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.arangodb;
2222

2323
import java.util.stream.Stream;
24+
import java.util.stream.StreamSupport;
2425

2526
/**
2627
* @author Mark Vollmary
@@ -30,6 +31,8 @@ public interface ArangoIterable<T> extends Iterable<T> {
3031
@Override
3132
ArangoIterator<T> iterator();
3233

33-
Stream<T> stream();
34+
default Stream<T> stream() {
35+
return StreamSupport.stream(spliterator(), false);
36+
}
3437

3538
}

core/src/main/java/com/arangodb/internal/cursor/ArangoCursorImpl.java

-25
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,15 @@
2828
import com.arangodb.internal.InternalArangoDatabase;
2929
import com.arangodb.internal.cursor.entity.InternalCursorEntity;
3030
import com.fasterxml.jackson.databind.JsonNode;
31-
import org.slf4j.Logger;
32-
import org.slf4j.LoggerFactory;
3331

34-
import java.util.ArrayList;
3532
import java.util.Collection;
3633
import java.util.Iterator;
3734
import java.util.NoSuchElementException;
38-
import java.util.List;
39-
import java.util.stream.Stream;
40-
import java.util.stream.StreamSupport;
4135

4236
/**
4337
* @author Mark Vollmary
4438
*/
4539
public class ArangoCursorImpl<T> implements ArangoCursor<T> {
46-
private final static Logger LOG = LoggerFactory.getLogger(ArangoCursorImpl.class);
4740

4841
protected final ArangoCursorIterator<T> iterator;
4942
private final Class<T> type;
@@ -113,20 +106,6 @@ public boolean hasNext() {
113106
return iterator.hasNext();
114107
}
115108

116-
@Override
117-
public List<T> asListRemaining() {
118-
final List<T> remaining = new ArrayList<>();
119-
while (hasNext()) {
120-
remaining.add(next());
121-
}
122-
try {
123-
close();
124-
} catch (final Exception e) {
125-
LOG.warn("Could not close cursor: ", e);
126-
}
127-
return remaining;
128-
}
129-
130109
@Override
131110
public boolean isPotentialDirtyRead() {
132111
return pontentialDirtyRead;
@@ -146,10 +125,6 @@ protected ArangoCursorExecute getExecute() {
146125
return execute;
147126
}
148127

149-
public Stream<T> stream() {
150-
return StreamSupport.stream(spliterator(), false);
151-
}
152-
153128
protected static class ArangoCursorIterator<T> implements ArangoIterator<T> {
154129
private final String cursorId;
155130
private final Class<T> type;

0 commit comments

Comments
 (0)