Skip to content

Commit

Permalink
Migrate to Java 11.
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer committed Oct 9, 2024
1 parent 5cbf3d6 commit c5f7481
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 368 deletions.
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.8.8/apache-maven-3.8.8-bin.zip
2 changes: 1 addition & 1 deletion build/settings-maven-central.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>oss-sonatype-releases</id>
<id>central</id>
<username>${env.MAVEN_CENTRAL_USERNAME}</username>
<password>${env.MAVEN_CENTRAL_PASSWORD}</password>
</server>
Expand Down
74 changes: 31 additions & 43 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
</developers>

<properties>
<versions.java>1.8</versions.java>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssX</maven.build.timestamp.format>
<project.baseName>java-stream-utils</project.baseName>
Expand All @@ -46,15 +47,33 @@

<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.11.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<version>5.14.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -170,34 +189,11 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${versions.java}</source>
<target>${versions.java}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.3</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>3.5.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<tagNameFormat>version-@{project.version}</tagNameFormat>
<!--suppress MavenModelInspection -->
<arguments>-DskipTests -Psign -Dgpg.passphrase=${passphrase} ${arguments}</arguments>
<scmCommentPrefix>* [RELEASE]</scmCommentPrefix>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -230,26 +226,18 @@
</profile>
<profile>
<id>maven-central</id>
<distributionManagement>
<repository>
<id>oss-sonatype-releases</id>
<url>dav:https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.7.0</version>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.6.0</version>
<extensions>true</extensions>
<configuration>
<serverId>oss-sonatype-releases</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
<publishingServerId>central</publishingServerId>
<autoPublish>true</autoPublish>
</configuration>
</plugin>

