Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JAVA-41881] #18211

Merged
merged 12 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core-java-modules/core-java-streams-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
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)
- [Java Stream findFirst() vs. findAny()](https://www.baeldung.com/java-stream-findfirst-vs-findany)
- [Java IntStream Conversions](https://www.baeldung.com/java-intstream-convert)
- [Java Streams peek() API](https://www.baeldung.com/java-streams-peek-api)
- [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)
- [Stream Ordering in Java](https://www.baeldung.com/java-stream-ordering)
- [Iterable to Stream in Java](https://www.baeldung.com/java-iterable-to-stream)
- [How to Get the Last Element of a Stream in Java?](https://www.baeldung.com/java-stream-last-element)
- [How to Use if/else Logic in Java Streams](https://www.baeldung.com/java-8-streams-if-else-logic)
- More articles: [[<-- prev>]](/../core-java-streams) [[next -->]](/../core-java-streams-3)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung.stream;
package com.baeldung.streams;

import java.util.List;
import java.util.stream.Stream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.baeldung.conversion;
package com.baeldung.convert;

import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import org.junit.Assert;
import org.junit.Test;

public class IterableStreamConversionUnitTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.baeldung.streamordering;

import org.junit.Test;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;


public class BenchmarkManualTest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.baeldung.streamordering;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

import java.util.*;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;

public class StreamsOrderingUnitTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.baeldung.stream;
package com.baeldung.streams;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class StreamApiUnitTest {

Expand Down
4 changes: 2 additions & 2 deletions core-java-modules/core-java-streams-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
This module contains articles about the Stream API in Java.

### Relevant Articles:
- [How to Use if/else Logic in Java 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](https://www.baeldung.com/java-8-primitive-streams)
- [Debugging Java Streams with IntelliJ](https://www.baeldung.com/intellij-debugging-java-streams)
- [Add BigDecimals using the Stream API](https://www.baeldung.com/java-stream-add-bigdecimals)
- [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)
- [Counting Matches on a Stream Filter](https://www.baeldung.com/java-stream-filter-count)
- [“Stream has already been operated upon or closed” Exception in Java](https://www.baeldung.com/java-stream-operated-upon-or-closed-exception)
- More articles: [[<-- prev>]](/../core-java-streams-2) [[next -->]](/../core-java-streams-4)
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.baeldung.stream.filter;
package com.baeldung.streams.filter;

import javax.net.ssl.HttpsURLConnection;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

public class Customer {
private String name;
private int points;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung.stream;
package com.baeldung.streams;

import static org.junit.Assert.fail;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.baeldung.stream.filter;
package com.baeldung.streams.filter;

import org.junit.Test;
import org.junit.Before;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Before;
import org.junit.Test;

public class StreamCountUnitTest {

Expand Down
1 change: 0 additions & 1 deletion core-java-modules/core-java-streams-4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
- [Count Occurrences Using Java groupingBy Collector](https://www.baeldung.com/java-groupingby-count)
- [How to Split a Stream into Multiple Streams](https://www.baeldung.com/java-split-stream)
- [Filter Java Stream to 1 and Only 1 Element](https://www.baeldung.com/java-filter-stream-unique-element)
- [Java 8 Streams: Multiple Filters vs. Complex Condition](https://www.baeldung.com/java-streams-multiple-filters-vs-condition)
- [Finding Max Date in List Using Streams](https://www.baeldung.com/java-max-date-list-streams)
- [Batch Processing of Stream Data in Java](https://www.baeldung.com/java-stream-batch-processing)
- [Stream to Iterable in Java](https://www.baeldung.com/java-stream-to-iterable)
Expand Down
2 changes: 0 additions & 2 deletions core-java-modules/core-java-streams-5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
- [Difference Between parallelStream() and stream().parallel() in Java](https://www.baeldung.com/java-parallelstream-vs-stream-parallel)
- [Working With Empty Stream in Java](https://www.baeldung.com/java-empty-stream)
- [Aggregate Runtime Exceptions in Java Streams](https://www.baeldung.com/java-streams-aggregate-exceptions)
- [Streams vs. Loops in Java](https://www.baeldung.com/java-streams-vs-loops)
- [Partition a Stream in Java](https://www.baeldung.com/java-partition-stream)
- [Taking Every N-th Element from Finite and Infinite Streams in Java](https://www.baeldung.com/java-nth-element-finite-infinite-streams)
- [Modifying Objects Within Stream While Iterating](https://www.baeldung.com/java-stream-modify-objects-during-iteration)
- [How to Avoid NoSuchElementException in Stream API](https://www.baeldung.com/java-streams-api-avoid-nosuchelementexception)
- [Get Index of First Element Matching Boolean Using Java Streams](https://www.baeldung.com/java-streams-find-first-match-index)
- [Handling NullPointerException in findFirst() When the First Element Is Null](https://www.baeldung.com/java-handle-nullpointerexception-findfirst-first-null)
Expand Down
5 changes: 2 additions & 3 deletions core-java-modules/core-java-streams-5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<artifactId>vavr</artifactId>
<version>${vavr.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
Expand All @@ -34,10 +33,10 @@
</dependencies>

<build>
<finalName>core-java-streams-4</finalName>
<finalName>core-java-streams-5</finalName>
<resources>
<resource>
<directory>../core-java-streams-4/src/main</directory>
<directory>../core-java-streams-5/src/main</directory>
<filtering>true</filtering>
</resource>
</resources>
Expand Down
4 changes: 4 additions & 0 deletions core-java-modules/core-java-streams-6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
- [Return Non-null Elements From Java Map Operation](https://www.baeldung.com/java-stream-non-null-map)
- [How to Convert to and From a Stream and Two Dimensional Array in Java](https://www.baeldung.com/java-convert-stream-2d-array)
- [Understanding findAny() and anyMatch() in Streams](https://www.baeldung.com/java-streams-findany-anymatch)
- [Java and Infinite Streams](https://www.baeldung.com/java-inifinite-streams)
- [Skip Bytes in InputStream in Java](https://www.baeldung.com/java-inputstream-skip-bytes)
- [How to Find All Getters Returning Null](https://www.baeldung.com/java-getters-returning-null)

4 changes: 0 additions & 4 deletions core-java-modules/core-java-streams-6/REAME.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung.reflection;
package com.baeldung.streams.gettersreturningnull;

public class Customer {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package com.baeldung.reflection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package com.baeldung.streams.gettersreturningnull;

import java.beans.Introspector;
import java.beans.PropertyDescriptor;
Expand All @@ -11,9 +8,12 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

class BaeldungReflectionUtils {
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class Utils {

private static final Logger LOG = LoggerFactory.getLogger(BaeldungReflectionUtils.class);
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);

static List<String> getNullPropertiesList(Customer customer) throws Exception {
PropertyDescriptor[] propDescArr = Introspector.getBeanInfo(Customer.class, Object.class).getPropertyDescriptors();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.baeldung.stream;
package com.baeldung.streams.infinitestream;

import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.stream.Stream;

public class InfiniteStreams {

private static final Logger LOG = LoggerFactory.getLogger(InfiniteStreams.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.baeldung.reflection;
package com.baeldung.streams.gettersreturningnull;

import org.junit.Test;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

public class BaeldungReflectionUtilsUnitTest {

@Test
public void givenCustomer_whenAFieldIsNull_thenFieldNameInResult() throws Exception {
Customer customer = new Customer(1, "Himanshu", null, null);

List<String> result = BaeldungReflectionUtils.getNullPropertiesList(customer);
List<String> result = Utils.getNullPropertiesList(customer);
List<String> expectedFieldNames = Arrays.asList("emailId", "phoneNumber");

assertTrue(result.size() == expectedFieldNames.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.baeldung.stream;
package com.baeldung.streams.infinitestream;


import org.junit.Test;
import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.List;
Expand All @@ -10,7 +9,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class InfiniteStreamUnitTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package com.baeldung.skipinputstream;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.Assert.assertArrayEquals;
public class SkipInputStreamUnitTest {
@Test
public void givenInputStreamWithBytes_whenSkipBytes_thenRemainingBytes() throws IOException {
byte[] inputData = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
InputStream inputStream = new ByteArrayInputStream(inputData);
long bytesToSkip = 3;
long skippedBytes = inputStream.skip(bytesToSkip);
assertArrayEquals(new byte[]{4, 5, 6, 7, 8, 9, 10}, readRemainingBytes(inputStream));
assert skippedBytes == bytesToSkip : "Incorrect number of bytes skipped";
}
private byte[] readRemainingBytes(InputStream inputStream) throws IOException {
byte[] buffer = new byte[inputStream.available()];
int bytesRead = inputStream.read(buffer);
if (bytesRead == -1) {
throw new IOException("End of stream reached");
}
return buffer;
}
}
package com.baeldung.streams.skipinputstream;

import static org.junit.Assert.assertArrayEquals;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;

public class SkipInputStreamUnitTest {
@Test
public void givenInputStreamWithBytes_whenSkipBytes_thenRemainingBytes() throws IOException {
byte[] inputData = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
InputStream inputStream = new ByteArrayInputStream(inputData);

long bytesToSkip = 3;
long skippedBytes = inputStream.skip(bytesToSkip);

assertArrayEquals(new byte[]{4, 5, 6, 7, 8, 9, 10}, readRemainingBytes(inputStream));

assert skippedBytes == bytesToSkip : "Incorrect number of bytes skipped";
}

private byte[] readRemainingBytes(InputStream inputStream) throws IOException {
byte[] buffer = new byte[inputStream.available()];
int bytesRead = inputStream.read(buffer);
if (bytesRead == -1) {
throw new IOException("End of stream reached");
}
return buffer;
}
}
15 changes: 7 additions & 8 deletions core-java-modules/core-java-streams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
This module contains articles about the Stream API in Java.

### Relevant Articles:
- [Java and Infinite Streams](https://www.baeldung.com/java-inifinite-streams)
- [How to Get the Last Element of a Stream in Java?](https://www.baeldung.com/java-stream-last-element)
- [“Stream has already been operated upon or closed” Exception in Java](https://www.baeldung.com/java-stream-operated-upon-or-closed-exception)
- [Iterable to Stream in Java](https://www.baeldung.com/java-iterable-to-stream)
- [The Java 8 Stream API Tutorial](https://www.baeldung.com/java-8-streams)
- [How to Iterate Over a Stream With Indices](https://www.baeldung.com/java-stream-indices)
- [Stream Ordering in Java](https://www.baeldung.com/java-stream-ordering)
- [Counting Matches on a Stream Filter](https://www.baeldung.com/java-stream-filter-count)
- [Summing Numbers with Java Streams](https://www.baeldung.com/java-stream-sum)
- [How to Find All Getters Returning Null](https://www.baeldung.com/java-getters-returning-null)
- [Skip Bytes in InputStream in Java](https://www.baeldung.com/java-inputstream-skip-bytes)
- [The Difference Between Collection.stream().forEach() and Collection.forEach()](https://www.baeldung.com/java-collection-stream-foreach)
- [Java 8 Streams: Multiple Filters vs. Complex Condition](https://www.baeldung.com/java-streams-multiple-filters-vs-condition)
- [Modifying Objects Within Stream While Iterating](https://www.baeldung.com/java-stream-modify-objects-during-iteration)
- [Streams vs. Loops in Java](https://www.baeldung.com/java-streams-vs-loops)
- [Java Streams peek() API](https://www.baeldung.com/java-streams-peek-api)
- [Java Stream findFirst() vs. findAny()](https://www.baeldung.com/java-stream-findfirst-vs-findany)
- More articles: [[next -->]](/../core-java-streams-2)
Loading