aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common
diff options
context:
space:
mode:
authorPierre <pierre.guillot@sonarsource.com>2020-12-08 13:01:37 +0100
committersonartech <sonartech@sonarsource.com>2020-12-09 20:07:21 +0000
commit2ac64829407349d696108c9d09c70d7ea2ad266a (patch)
tree8ac9725c0d669fa1187935726960c613b6352e15 /server/sonar-server-common
parentfc6b79aaba37e38c01a5cac7d061b401a17947f8 (diff)
downloadsonarqube-2ac64829407349d696108c9d09c70d7ea2ad266a.tar.gz
sonarqube-2ac64829407349d696108c9d09c70d7ea2ad266a.zip
remove use of Stream.peek()
Diffstat (limited to 'server/sonar-server-common')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/es/textsearch/ComponentTextSearchQueryFactory.java8
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/State.java20
2 files changed, 10 insertions, 18 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/textsearch/ComponentTextSearchQueryFactory.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/textsearch/ComponentTextSearchQueryFactory.java
index 060b0504956..462dd50d378 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/es/textsearch/ComponentTextSearchQueryFactory.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/textsearch/ComponentTextSearchQueryFactory.java
@@ -25,7 +25,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.sonar.server.es.textsearch.ComponentTextSearchFeature.UseCase;
@@ -58,16 +57,15 @@ public class ComponentTextSearchQueryFactory {
private static Optional<QueryBuilder> createQuery(ComponentTextSearchQuery query, ComponentTextSearchFeature[] features, UseCase useCase) {
BoolQueryBuilder generateResults = boolQuery();
- AtomicBoolean anyFeatures = new AtomicBoolean();
Arrays.stream(features)
.filter(f -> f.getUseCase() == useCase)
- .peek(f -> anyFeatures.set(true))
.flatMap(f -> f.getQueries(query))
.forEach(generateResults::should);
- if (anyFeatures.get()) {
+ if (!generateResults.should().isEmpty()) {
return Optional.of(generateResults);
+ } else {
+ return Optional.empty();
}
- return Optional.empty();
}
public static class ComponentTextSearchQuery {
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/State.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/State.java
index 2e7dbbf74fa..43a7b1c8bcf 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/State.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/workflow/State.java
@@ -62,20 +62,14 @@ public class State {
@CheckForNull
public Transition outAutomaticTransition(Issue issue) {
- final Transition[] result = new Transition[1];
- Set<String> keys = new HashSet<>();
-
- Arrays.stream(outTransitions)
+ List<Transition> transitions = Arrays.stream(outTransitions)
.filter(Transition::automatic)
- .filter(transition -> transition.supports(issue))
- .peek(transition -> result[0] = transition)
- .filter(transition -> !keys.add(transition.key()))
- .findAny()
- .ifPresent(transition -> {
- throw new IllegalArgumentException("Several automatic transitions are available for issue: " + issue);
- });
-
- return result[0];
+ .filter(t -> t.supports(issue))
+ .collect(Collectors.toList());
+ if(transitions.size() > 1){
+ throw new IllegalArgumentException("Several automatic transitions are available for issue: " + issue);
+ }
+ return transitions.size() == 1 ? transitions.get(0) : null;
}
Transition transition(String transitionKey) {