[java-support] branch master updated: Null-safe immutable collection builders.
Scott Cantor
cantor.2 at osu.edu
Tue Mar 26 20:54:20 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=d7aaa1f5903be24efac8849e00f6e47cf719d754
The following commit(s) were added to refs/heads/master by this push:
new d7aaa1f Null-safe immutable collection builders.
d7aaa1f is described below
commit d7aaa1f5903be24efac8849e00f6e47cf719d754
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Mar 26 20:54:17 2019 -0400
Null-safe immutable collection builders.
---
.../java/support/collection/CollectionSupport.java | 47 ++++++++++++++++++++++
1 file changed, 47 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 bc93eb7..1f75023 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
@@ -18,12 +18,20 @@
package net.shibboleth.utilities.java.support.collection;
import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotLive;
+import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
import net.shibboleth.utilities.java.support.logic.Constraint;
/** Helper methods for working with collections of objects. */
@@ -33,6 +41,45 @@ public final class CollectionSupport {
private CollectionSupport() {
}
+
+ /**
+ * Builds an immutable list containing the source collection, allowing for a null collection.
+ *
+ * @param <T> source type
+ * @param source objects to populate into list, or null
+ *
+ * @return An immutable list containing the source objects
+ *
+ * @since 8.0.0
+ */
+ @Nonnull @NotLive @Unmodifiable public static <T> List<T> buildImmutableList(
+ @Nullable final Collection<? extends T> source) {
+ if (source != null) {
+ return ImmutableList.copyOf(source);
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ /**
+ * Builds an immutable set containing the source collection, allowing for a null collection.
+ *
+ * @param <T> source type
+ * @param source objects to populate into set, or null
+ *
+ * @return An immutable set containing the source objects
+ *
+ * @since 8.0.0
+ */
+ @Nonnull @NotLive @Unmodifiable public static <T> Set<T> buildImmutableSet(
+ @Nullable final Collection<? extends T> source) {
+ if (source != null) {
+ return ImmutableSet.copyOf(source);
+ } else {
+ return Collections.emptySet();
+ }
+ }
+
/**
* Adds an element to a collection if it meets the requirements of a given predicate.
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list