#136 - Replace Streamable with the one from Spring Data Commons.

This commit is contained in:
Mark Paluch
2020-02-26 14:11:07 +01:00
parent 5231a0e572
commit 49bbb32d77
14 changed files with 41 additions and 71 deletions

View File

@@ -33,6 +33,11 @@
<artifactId>spring-web</artifactId> <artifactId>spring-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.release;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* SImple interface to ease streamability of {@link Iterable}s.
*
* @author Oliver Gierke
*/
public interface Streamable<T> extends Iterable<T> {
/**
* Creates a non-parallel {@link Stream} of the underlying {@link Iterable}.
*
* @return will never be {@literal null}.
*/
public default Stream<T> stream() {
return StreamSupport.stream(spliterator(), false);
}
}

View File

@@ -39,11 +39,11 @@ import java.util.stream.Collector;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import org.springframework.data.release.Streamable;
import org.springframework.data.release.model.Project; import org.springframework.data.release.model.Project;
import org.springframework.data.release.model.ProjectAware; import org.springframework.data.release.model.ProjectAware;
import org.springframework.data.release.utils.ListWrapperCollector; import org.springframework.data.release.utils.ListWrapperCollector;
import org.springframework.data.release.utils.Logger; import org.springframework.data.release.utils.Logger;
import org.springframework.data.util.Streamable;
import org.springframework.plugin.core.PluginRegistry; import org.springframework.plugin.core.PluginRegistry;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.Assert; import org.springframework.util.Assert;

View File

