3030import java .util .ArrayList ;
3131import java .util .HashSet ;
3232import java .util .List ;
33+ import java .util .Optional ;
3334import java .util .Set ;
3435import java .util .concurrent .atomic .AtomicLong ;
36+ import java .util .stream .Collectors ;
3537
3638import static org .hamcrest .MatcherAssert .assertThat ;
3739import static org .hamcrest .Matchers .*;
@@ -60,6 +62,15 @@ public void first() {
6062 assertThat (first .getAsLong (), is (0L ));
6163 }
6264
65+ @ Test
66+ public void firstStream () {
67+ final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
68+ final Optional <VPackSlice > first = cursor .stream ().findFirst ();
69+ assertThat (first .isPresent (), is (true ));
70+ assertThat (first .get ().isInteger (), is (true ));
71+ assertThat (first .get ().getAsLong (), is (0L ));
72+ }
73+
6374 @ Test
6475 public void next () {
6576
@@ -78,6 +89,13 @@ public void mapFilterCount() {
7889 assertThat (count , is (50L ));
7990 }
8091
92+ @ Test
93+ public void mapFilterCountStream () {
94+ final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
95+ final long count = cursor .stream ().map (VPackSlice ::getAsLong ).filter (t -> t < 50 ).count ();
96+ assertThat (count , is (50L ));
97+ }
98+
8199 @ Test
82100 public void mapMapFilterCount () {
83101 final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
@@ -122,34 +140,70 @@ public void mapFilterCollectIntoSet() {
122140 assertThat (target .size (), is (50 ));
123141 }
124142
143+ @ Test
144+ public void mapFilterCollectIntoSetStream () {
145+ final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
146+ final Set <Long > target = cursor .stream ().map (VPackSlice ::getAsLong ).filter (t -> t < 50 ).collect (Collectors .toSet ());
147+ assertThat (target , is (not (nullValue ())));
148+ assertThat (target .size (), is (50 ));
149+ }
150+
125151 @ Test
126152 public void foreach () {
127153 final AtomicLong i = new AtomicLong (0L );
128154 final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
129155 cursor .foreach (t -> assertThat (t .getAsLong (), is (i .getAndIncrement ())));
130156 }
131157
158+ @ Test
159+ public void forEach () {
160+ final AtomicLong i = new AtomicLong (0L );
161+ final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
162+ cursor .forEach (t -> assertThat (t .getAsLong (), is (i .getAndIncrement ())));
163+ }
164+
132165 @ Test
133166 public void mapForeach () {
134167 final AtomicLong i = new AtomicLong (0L );
135168 final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
136169 cursor .map (VPackSlice ::getAsLong ).foreach (t -> assertThat (t , is (i .getAndIncrement ())));
137170 }
138171
172+ @ Test
173+ public void mapForeachStream () {
174+ final AtomicLong i = new AtomicLong (0L );
175+ final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
176+ cursor .stream ().map (VPackSlice ::getAsLong ).forEach (t -> assertThat (t , is (i .getAndIncrement ())));
177+ }
178+
139179 @ Test
140180 public void mapFilterForeach () {
141181 final AtomicLong i = new AtomicLong (0L );
142182 final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
143183 cursor .map (VPackSlice ::getAsLong ).filter (t -> t < 50 ).foreach (t -> assertThat (t , is (i .getAndIncrement ())));
144184 }
145185
186+ @ Test
187+ public void mapFilterForEachStream () {
188+ final AtomicLong i = new AtomicLong (0L );
189+ final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
190+ cursor .stream ().map (VPackSlice ::getAsLong ).filter (t -> t < 50 ).forEach (t -> assertThat (t , is (i .getAndIncrement ())));
191+ }
192+
146193 @ Test
147194 public void anyMatch () {
148195 final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
149196 final boolean match = cursor .anyMatch (t -> t .getAsLong () == 50L );
150197 assertThat (match , is (true ));
151198 }
152199
200+ @ Test
201+ public void anyMatchStream () {
202+ final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
203+ final boolean match = cursor .stream ().anyMatch (t -> t .getAsLong () == 50L );
204+ assertThat (match , is (true ));
205+ }
206+
153207 @ Test
154208 public void mapAnyMatch () {
155209 final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
@@ -171,6 +225,13 @@ public void noneMatch() {
171225 assertThat (match , is (true ));
172226 }
173227
228+ @ Test
229+ public void noneMatchStream () {
230+ final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
231+ final boolean match = cursor .stream ().noneMatch (t -> t .getAsLong () == 100L );
232+ assertThat (match , is (true ));
233+ }
234+
174235 @ Test
175236 public void mapNoneMatch () {
176237 final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
@@ -192,6 +253,13 @@ public void allMatch() {
192253 assertThat (match , is (true ));
193254 }
194255
256+ @ Test
257+ public void allMatchStream () {
258+ final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
259+ final boolean match = cursor .stream ().allMatch (t -> t .getAsLong () < 100L );
260+ assertThat (match , is (true ));
261+ }
262+
195263 @ Test
196264 public void mapAllMatch () {
197265 final ArangoCursor <VPackSlice > cursor = db .query ("FOR i IN 0..99 RETURN i" , VPackSlice .class );
0 commit comments