diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-12-12 17:16:05 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2016-12-13 14:48:31 +0100 |
commit | a01c99bb547c5f9318eb536f03e473e8cb6f1126 (patch) | |
tree | b830158f84979d9ba83b8bd43617326949be9775 /sonar-core | |
parent | fb9f4f8314cc44d45aef2f41a82520d969080444 (diff) | |
download | sonarqube-a01c99bb547c5f9318eb536f03e473e8cb6f1126.tar.gz sonarqube-a01c99bb547c5f9318eb536f03e473e8cb6f1126.zip |
SONAR-8467 Create WS api/project_analyses/search
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/util/stream/Collectors.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/util/stream/Collectors.java b/sonar-core/src/main/java/org/sonar/core/util/stream/Collectors.java index 449261a6c4a..40990df3018 100644 --- a/sonar-core/src/main/java/org/sonar/core/util/stream/Collectors.java +++ b/sonar-core/src/main/java/org/sonar/core/util/stream/Collectors.java @@ -260,6 +260,21 @@ public final class Collectors { Collector.Characteristics.UNORDERED); } + /** + * For stream of one expected element, return the element + * @throws IllegalArgumentException if stream has no element or more than 1 element + */ + public static <T> Collector<T, ?, T> toOneElement() { + return java.util.stream.Collectors.collectingAndThen( + java.util.stream.Collectors.toList(), + list -> { + if (list.size() != 1) { + throw new IllegalStateException("Stream should have only one element"); + } + return list.get(0); + }); + } + private static <K, V> Supplier<Map<K, V>> newHashMapSupplier(int expectedSize) { return () -> expectedSize == DEFAULT_HASHMAP_CAPACITY ? new HashMap<>() : new HashMap<>(expectedSize); } |