From 94d02ed1f6c960db7bae229f3b3f0cbdb9ab4c9b Mon Sep 17 00:00:00 2001 From: Fatos Morina Date: Sat, 2 Sep 2017 10:42:24 +0200 Subject: [PATCH 1/2] BAEL-1078 How to iterate over a stream with indices (#2544) * Add the example with EntryStream * Add the example with EntryStream * Add vavr * Implement the method getOddIndexedStringsVersionTwo * Implement the method givenArray_whenGetIndexedStrings_thenReturnListOfOddStringsVersionTwo * BAEL-1078 Code formatting * Extract tuples using map * Fix merge conflicts --- .../com/baeldung/stream/StreamIndices.java | 58 ++++++++----------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/stream/StreamIndices.java b/core-java/src/main/java/com/baeldung/stream/StreamIndices.java index aa4da58818..34768a725a 100644 --- a/core-java/src/main/java/com/baeldung/stream/StreamIndices.java +++ b/core-java/src/main/java/com/baeldung/stream/StreamIndices.java @@ -1,6 +1,5 @@ package com.baeldung.stream; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -8,65 +7,56 @@ import java.util.stream.IntStream; import com.codepoetics.protonpack.Indexed; import com.codepoetics.protonpack.StreamUtils; -import io.vavr.Tuple2; import io.vavr.collection.Stream; import one.util.streamex.EntryStream; public class StreamIndices { public static List getEvenIndexedStrings(String[] names) { - List evenIndexedNames = IntStream - .range(0, names.length) - .filter(i -> i % 2 == 0) - .mapToObj(i -> names[i]) - .collect(Collectors.toList()); + List evenIndexedNames = IntStream.range(0, names.length) + .filter(i -> i % 2 == 0) + .mapToObj(i -> names[i]) + .collect(Collectors.toList()); return evenIndexedNames; } public List getEvenIndexedStringsVersionTwo(List names) { - List evenIndexedNames = EntryStream - .of(names) - .filterKeyValue((index, name) -> index % 2 == 0) - .values() - .toList(); + List evenIndexedNames = EntryStream.of(names) + .filterKeyValue((index, name) -> index % 2 == 0) + .values() + .toList(); return evenIndexedNames; } public static List> getEvenIndexedStrings(List names) { - List> list = StreamUtils - .zipWithIndex(names.stream()) - .filter(i -> i.getIndex() % 2 == 0) - .collect(Collectors.toList()); + List> list = StreamUtils.zipWithIndex(names.stream()) + .filter(i -> i.getIndex() % 2 == 0) + .collect(Collectors.toList()); return list; } public static List> getOddIndexedStrings(List names) { - List> list = StreamUtils - .zipWithIndex(names.stream()) - .filter(i -> i.getIndex() % 2 == 1) - .collect(Collectors.toList()); + List> list = StreamUtils.zipWithIndex(names.stream()) + .filter(i -> i.getIndex() % 2 == 1) + .collect(Collectors.toList()); return list; } public static List getOddIndexedStrings(String[] names) { - List oddIndexedNames = IntStream - .range(0, names.length) - .filter(i -> i % 2 == 1) - .mapToObj(i -> names[i]) - .collect(Collectors.toList()); + List oddIndexedNames = IntStream.range(0, names.length) + .filter(i -> i % 2 == 1) + .mapToObj(i -> names[i]) + .collect(Collectors.toList()); return oddIndexedNames; } public static List getOddIndexedStringsVersionTwo(String[] names) { - List> tuples = Stream - .of(names) - .zipWithIndex() - .filter(tuple -> tuple._2 % 2 == 1) - .toJavaList(); - List oddIndexedNames = new ArrayList(); - tuples.forEach(tuple -> { - oddIndexedNames.add(tuple._1); - }); + List oddIndexedNames = Stream.of(names) + .zipWithIndex() + .filter(tuple -> tuple._2 % 2 == 1) + .map(tuple -> tuple._1) + .toJavaList(); return oddIndexedNames; } + } \ No newline at end of file From 7262427421efd8e60dcad373f73bdda39d279625 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 2 Sep 2017 10:43:10 +0200 Subject: [PATCH 2/2] Version update 9 02 (#2547) * Update Hazelcast * Update Hbase * Update Immutables * Update Lombok --- hazelcast/pom.xml | 4 ++-- hbase/pom.xml | 2 +- immutables/pom.xml | 3 +-- json-path/pom.xml | 1 - lombok/pom.xml | 4 +--- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/hazelcast/pom.xml b/hazelcast/pom.xml index 5b467af655..2811bf8b12 100644 --- a/hazelcast/pom.xml +++ b/hazelcast/pom.xml @@ -22,7 +22,7 @@ com.hazelcast hazelcast-client - 3.7.2 + ${hazelcast.version} @@ -39,7 +39,7 @@ - 3.7.4 + 3.8.4 \ No newline at end of file diff --git a/hbase/pom.xml b/hbase/pom.xml index 3f5456777e..5fe47fcdc7 100644 --- a/hbase/pom.xml +++ b/hbase/pom.xml @@ -31,7 +31,7 @@ - 1.3.0 + 1.3.1 diff --git a/immutables/pom.xml b/immutables/pom.xml index 9b623c85e7..884ebc0c61 100644 --- a/immutables/pom.xml +++ b/immutables/pom.xml @@ -3,7 +3,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung immutables 1.0.0-SNAPSHOT @@ -34,7 +33,7 @@ - 2.3.10 + 2.5.6 3.6.1 0.9.6 diff --git a/json-path/pom.xml b/json-path/pom.xml index 8384ba68ed..0f8ff3bd31 100644 --- a/json-path/pom.xml +++ b/json-path/pom.xml @@ -1,7 +1,6 @@ 4.0.0 - com.baeldung json-path 0.0.1-SNAPSHOT json-path diff --git a/lombok/pom.xml b/lombok/pom.xml index 472516de4d..bea05b38f3 100644 --- a/lombok/pom.xml +++ b/lombok/pom.xml @@ -6,8 +6,6 @@ 4.0.0 lombok - - com.baeldung lombok 0.1-SNAPSHOT @@ -81,7 +79,7 @@ UTF-8 - 1.16.12 + 1.16.18 1.0.0.Final