[JAVA-12051] Moved code to core-java-streams-simple for ebook (#14889)
This commit is contained in:
@@ -5,7 +5,6 @@ This module contains articles about Java 11 core features
|
||||
### Relevant articles
|
||||
- [Guide To Java 8 Optional](https://www.baeldung.com/java-optional)
|
||||
- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
|
||||
- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
|
||||
- [New Features in Java 11](https://www.baeldung.com/java-11-new-features)
|
||||
- [Getting the Java Version at Runtime](https://www.baeldung.com/get-java-version-runtime)
|
||||
- [Invoking a SOAP Web Service in Java](https://www.baeldung.com/java-soap-web-service)
|
||||
|
||||
@@ -4,5 +4,4 @@
|
||||
- [Guide to mapMulti in Stream API](https://www.baeldung.com/java-mapmulti)
|
||||
- [Collecting Stream Elements into a List in Java](https://www.baeldung.com/java-stream-to-list-collecting)
|
||||
- [New Features in Java 16](https://www.baeldung.com/java-16-new-features)
|
||||
- [Guide to Java 8 groupingBy Collector](https://www.baeldung.com/java-groupingby-collector)
|
||||
- [Value-Based Classes in Java](https://www.baeldung.com/java-value-based-classes)
|
||||
|
||||
@@ -4,12 +4,9 @@ This module contains articles about the Stream API in Java.
|
||||
|
||||
### Relevant Articles:
|
||||
- [The Java 8 Stream API Tutorial](https://www.baeldung.com/java-8-streams)
|
||||
- [Introduction to Java 8 Streams](https://www.baeldung.com/java-8-streams-introduction)
|
||||
- [Java 8 Stream findFirst() vs. findAny()](https://www.baeldung.com/java-stream-findfirst-vs-findany)
|
||||
- [Guide to Stream.reduce()](https://www.baeldung.com/java-stream-reduce)
|
||||
- [Java IntStream Conversions](https://www.baeldung.com/java-intstream-convert)
|
||||
- [Java 8 Streams peek() API](https://www.baeldung.com/java-streams-peek-api)
|
||||
- [Working With Maps Using Streams](https://www.baeldung.com/java-maps-streams)
|
||||
- [Collect a Java Stream to an Immutable Collection](https://www.baeldung.com/java-stream-immutable-collection)
|
||||
- [How to Add a Single Element to a Stream](https://www.baeldung.com/java-stream-append-prepend)
|
||||
- [Operating on and Removing an Item from Stream](https://www.baeldung.com/java-use-remove-item-stream)
|
||||
|
||||
+2
@@ -1,6 +1,7 @@
|
||||
package com.baeldung.streams;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -37,6 +38,7 @@ public class Java8StreamApiUnitTest {
|
||||
assertEquals(list.size() - 1, size);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void checkOrder_whenChangeQuantityOfMethodCalls_thenCorrect() {
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
This module contains articles about the Stream API in Java.
|
||||
|
||||
### Relevant Articles:
|
||||
- [The Difference Between map() and flatMap()](https://www.baeldung.com/java-difference-map-and-flatmap)
|
||||
### Relevant Articles:
|
||||
- [How to Use if/else Logic in Java 8 Streams](https://www.baeldung.com/java-8-streams-if-else-logic)
|
||||
- [The Difference Between Collection.stream().forEach() and Collection.forEach()](https://www.baeldung.com/java-collection-stream-foreach)
|
||||
- [Primitive Type Streams in Java 8](https://www.baeldung.com/java-8-primitive-streams)
|
||||
@@ -12,5 +11,4 @@ This module contains articles about the Stream API in Java.
|
||||
- [Should We Close a Java Stream?](https://www.baeldung.com/java-stream-close)
|
||||
- [Returning Stream vs. Collection](https://www.baeldung.com/java-return-stream-collection)
|
||||
- [Convert a Java Enumeration Into a Stream](https://www.baeldung.com/java-enumeration-to-stream)
|
||||
- [When to Use a Parallel Stream in Java](https://www.baeldung.com/java-when-to-use-parallel-stream)
|
||||
- More articles: [[<-- prev>]](/../core-java-streams-2)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
## Java Streams Ebook
|
||||
|
||||
This module contains articles about Streams that are part of the Java Streams Ebook.
|
||||
|
||||
### Relevant Articles
|
||||
|
||||
- [Introduction to Java 8 Streams](https://www.baeldung.com/java-8-streams-introduction)
|
||||
- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
|
||||
- [Java Stream Filter with Lambda Expression](https://www.baeldung.com/java-stream-filter-lambda)
|
||||
- [Working With Maps Using Streams](https://www.baeldung.com/java-maps-streams)
|
||||
- [The Difference Between map() and flatMap()](https://www.baeldung.com/java-difference-map-and-flatmap)
|
||||
- [When to Use a Parallel Stream in Java](https://www.baeldung.com/java-when-to-use-parallel-stream)
|
||||
- [Guide to Java 8 groupingBy Collector](https://www.baeldung.com/java-groupingby-collector)
|
||||
- [Guide to Stream.reduce()](https://www.baeldung.com/java-stream-reduce)
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-streams-simple</artifactId>
|
||||
<name>core-java-streams-simple</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.pivovarit</groupId>
|
||||
<artifactId>throwing-function</artifactId>
|
||||
<version>${throwing-function.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-streams-simple</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<throwing-function.version>1.5.1</throwing-function.version>
|
||||
<maven.compiler.source.version>17</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>17</maven.compiler.target.version>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.baeldung.streams.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
public class Customer {
|
||||
private String name;
|
||||
private int points;
|
||||
private String profilePhotoUrl;
|
||||
|
||||
public Customer(String name, int points) {
|
||||
this(name, points, "");
|
||||
}
|
||||
|
||||
public Customer(String name, int points, String profilePhotoUrl) {
|
||||
this.name = name;
|
||||
this.points = points;
|
||||
this.profilePhotoUrl = profilePhotoUrl;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public boolean hasOver(int points) {
|
||||
return this.points > points;
|
||||
}
|
||||
|
||||
public boolean hasOverHundredPoints() {
|
||||
return this.points > 100;
|
||||
}
|
||||
|
||||
public boolean hasValidProfilePhoto() throws IOException {
|
||||
URL url = new URL(this.profilePhotoUrl);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
public boolean hasValidProfilePhotoWithoutCheckedException() {
|
||||
try {
|
||||
URL url = new URL(this.profilePhotoUrl);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.java_16_features.groupingby;
|
||||
package com.baeldung.streams.groupingby;
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.java_16_features.groupingby;
|
||||
package com.baeldung.streams.groupingby;
|
||||
|
||||
public enum BlogPostType {
|
||||
NEWS, REVIEW, GUIDE
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.java_16_features.groupingby;
|
||||
package com.baeldung.streams.groupingby;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
+3
-4
@@ -1,8 +1,7 @@
|
||||
package com.baeldung.reduce.application;
|
||||
package com.baeldung.streams.reduce.application;
|
||||
|
||||
import com.baeldung.streams.reduce.entities.User;
|
||||
|
||||
import com.baeldung.reduce.entities.User;
|
||||
import com.baeldung.reduce.utilities.NumberUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.reduce.benchmarks;
|
||||
package com.baeldung.streams.reduce.benchmarks;
|
||||
|
||||
import com.baeldung.reduce.entities.User;
|
||||
import com.baeldung.streams.reduce.entities.User;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.reduce.entities;
|
||||
package com.baeldung.streams.reduce.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.reduce.entities;
|
||||
package com.baeldung.streams.reduce.entities;
|
||||
|
||||
public class Review {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.reduce.entities;
|
||||
package com.baeldung.streams.reduce.entities;
|
||||
|
||||
public class User {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.reduce.utilities;
|
||||
package com.baeldung.streams.reduce.utilities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.collectors;
|
||||
package com.baeldung.streams.collectors;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.stream.filter;
|
||||
package com.baeldung.streams.filter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import com.pivovarit.function.ThrowingPredicate;
|
||||
@@ -14,10 +14,10 @@ import java.util.stream.Stream;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
|
||||
public class StreamFilterUnitTest {
|
||||
class StreamFilterUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenListOfCustomers_whenFilterByPoints_thenGetTwo() {
|
||||
void givenListOfCustomers_whenFilterByPoints_thenGetTwo() {
|
||||
Customer john = new Customer("John P.", 15);
|
||||
Customer sarah = new Customer("Sarah M.", 200);
|
||||
Customer charles = new Customer("Charles B.", 150);
|
||||
@@ -53,7 +53,7 @@ public class StreamFilterUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfCustomers_whenFilterByMethodReference_thenGetTwo() {
|
||||
void givenListOfCustomers_whenFilterByMethodReference_thenGetTwo() {
|
||||
Customer john = new Customer("John P.", 15);
|
||||
Customer sarah = new Customer("Sarah M.", 200);
|
||||
Customer charles = new Customer("Charles B.", 150);
|
||||
@@ -70,7 +70,7 @@ public class StreamFilterUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfCustomersWithOptional_whenFilterBy100Points_thenGetTwo() {
|
||||
void givenListOfCustomersWithOptional_whenFilterBy100Points_thenGetTwo() {
|
||||
Optional<Customer> john = Optional.of(new Customer("John P.", 15));
|
||||
Optional<Customer> sarah = Optional.of(new Customer("Sarah M.", 200));
|
||||
Optional<Customer> mary = Optional.of(new Customer("Mary T.", 300));
|
||||
@@ -89,7 +89,7 @@ public class StreamFilterUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfCustomers_whenFilterWithCustomHandling_thenThrowException() {
|
||||
void givenListOfCustomers_whenFilterWithCustomHandling_thenThrowException() {
|
||||
Customer john = new Customer("John P.", 15, "https://images.unsplash.com/photo-1543320485-d0d5a49c2b2e");
|
||||
Customer sarah = new Customer("Sarah M.", 200);
|
||||
Customer charles = new Customer("Charles B.", 150);
|
||||
@@ -103,7 +103,7 @@ public class StreamFilterUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenListOfCustomers_whenFilterWithThrowingFunction_thenThrowException() {
|
||||
void givenListOfCustomers_whenFilterWithThrowingFunction_thenThrowException() {
|
||||
Customer john = new Customer("John P.", 15, "https://images.unsplash.com/photo-1543320485-d0d5a49c2b2e");
|
||||
Customer sarah = new Customer("Sarah M.", 200);
|
||||
Customer charles = new Customer("Charles B.", 150);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user