@@ -15,23 +15,23 @@
*/ */
package org.springframework.data.release.git; package org.springframework.data.release.git;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.data.release.Streamable;
import org.springframework.data.release.issues.Ticket; import org.springframework.data.release.issues.Ticket;
import org.springframework.data.util.Streamable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
/** /**
* Value object to represent a collection of {@link Branch}es with assigned tickets. * Value object to represent a collection of {@link Branch}es with assigned tickets.
* *
* @author Mark Paluch * @author Mark Paluch
* @author Oliver Gierke * @author Oliver Gierke
*/ */
@@ -44,7 +44,7 @@ public class TicketBranches implements Streamable<Branch> {
/** /**
* Returns whether there's a ticket available for the given {@link Branch}. If {@code requireResolved} is set to * Returns whether there's a ticket available for the given {@link Branch}. If {@code requireResolved} is set to
* {@literal true} the answer will only be true if the available ticket is marked resolved. * {@literal true} the answer will only be true if the available ticket is marked resolved.
* *
* @param branch must not be {@literal null}. * @param branch must not be {@literal null}.
* @param requireResolved whether the {@link Ticket} we look for is required to be resolved. * @param requireResolved whether the {@link Ticket} we look for is required to be resolved.
* @return * @return
@@ -60,7 +60,7 @@ public class TicketBranches implements Streamable<Branch> {
/** /**
* Returns a {@link TicketBranches} containing only the branches for which resolved {@link Ticket}s are found. * Returns a {@link TicketBranches} containing only the branches for which resolved {@link Ticket}s are found.
* *
* @return * @return
*/ */
public TicketBranches getResolvedTickets() { public TicketBranches getResolvedTickets() {
@@ -72,7 +72,7 @@ public class TicketBranches implements Streamable<Branch> {
/** /**
* Returns the ticket for the given {@link Branch}. * Returns the ticket for the given {@link Branch}.
* *
* @param branch must not be {@literal null}. * @param branch must not be {@literal null}.
* @return * @return
*/ */

View File

@@ -21,14 +21,14 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.data.release.Streamable;
import org.springframework.data.release.model.ArtifactVersion; import org.springframework.data.release.model.ArtifactVersion;
import org.springframework.data.release.model.ModuleIteration; import org.springframework.data.release.model.ModuleIteration;
import org.springframework.data.util.Streamable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Value object to represent a collection of {@link Tag}s. * Value object to represent a collection of {@link Tag}s.
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
@EqualsAndHashCode @EqualsAndHashCode
@@ -38,7 +38,7 @@ public class VersionTags implements Streamable<Tag> {
/** /**
* Creates a new {@link VersionTags} instance for the given {@link List} of {@link Tag}s. * Creates a new {@link VersionTags} instance for the given {@link List} of {@link Tag}s.
* *
* @param source must not be {@literal null}. * @param source must not be {@literal null}.
*/ */
VersionTags(List<Tag> source) { VersionTags(List<Tag> source) {
@@ -52,7 +52,7 @@ public class VersionTags implements Streamable<Tag> {
/** /**
* Returns the latest {@link Tag}. * Returns the latest {@link Tag}.
* *
* @return * @return
*/ */
public Tag getLatest() { public Tag getLatest() {
@@ -65,14 +65,14 @@ public class VersionTags implements Streamable<Tag> {
/** /**
* Returns all {@link Tag}s as {@link List}. * Returns all {@link Tag}s as {@link List}.
* *
* @return * @return
*/ */
public List<Tag> asList() { public List<Tag> asList() {
return tags; return tags;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see java.lang.Iterable#iterator() * @see java.lang.Iterable#iterator()
*/ */

View File

@@ -25,10 +25,10 @@ import java.util.Optional;
import java.util.stream.Collector; import java.util.stream.Collector;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.springframework.data.release.Streamable;
import org.springframework.data.release.model.ModuleIteration; import org.springframework.data.release.model.ModuleIteration;
import org.springframework.data.release.model.TrainIteration; import org.springframework.data.release.model.TrainIteration;
import org.springframework.data.release.utils.ListWrapperCollector; import org.springframework.data.release.utils.ListWrapperCollector;
import org.springframework.data.util.Streamable;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**

View File

@@ -22,7 +22,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.springframework.data.release.Streamable; import org.springframework.data.util.Streamable;
/** /**
* @author Oliver Gierke * @author Oliver Gierke
@@ -46,7 +46,7 @@ class JiraIssues implements Streamable<JiraIssue> {
return !issues.isEmpty(); return !issues.isEmpty();
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see java.lang.Iterable#iterator() * @see java.lang.Iterable#iterator()
*/ */

View File

@@ -21,11 +21,11 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.springframework.data.release.Streamable; import org.springframework.data.util.Streamable;
/** /**
* Value object to bind REST responses to. * Value object to bind REST responses to.
* *
* @author Mark Paluch * @author Mark Paluch
*/ */
@Value @Value

View File

@@ -19,12 +19,12 @@ import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.TreeSet; import java.util.TreeSet;
import org.springframework.data.release.Streamable; import org.springframework.data.util.Streamable;
/** /**
* A {@link Streamable} set of modules. Makes sure the stream order will match the natural dependency order of the given * A {@link Streamable} set of modules. Makes sure the stream order will match the natural dependency order of the given
* {@link Module} instances. * {@link Module} instances.
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
class Modules implements Streamable<Module> { class Modules implements Streamable<Module> {

View File

@@ -62,7 +62,8 @@ public class ReleaseTrains {
new Module(MONGO_DB, "3.0"), // new Module(MONGO_DB, "3.0"), //
new Module(JDBC, "2.0"), // new Module(JDBC, "2.0"), //
new Module(R2DBC, "1.1")) // new Module(R2DBC, "1.1")) //
.filter(module -> !module.getProject().equals(GEMFIRE)).withIterations(new Train.Iterations(M1, M2, M3, RC1, GA)); .filterModules(module -> !module.getProject().equals(GEMFIRE))
.withIterations(new Train.Iterations(M1, M2, M3, M4, RC1, GA));
// Trains // Trains

View File

@@ -36,7 +36,7 @@ import java.util.stream.Stream;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.springframework.data.release.Streamable; import org.springframework.data.util.Streamable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@@ -115,7 +115,7 @@ public class Train implements Streamable<Module> {
return new Train(name, collect); return new Train(name, collect);
} }
public Train filter(Predicate<Module> filterPredicate) { public Train filterModules(Predicate<Module> filterPredicate) {
return new Train(name, getModules().stream().filter(filterPredicate).collect(Collectors.toList())); return new Train(name, getModules().stream().filter(filterPredicate).collect(Collectors.toList()));
} }

View File

@@ -21,7 +21,7 @@ import lombok.Value;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.springframework.data.release.Streamable; import org.springframework.data.util.Streamable;
/** /**
* @author Oliver Gierke * @author Oliver Gierke

View File

@@ -23,12 +23,12 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.data.release.Streamable;
import org.springframework.data.release.model.ArtifactVersion; import org.springframework.data.release.model.ArtifactVersion;
import org.springframework.data.util.Streamable;
/** /**
* Wrapper type for a {@link List} of {@link MaintainedVersion}. * Wrapper type for a {@link List} of {@link MaintainedVersion}.
* *
* @author Oliver Gierke * @author Oliver Gierke
*/ */
@ToString @ToString
@@ -40,7 +40,7 @@ class MaintainedVersions implements Streamable<MaintainedVersion> {
/** /**
* Creates a new {@link MaintainedVersions} with the given {@link MaintainedVersion}s in descending order (more recent * Creates a new {@link MaintainedVersions} with the given {@link MaintainedVersion}s in descending order (more recent
* versions first). * versions first).
* *
* @param versions must not be {@literal null}. * @param versions must not be {@literal null}.
* @return * @return
*/ */
@@ -54,7 +54,7 @@ class MaintainedVersions implements Streamable<MaintainedVersion> {
/** /**
* Creates a new {@link MaintainedVersions} with the given {@link MaintainedVersion}s in descending order (more recent * Creates a new {@link MaintainedVersions} with the given {@link MaintainedVersion}s in descending order (more recent
* versions first). * versions first).
* *
* @param versions must not be {@literal null}. * @param versions must not be {@literal null}.
* @return * @return
*/ */
@@ -64,7 +64,7 @@ class MaintainedVersions implements Streamable<MaintainedVersion> {
/** /**
* Returns whether the given {@link MaintainedVersion} is the main version of the current set. * Returns whether the given {@link MaintainedVersion} is the main version of the current set.
* *
* @param version must not be {@literal null}. * @param version must not be {@literal null}.
* @return * @return
*/ */
@@ -82,7 +82,7 @@ class MaintainedVersions implements Streamable<MaintainedVersion> {
.orElse(false); .orElse(false);
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see java.lang.Iterable#iterator() * @see java.lang.Iterable#iterator()
*/ */

View File

@@ -24,7 +24,7 @@ import java.util.function.Function;
import java.util.stream.Collector; import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.data.release.Streamable; import org.springframework.data.util.Streamable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@@ -75,7 +75,7 @@ public class ExecutionUtils {
Collector<? super S, ?, R> collector) { Collector<? super S, ?, R> collector) {
Assert.notNull(streamable, "Iterable must not be null!"); Assert.notNull(streamable, "Iterable must not be null!");
Assert.notNull(function, "Consumer must not be null!"); Assert.notNull(function, "Function must not be null!");
return streamable.stream().// return streamable.stream().//
map(it -> CompletableFuture.supplyAsync(() -> function.apply(it))).// map(it -> CompletableFuture.supplyAsync(() -> function.apply(it))).//