Skip to content

Commit 1afa7e2

Browse files
daveRanjanmaibin
authored andcommitted
Bael 1043/protonpack (eugenp#2415)
* BAEL-1043/ Introduction to protonpack * Added test cases for windowed() api * Resolving merge issues
1 parent 133bbe1 commit 1afa7e2

5 files changed

Lines changed: 511 additions & 107 deletions

File tree

‎libraries/pom.xml‎

Lines changed: 112 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,110 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<parent>
5-
<artifactId>parent-modules</artifactId>
6-
<groupId>com.baeldung</groupId>
7-
<version>1.0.0-SNAPSHOT</version>
8-
</parent>
9-
<modelVersion>4.0.0</modelVersion>
10-
<artifactId>libraries</artifactId>
11-
<name>libraries</name>
12-
<build>
13-
<plugins>
14-
<plugin>
15-
<groupId>org.apache.maven.plugins</groupId>
16-
<artifactId>maven-dependency-plugin</artifactId>
17-
<dependencies>
18-
<dependency>
19-
<groupId>org.apache.felix</groupId>
20-
<artifactId>maven-bundle-plugin</artifactId>
21-
<version>3.3.0</version>
22-
<type>maven-plugin</type>
23-
</dependency>
24-
</dependencies>
25-
<extensions>true</extensions>
26-
</plugin>
27-
<plugin>
28-
<artifactId>maven-failsafe-plugin</artifactId>
29-
<version>2.20</version>
30-
<configuration>
31-
<systemProperties>
32-
<webdriver.chrome.driver>chromedriver</webdriver.chrome.driver>
33-
</systemProperties>
34-
</configuration>
35-
</plugin>
36-
<plugin>
37-
<groupId>net.serenity-bdd.maven.plugins</groupId>
38-
<artifactId>serenity-maven-plugin</artifactId>
39-
<version>${serenity.plugin.version}</version>
40-
<executions>
41-
<execution>
42-
<id>serenity-reports</id>
43-
<phase>post-integration-test</phase>
44-
<goals>
45-
<goal>aggregate</goal>
46-
</goals>
47-
</execution>
48-
</executions>
49-
</plugin>
50-
<!-- JDO Plugin -->
51-
<plugin>
52-
<groupId>org.datanucleus</groupId>
53-
<artifactId>datanucleus-maven-plugin</artifactId>
54-
<version>5.0.2</version>
55-
<configuration>
56-
<api>JDO</api>
57-
<props>${basedir}/datanucleus.properties</props>
58-
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
59-
<verbose>true</verbose>
60-
<fork>false</fork>
61-
<!-- Solve windows line too long error -->
62-
</configuration>
63-
<executions>
64-
<execution>
65-
<phase>process-classes</phase>
66-
<goals>
67-
<goal>enhance</goal>
68-
</goals>
69-
</execution>
70-
</executions>
71-
</plugin>
72-
<!-- Neuroph -->
73-
<plugin>
74-
<groupId>org.apache.maven.plugins</groupId>
75-
<artifactId>maven-jar-plugin</artifactId>
76-
<version>3.0.2</version>
77-
<configuration>
78-
<excludes>
79-
<exclude>**/log4j.properties</exclude>
80-
</excludes>
81-
<archive>
82-
<manifest>
83-
<mainClass>com.baeldung.neuroph.NeurophXOR</mainClass>
84-
</manifest>
85-
</archive>
86-
</configuration>
87-
</plugin>
88-
<plugin>
89-
<groupId>org.apache.maven.plugins</groupId>
90-
<artifactId>maven-surefire-plugin</artifactId>
91-
<version>2.18.1</version>
92-
<executions>
93-
<execution>
94-
<id>test</id>
95-
<phase>test</phase>
96-
<goals>
97-
<goal>test</goal>
98-
</goals>
99-
<configuration>
100-
<includes>
101-
<include>test/java/com/baeldung/neuroph/XORTest.java</include>
102-
</includes>
103-
</configuration>
104-
</execution>
105-
</executions>
106-
</plugin>
107-
<!-- /Neuroph -->
108-
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<parent>
5+
<artifactId>parent-modules</artifactId>
6+
<groupId>com.baeldung</groupId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
</parent>
9+
<modelVersion>4.0.0</modelVersion>
10+
<artifactId>libraries</artifactId>
11+
<name>libraries</name>
12+
<build>
13+
<plugins>
14+
<plugin>
15+
<groupId>org.apache.maven.plugins</groupId>
16+
<artifactId>maven-dependency-plugin</artifactId>
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.apache.felix</groupId>
20+
<artifactId>maven-bundle-plugin</artifactId>
21+
<version>3.3.0</version>
22+
<type>maven-plugin</type>
23+
</dependency>
24+
</dependencies>
25+
<extensions>true</extensions>
26+
</plugin>
27+
<plugin>
28+
<artifactId>maven-failsafe-plugin</artifactId>
29+
<version>2.20</version>
30+
<configuration>
31+
<systemProperties>
32+
<webdriver.chrome.driver>chromedriver</webdriver.chrome.driver>
33+
</systemProperties>
34+
</configuration>
35+
</plugin>
36+
<plugin>
37+
<groupId>net.serenity-bdd.maven.plugins</groupId>
38+
<artifactId>serenity-maven-plugin</artifactId>
39+
<version>${serenity.plugin.version}</version>
40+
<executions>
41+
<execution>
42+
<id>serenity-reports</id>
43+
<phase>post-integration-test</phase>
44+
<goals>
45+
<goal>aggregate</goal>
46+
</goals>
47+
</execution>
48+
</executions>
49+
</plugin>
50+
<!-- JDO Plugin -->
51+
<plugin>
52+
<groupId>org.datanucleus</groupId>
53+
<artifactId>datanucleus-maven-plugin</artifactId>
54+
<version>5.0.2</version>
55+
<configuration>
56+
<api>JDO</api>
57+
<props>${basedir}/datanucleus.properties</props>
58+
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
59+
<verbose>true</verbose>
60+
<fork>false</fork>
61+
<!-- Solve windows line too long error -->
62+
</configuration>
63+
<executions>
64+
<execution>
65+
<phase>process-classes</phase>
66+
<goals>
67+
<goal>enhance</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
<!-- Neuroph -->
73+
<plugin>
74+
<groupId>org.apache.maven.plugins</groupId>
75+
<artifactId>maven-jar-plugin</artifactId>
76+
<version>3.0.2</version>
77+
<configuration>
78+
<excludes>
79+
<exclude>**/log4j.properties</exclude>
80+
</excludes>
81+
<archive>
82+
<manifest>
83+
<mainClass>com.baeldung.neuroph.NeurophXOR</mainClass>
84+
</manifest>
85+
</archive>
86+
</configuration>
87+
</plugin>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-surefire-plugin</artifactId>
91+
<version>2.18.1</version>
92+
<executions>
93+
<execution>
94+
<id>test</id>
95+
<phase>test</phase>
96+
<goals>
97+
<goal>test</goal>
98+
</goals>
99+
<configuration>
100+
<includes>
101+
<include>test/java/com/baeldung/neuroph/XORTest.java</include>
102+
</includes>
103+
</configuration>
104+
</execution>
105+
</executions>
106+
</plugin>
107+
<!-- /Neuroph -->
109108
</plugins>
110109
</build>
111110
<dependencies>
@@ -534,7 +533,12 @@
534533
<artifactId>jdeferred-core</artifactId>
535534
<version>1.2.6</version>
536535
</dependency>
537-
</dependencies>
536+
<dependency>
537+
<groupId>com.codepoetics</groupId>
538+
<artifactId>protonpack</artifactId>
539+
<version>${protonpack.version}</version>
540+
</dependency>
541+
</dependencies>
538542
<repositories>
539543
<repository>
540544
<id>maven2-repository.dev.java.net</id>
@@ -610,5 +614,6 @@
610614
<geotools.version>15.2</geotools.version>
611615
<joda-time.version>2.9.9</joda-time.version>
612616
<hirondelle-date4j.version>1.5.1</hirondelle-date4j.version>
617+
<protonpack.version>1.14</protonpack.version>
613618
</properties>
614619
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.protonpack;
2+
3+
import java.util.Optional;
4+
import java.util.stream.Stream;
5+
6+
import static com.codepoetics.protonpack.collectors.CollectorUtils.maxBy;
7+
import static com.codepoetics.protonpack.collectors.CollectorUtils.minBy;
8+
9+
public class CollectorUtilsExample {
10+
11+
public void minMaxProjectionCollector() {
12+
Stream<String> integerStream = Stream.of("a", "bb", "ccc", "1");
13+
14+
Optional<String> max = integerStream.collect(maxBy(String::length));
15+
Optional<String> min = integerStream.collect(minBy(String::length));
16+
17+
}
18+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.baeldung.protonpack;
2+
3+
import com.codepoetics.protonpack.Indexed;
4+
import com.codepoetics.protonpack.StreamUtils;
5+
import com.codepoetics.protonpack.selectors.Selectors;
6+
7+
import java.util.List;
8+
import java.util.Optional;
9+
import java.util.stream.Collectors;
10+
import java.util.stream.LongStream;
11+
import java.util.stream.Stream;
12+
13+
import static java.util.stream.Collectors.toList;
14+
15+
public class StreamUtilsExample {
16+
17+
public void createInfiniteIndex() {
18+
LongStream indices = StreamUtils.indices();
19+
}
20+
21+
public void zipAStreamWithIndex() {
22+
Stream<String> source = Stream.of("Foo", "Bar", "Baz");
23+
List<Indexed<String>> zipped = StreamUtils
24+
.zipWithIndex(source)
25+
.collect(Collectors.toList());
26+
}
27+
28+
public void zipAPairOfStreams() {
29+
Stream<String> streamA = Stream.of("A", "B", "C");
30+
Stream<String> streamB = Stream.of("Apple", "Banana", "Carrot");
31+
32+
List<String> zipped = StreamUtils
33+
.zip(streamA, streamB, (a, b) -> a + " is for " + b)
34+
.collect(Collectors.toList());
35+
}
36+
37+
public void zipThreeStreams() {
38+
Stream<String> streamA = Stream.of("A", "B", "C");
39+
Stream<String> streamB = Stream.of("aggravating", "banausic", "complaisant");
40+
Stream<String> streamC = Stream.of("Apple", "Banana", "Carrot");
41+
42+
List<String> zipped = StreamUtils
43+
.zip(streamA, streamB, streamC, (a, b, c) -> a + " is for " + b + " " + c)
44+
.collect(Collectors.toList());
45+
}
46+
47+
public void mergeThreeStreams() {
48+
Stream<String> streamA = Stream.of("A", "B", "C");
49+
Stream<String> streamB = Stream.of("apple", "banana", "carrot", "date");
50+
Stream<String> streamC = Stream.of("fritter", "split", "cake", "roll", "pastry");
51+
52+
Stream<List<String>> merged = StreamUtils.mergeToList(streamA, streamB, streamC);
53+
}
54+
55+
public void interleavingStreamsUsingRoundRobin() {
56+
Stream<String> streamA = Stream.of("Peter", "Paul", "Mary");
57+
Stream<String> streamB = Stream.of("A", "B", "C", "D", "E");
58+
Stream<String> streamC = Stream.of("foo", "bar", "baz", "xyzzy");
59+
60+
Stream<String> interleaved = StreamUtils.interleave(Selectors.roundRobin(), streamA, streamB, streamC);
61+
}
62+
63+
public void takeWhileAndTakeUntilStream() {
64+
Stream<Integer> infiniteInts = Stream.iterate(0, i -> i + 1);
65+
Stream<Integer> finiteIntsWhileLessThan10 = StreamUtils.takeWhile(infiniteInts, i -> i < 10);
66+
Stream<Integer> finiteIntsUntilGreaterThan10 = StreamUtils.takeUntil(infiniteInts, i -> i > 10);
67+
}
68+
69+
public void skipWhileAndSkipUntilStream() {
70+
Stream<Integer> ints = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
71+
Stream<Integer> skippedWhileConditionMet = StreamUtils.skipWhile(ints, i -> i < 4);
72+
Stream<Integer> skippedUntilConditionMet = StreamUtils.skipWhile(ints, i -> i > 4);
73+
}
74+
75+
public void unfoldStream() {
76+
Stream<Integer> unfolded = StreamUtils.unfold(1, i -> (i < 10) ? Optional.of(i + 1) : Optional.empty());
77+
}
78+
79+
public void windowedStream() {
80+
Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5);
81+
82+
List<List<Integer>> windows = StreamUtils
83+
.windowed(integerStream, 2)
84+
.collect(toList());
85+
List<List<Integer>> windowsWithSkipIndex = StreamUtils
86+
.windowed(integerStream, 3, 2)
87+
.collect(toList());
88+
List<List<Integer>> windowsWithSkipIndexAndAllowLowerSize = StreamUtils
89+
.windowed(integerStream, 2, 2, true)
90+
.collect(toList());
91+
92+
}
93+
94+
public void groupRunsStreams() {
95+
Stream<Integer> integerStream = Stream.of(1, 1, 2, 2, 3, 4, 5);
96+
97+
List<List<Integer>> runs = StreamUtils
98+
.groupRuns(integerStream)
99+
.collect(toList());
100+
}
101+
102+
public void aggreagateOnBiElementPredicate() {
103+
Stream<String> stream = Stream.of("a1", "b1", "b2", "c1");
104+
Stream<List<String>> aggregated = StreamUtils.aggregate(stream, (e1, e2) -> e1.charAt(0) == e2.charAt(0));
105+
}
106+
107+
}

0 commit comments

Comments
 (0)