Repository: bval
Updated Branches:
  refs/heads/bv2 513606da5 -> eab5a0123


ToUnmodifiable#* returns empty collection/map when possible


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/d9cb6a7f
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/d9cb6a7f
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/d9cb6a7f

Branch: refs/heads/bv2
Commit: d9cb6a7f600c4e352160c01d85f985bf0623eeba
Parents: 513606d
Author: Matt Benson <[email protected]>
Authored: Thu Mar 22 13:56:48 2018 -0500
Committer: Matt Benson <[email protected]>
Committed: Thu Mar 22 13:56:48 2018 -0500

----------------------------------------------------------------------
 .../java/org/apache/bval/jsr/util/ToUnmodifiable.java    | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/d9cb6a7f/bval-jsr/src/main/java/org/apache/bval/jsr/util/ToUnmodifiable.java
----------------------------------------------------------------------
diff --git 
a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ToUnmodifiable.java 
b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ToUnmodifiable.java
index 98c70be..6f6b021 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/util/ToUnmodifiable.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/util/ToUnmodifiable.java
@@ -32,19 +32,22 @@ import java.util.stream.Collectors;
 public class ToUnmodifiable {
 
     public static <T> Collector<T, ?, Set<T>> set(Supplier<Set<T>> set) {
-        return Collectors.collectingAndThen(Collectors.toCollection(set), 
Collections::unmodifiableSet);
+        return Collectors.collectingAndThen(Collectors.toCollection(set),
+            t -> t.isEmpty() ? Collections.emptySet() : 
Collections.unmodifiableSet(t));
     }
 
     public static <T> Collector<T, ?, Set<T>> set() {
-        return 
Collectors.collectingAndThen(Collectors.toCollection(LinkedHashSet::new), 
Collections::unmodifiableSet);
+        return set(LinkedHashSet::new);
     }
 
     public static <T> Collector<T, ?, List<T>> list() {
-        return Collectors.collectingAndThen(Collectors.toList(), 
Collections::unmodifiableList);
+        return Collectors.collectingAndThen(Collectors.toList(),
+            t -> t.isEmpty() ? Collections.emptyList() : 
Collections.unmodifiableList(t));
     }
 
     public static <T, K, U> Collector<T, ?, Map<K, U>> map(Function<? super T, 
? extends K> keyMapper,
         Function<? super T, ? extends U> valueMapper) {
-        return Collectors.collectingAndThen(Collectors.toMap(keyMapper, 
valueMapper), Collections::unmodifiableMap);
+        return Collectors.collectingAndThen(Collectors.toMap(keyMapper, 
valueMapper),
+            t -> t.isEmpty() ? Collections.emptyMap() : 
Collections.unmodifiableMap(t));
     }
 }

Reply via email to