</plugins>
</build>
</profile>
Expand All @@ -263,11 +251,11 @@
<distributionManagement>
<snapshotRepository>
<id>github</id>
<url>https://maven.pkg.github.com/echocat/java-stream-utils</url>
<url>https://maven.pkg.github.com/echocat/hugo-maven-plugin</url>
</snapshotRepository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/echocat/java-stream-utils</url>
<url>https://maven.pkg.github.com/echocat/hugo-maven-plugin</url>
</repository>
</distributionManagement>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/echocat/jsu/AutoCloseableUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static <T extends AutoCloseable> T doOnClose(@Nonnull Class<T> type, @Non
if (callablesExecuteOnClose == null || callablesExecuteOnClose.length == 0) {
return instance;
}
final Method specificCloseMethod = typeSpecificCloseMethodOf(instance);
final var specificCloseMethod = typeSpecificCloseMethodOf(instance);
//noinspection unchecked
return (T) newProxyInstance(type.getClassLoader(), new Class[]{type}, (proxy, method, args) -> {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/echocat/jsu/Batch.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public Batch(

@Override
public boolean tryAdvance(@Nonnull Consumer<? super List<T>> consumer) {
final int batchSize = batchSize().get();
final List<T> batch = new ArrayList<>(batchSize);
final var batchSize = batchSize().get();
final var batch = new ArrayList<T>(batchSize);
for (int i = 0; i < batchSize; i++) {
if (!source().tryAdvance(batch::add)) {
if (!batch.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
package org.echocat.jsu;

import org.echocat.jsu.Generator.Value;

import javax.annotation.Nonnull;
import java.util.Spliterators.AbstractSpliterator;
import java.util.function.Consumer;
import javax.annotation.Nonnull;

public class ContinuingGenerator<T> extends AbstractSpliterator<T> {
public class ContinuingSupplier<T> extends AbstractSpliterator<T> {

@Nonnull
private final Generator<? extends T> generator;

public ContinuingGenerator(@Nonnull Generator<? extends T> generator) {
public ContinuingSupplier(@Nonnull Generator<? extends T> generator) {
super(Long.MAX_VALUE, ORDERED | IMMUTABLE);
this.generator = generator;
}

@Override
public boolean tryAdvance(Consumer<? super T> action) {
final Value<? extends T> value = generator().generate();
if (value == null) {
final var next = generator().generate();
if (next.isEmpty()) {
return false;
}
action.accept(value.get());
action.accept(next.get());
return true;
}

Expand Down
22 changes: 3 additions & 19 deletions src/main/java/org/echocat/jsu/Generator.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
package org.echocat.jsu;

import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Supplier;

@FunctionalInterface
public interface Generator<T> {

@Nullable
Value<T> generate();

@FunctionalInterface
public interface Value<T> extends Supplier<T> {

@Nonnull
public static <T> Value<T> valueOf(@Nullable T value) {
return () -> value;
}

@Nullable
public static <T> Value<T> end() {
return null;
}

}
@Nonnull
Optional<T> generate();

}
17 changes: 8 additions & 9 deletions src/main/java/org/echocat/jsu/JdbcUtils.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.echocat.jsu;

import org.echocat.jsu.support.SqlFunction;
import org.echocat.jsu.support.UncheckedSqlException;
import static org.echocat.jsu.AutoCloseableUtils.closeQuietly;
import static org.echocat.jsu.StreamUtils.generate;

import javax.annotation.Nonnull;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;
import javax.annotation.Nonnull;

import static org.echocat.jsu.AutoCloseableUtils.closeQuietly;
import static org.echocat.jsu.Generator.Value.end;
import static org.echocat.jsu.Generator.Value.valueOf;
import static org.echocat.jsu.StreamUtils.generate;
import org.echocat.jsu.support.SqlFunction;
import org.echocat.jsu.support.UncheckedSqlException;

public final class JdbcUtils {

Expand All @@ -21,9 +20,9 @@ public static Stream<ResultSet> toStream(@Nonnull ResultSet resultSet) {
return generate(() -> {
try {
if (!resultSet.next()) {
return end();
return Optional.empty();
}
return valueOf(resultSet);
return Optional.of(resultSet);
} catch (final SQLException e) {
throw new UncheckedSqlException(e);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/echocat/jsu/SpliteratorUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.echocat.jsu;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.Spliterator;
import java.util.function.Predicate;
import java.util.function.Supplier;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;

public final class SpliteratorUtils {

Expand All @@ -26,7 +26,7 @@ public static <T> Spliterator<List<T>> batch(@Nonnull Spliterator<? extends T> s

@Nonnull
public static <T> Spliterator<T> generate(@Nonnull Generator<? extends T> generator) {
return new ContinuingGenerator<>(generator);
return new ContinuingSupplier<>(generator);
}

}
31 changes: 15 additions & 16 deletions src/main/java/org/echocat/jsu/StreamUtils.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package org.echocat.jsu;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import static org.echocat.jsu.AutoCloseableUtils.closeQuietly;

import java.util.List;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static java.util.stream.StreamSupport.stream;
import static org.echocat.jsu.Generator.Value.valueOf;
import java.util.stream.StreamSupport;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;

public final class StreamUtils {

@Nonnull
public static <T> Stream<T> takeWhile(@Nonnull Stream<? extends T> source, @Nonnegative @Nonnull Predicate<T> predicate) {
return stream(SpliteratorUtils.takeWhile(source.spliterator(), predicate), false)
.onClose(() -> AutoCloseableUtils.closeQuietly(source));
//noinspection unchecked
return (Stream<T>) source.takeWhile(predicate)
.onClose(() -> closeQuietly(source));
}

@Nonnull
public static <T> Stream<List<T>> batch(@Nonnull Stream<? extends T> source, @Nonnegative @Nonnull Supplier<Integer> batchSize) {
//noinspection unchecked,rawtypes
return (Stream) stream(SpliteratorUtils.batch(source.spliterator(), batchSize), false)
.onClose(() -> AutoCloseableUtils.closeQuietly(source));
return StreamSupport.<List<T>>stream(SpliteratorUtils.batch(source.spliterator(), batchSize), false)
.onClose(() -> closeQuietly(source));
}

@Nonnull
Expand All @@ -31,15 +31,14 @@ public static <T> Stream<List<T>> batch(@Nonnull Stream<? extends T> source, @No
}

@Nonnull
public static <T> Stream<T> generate(@Nonnull Generator<? extends T> supplier) {
//noinspection unchecked
return (Stream<T>) stream(SpliteratorUtils.generate(supplier), false)
.onClose(() -> AutoCloseableUtils.closeQuietly(supplier));
public static <T> Stream<T> generate(@Nonnull Generator<? extends T> generator) {
return generate(generator, false);
}

@Nonnull
public static <T> Stream<T> generate(@Nonnull Supplier<? extends T> supplier) {
return generate(() -> valueOf(supplier.get()));
public static <T> Stream<T> generate(@Nonnull Generator<? extends T> generator, boolean parallel) {
return StreamSupport.<T>stream(SpliteratorUtils.generate(generator), parallel)
.onClose(() -> AutoCloseableUtils.closeQuietly(generator));
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/echocat/jsu/TakeWhile.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public TakeWhile(

@Override
public boolean tryAdvance(@Nonnull Consumer<? super T> consumer) {
final AtomicReference<T> reference = new AtomicReference<>();
final var reference = new AtomicReference<T>();
if (!source().tryAdvance(reference::set)) {
return false;
}
Expand Down
Loading

0 comments on commit c5f7481

Please sign in to comment.