[java-support] branch master updated: Add null-safe map builder.

Scott Cantor cantor.2 at osu.edu
Wed Mar 27 11:21:52 EDT 2019


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch master
in repository java-support.

View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=336fe0858f84f8632d065f465fb17a9ae702bead

The following commit(s) were added to refs/heads/master by this push:
       new  336fe08   Add null-safe map builder.
336fe08 is described below

commit 336fe0858f84f8632d065f465fb17a9ae702bead
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Mar 27 11:21:47 2019 -0400

    Add null-safe map builder.
---
 .../java/support/collection/CollectionSupport.java | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java b/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java
index 1f75023..38082d1 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/collection/CollectionSupport.java
@@ -20,6 +20,7 @@ package net.shibboleth.utilities.java.support.collection;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.function.Function;
 import java.util.function.Predicate;
@@ -28,6 +29,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
 import net.shibboleth.utilities.java.support.annotation.constraint.NotLive;
@@ -79,6 +81,26 @@ public final class CollectionSupport {
             return Collections.emptySet();
         }
     }    
+
+    /**
+     * Builds an immutable set containing the source collection, allowing for a null collection.
+     * 
+     * @param <K> key type
+     * @param <V> value type
+     * @param source objects to populate into map, or null
+     * 
+     * @return An immutable map containing the source objects
+     * 
+     * @since 8.0.0
+     */
+    @Nonnull @NotLive @Unmodifiable public static <K,V> Map<K,V> buildImmutableMap(
+            @Nullable final Map<? extends K, ? extends V> source) {
+        if (source != null) {
+            return ImmutableMap.copyOf(source);
+        } else {
+            return Collections.emptyMap();
+        }
+    }    
     
 
     /**

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list