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

Make nullable lists more sane, update JEP reference #61

Merged
merged 1 commit into from
Dec 1, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gatherers4j

A library of useful [Stream Gatherers](https://openjdk.org/jeps/473) (custom intermediate operations) for Java 23+.
A library of useful [Stream Gatherers](https://openjdk.org/jeps/485) (custom intermediate operations) for Java 23+.

# Installing

Expand Down
11 changes: 0 additions & 11 deletions src/main/java/com/ginsberg/gatherers4j/GathererUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,10 @@

import org.jspecify.annotations.Nullable;

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

abstract class GathererUtils {

final static long NANOS_PER_MILLISECOND = 1_000_000;


static <INPUT> List<INPUT> listOfNullables(final @Nullable INPUT left, final @Nullable INPUT right) {
final List<INPUT> list = new ArrayList<>();
list.add(left);
list.add(right);
return list;
}

static void mustNotBeNull(final @Nullable Object subject, final String message) {
if (subject == null) {
throw new IllegalArgumentException(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

import org.jspecify.annotations.Nullable;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Gatherer;

import static com.ginsberg.gatherers4j.GathererUtils.listOfNullables;

public class ZipWithNextGatherer<INPUT extends @Nullable Object>
implements Gatherer<INPUT, ZipWithNextGatherer.State<INPUT>, List<INPUT>> {

Expand All @@ -42,7 +41,7 @@ public Integrator<State<INPUT>, INPUT, List<INPUT>> integrator() {
if (!state.hasValue) {
state.hasValue = true;
} else {
downstream.push(listOfNullables(state.value, element));
downstream.push(Arrays.asList(state.value, element));
}
state.value = element;
return !downstream.isRejecting();
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/ginsberg/gatherers4j/GathererUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

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

import static com.ginsberg.gatherers4j.GathererUtils.listOfNullables;
import static com.ginsberg.gatherers4j.GathererUtils.mustNotBeNull;
import static org.assertj.core.api.Assertions.*;

Expand All @@ -37,7 +37,7 @@ void containsNulls() {
final String right = null;

// Act
final List<String> output = listOfNullables(left, right);
final List<String> output = Arrays.asList(left, right);

// Assert
assertThat(output).isNotNull().hasSize(2).containsExactly(left, right);
Expand All @@ -50,7 +50,7 @@ void containsNonNulls() {
final String right = "B";

// Act
final List<String> output = listOfNullables(left, right);
final List<String> output = Arrays.asList(left, right);

// Assert
assertThat(output).isNotNull().hasSize(2).containsExactly(left, right);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import static com.ginsberg.gatherers4j.GathererUtils.listOfNullables;
import static org.assertj.core.api.Assertions.assertThat;

class ZipWithNextGathererTest {
Expand Down Expand Up @@ -60,9 +60,9 @@ void zipWithNextIncludingNulls() {
// Assert
assertThat(output)
.containsExactly(
listOfNullables("A", null),
listOfNullables(null, "C"),
listOfNullables("C", null)
Arrays.asList("A", null),
Arrays.asList(null, "C"),
Arrays.asList("C", null)
);
}

Expand Down
Loading