Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
commit
56e3687cad
@ -1,6 +1,5 @@
|
|||||||
package com.baeldung.stream;
|
package com.baeldung.stream;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
@ -8,15 +7,13 @@ import java.util.stream.IntStream;
|
|||||||
import com.codepoetics.protonpack.Indexed;
|
import com.codepoetics.protonpack.Indexed;
|
||||||
import com.codepoetics.protonpack.StreamUtils;
|
import com.codepoetics.protonpack.StreamUtils;
|
||||||
|
|
||||||
import io.vavr.Tuple2;
|
|
||||||
import io.vavr.collection.Stream;
|
import io.vavr.collection.Stream;
|
||||||
import one.util.streamex.EntryStream;
|
import one.util.streamex.EntryStream;
|
||||||
|
|
||||||
public class StreamIndices {
|
public class StreamIndices {
|
||||||
|
|
||||||
public static List<String> getEvenIndexedStrings(String[] names) {
|
public static List<String> getEvenIndexedStrings(String[] names) {
|
||||||
List<String> evenIndexedNames = IntStream
|
List<String> evenIndexedNames = IntStream.range(0, names.length)
|
||||||
.range(0, names.length)
|
|
||||||
.filter(i -> i % 2 == 0)
|
.filter(i -> i % 2 == 0)
|
||||||
.mapToObj(i -> names[i])
|
.mapToObj(i -> names[i])
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -24,8 +21,7 @@ public class StreamIndices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getEvenIndexedStringsVersionTwo(List<String> names) {
|
public List<String> getEvenIndexedStringsVersionTwo(List<String> names) {
|
||||||
List<String> evenIndexedNames = EntryStream
|
List<String> evenIndexedNames = EntryStream.of(names)
|
||||||
.of(names)
|
|
||||||
.filterKeyValue((index, name) -> index % 2 == 0)
|
.filterKeyValue((index, name) -> index % 2 == 0)
|
||||||
.values()
|
.values()
|
||||||
.toList();
|
.toList();
|
||||||
@ -33,24 +29,21 @@ public class StreamIndices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<Indexed<String>> getEvenIndexedStrings(List<String> names) {
|
public static List<Indexed<String>> getEvenIndexedStrings(List<String> names) {
|
||||||
List<Indexed<String>> list = StreamUtils
|
List<Indexed<String>> list = StreamUtils.zipWithIndex(names.stream())
|
||||||
.zipWithIndex(names.stream())
|
|
||||||
.filter(i -> i.getIndex() % 2 == 0)
|
.filter(i -> i.getIndex() % 2 == 0)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Indexed<String>> getOddIndexedStrings(List<String> names) {
|
public static List<Indexed<String>> getOddIndexedStrings(List<String> names) {
|
||||||
List<Indexed<String>> list = StreamUtils
|
List<Indexed<String>> list = StreamUtils.zipWithIndex(names.stream())
|
||||||
.zipWithIndex(names.stream())
|
|
||||||
.filter(i -> i.getIndex() % 2 == 1)
|
.filter(i -> i.getIndex() % 2 == 1)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getOddIndexedStrings(String[] names) {
|
public static List<String> getOddIndexedStrings(String[] names) {
|
||||||
List<String> oddIndexedNames = IntStream
|
List<String> oddIndexedNames = IntStream.range(0, names.length)
|
||||||
.range(0, names.length)
|
|
||||||
.filter(i -> i % 2 == 1)
|
.filter(i -> i % 2 == 1)
|
||||||
.mapToObj(i -> names[i])
|
.mapToObj(i -> names[i])
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -58,15 +51,12 @@ public class StreamIndices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getOddIndexedStringsVersionTwo(String[] names) {
|
public static List<String> getOddIndexedStringsVersionTwo(String[] names) {
|
||||||
List<Tuple2<String, Integer>> tuples = Stream
|
List<String> oddIndexedNames = Stream.of(names)
|
||||||
.of(names)
|
|
||||||
.zipWithIndex()
|
.zipWithIndex()
|
||||||
.filter(tuple -> tuple._2 % 2 == 1)
|
.filter(tuple -> tuple._2 % 2 == 1)
|
||||||
|
.map(tuple -> tuple._1)
|
||||||
.toJavaList();
|
.toJavaList();
|
||||||
List<String> oddIndexedNames = new ArrayList<String>();
|
|
||||||
tuples.forEach(tuple -> {
|
|
||||||
oddIndexedNames.add(tuple._1);
|
|
||||||
});
|
|
||||||
return oddIndexedNames;
|
return oddIndexedNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -22,7 +22,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.hazelcast</groupId>
|
<groupId>com.hazelcast</groupId>
|
||||||
<artifactId>hazelcast-client</artifactId>
|
<artifactId>hazelcast-client</artifactId>
|
||||||
<version>3.7.2</version>
|
<version>${hazelcast.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- hazelcast -->
|
<!-- hazelcast -->
|
||||||
<hazelcast.version>3.7.4</hazelcast.version>
|
<hazelcast.version>3.8.4</hazelcast.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -31,7 +31,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<hbase.version>1.3.0</hbase.version>
|
<hbase.version>1.3.1</hbase.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>immutables</artifactId>
|
<artifactId>immutables</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
@ -34,7 +33,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<immutables.version>2.3.10</immutables.version>
|
<immutables.version>2.5.6</immutables.version>
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<mutabilitydetector.version>0.9.6</mutabilitydetector.version>
|
<mutabilitydetector.version>0.9.6</mutabilitydetector.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>json-path</artifactId>
|
<artifactId>json-path</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>json-path</name>
|
<name>json-path</name>
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<name>lombok</name>
|
<name>lombok</name>
|
||||||
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
@ -81,7 +79,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<!-- lombok: https://projectlombok.org/changelog.html -->
|
<!-- lombok: https://projectlombok.org/changelog.html -->
|
||||||
<lombok.version>1.16.12</lombok.version>
|
<lombok.version>1.16.18</lombok.version>
|
||||||
|
|
||||||
<!-- various -->
|
<!-- various -->
|
||||||
<hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
|
<hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user