[java-shib-shared] branch main updated: Add non-null empty collection wrappers.
Scott Cantor
cantor.2 at osu.edu
Fri Jan 20 17:29:45 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=af17801ef274e90dbf5c1df9b1bce32717246f80
The following commit(s) were added to refs/heads/main by this push:
new af17801e Add non-null empty collection wrappers.
af17801e is described below
commit af17801ef274e90dbf5c1df9b1bce32717246f80
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Fri Jan 20 12:29:42 2023 -0500
Add non-null empty collection wrappers.
---
.../shared/collection/CollectionSupport.java | 50 ++++++++++++++++++++--
1 file changed, 47 insertions(+), 3 deletions(-)
diff --git a/shib-support/src/main/java/net/shibboleth/shared/collection/CollectionSupport.java b/shib-support/src/main/java/net/shibboleth/shared/collection/CollectionSupport.java
index 8975ec91..6a4e9005 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/collection/CollectionSupport.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/collection/CollectionSupport.java
@@ -17,9 +17,15 @@
package net.shibboleth.shared.collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -29,7 +35,7 @@ import org.slf4j.LoggerFactory;
public final class CollectionSupport {
/** logger. */
- private static Logger log = LoggerFactory.getLogger(CollectionSupport.class);
+ @Nonnull private static Logger log = LoggerFactory.getLogger(CollectionSupport.class);
/** Constructor. */
private CollectionSupport() {
@@ -42,7 +48,7 @@ public final class CollectionSupport {
* @param takeFirst do we want the first of the last to win.
* @return an appropriate {@link BinaryOperator}
*/
- public static <T> BinaryOperator<T> warningMergeFunction(final String what, final boolean takeFirst) {
+ @Nonnull public static <T> BinaryOperator<T> warningMergeFunction(final String what, final boolean takeFirst) {
return new BinaryOperator<>() {
@@ -55,4 +61,42 @@ public final class CollectionSupport {
};
}
-}
+
+ /**
+ * Gets an empty list with non-null guarantee.
+ *
+ * @param <T> list type
+ *
+ * @return empty list
+ */
+ @SuppressWarnings("null")
+ @Nonnull public static <T> List<T> emptyList() {
+ return Collections.emptyList();
+ }
+
+ /**
+ * Gets an empty set with non-null guarantee.
+ *
+ * @param <T> set type
+ *
+ * @return empty set
+ */
+ @SuppressWarnings("null")
+ @Nonnull public static <T> Set<T> emptySet() {
+ return Collections.emptySet();
+ }
+
+ /**
+ * Gets an empty map with non-null guarantee.
+ *
+ * @param <T> key type
+ * @param <U> value type
+ *
+ * @return empty amp
+ */
+ @SuppressWarnings("null")
+ @Nonnull public static <T,U> Map<T,U> emptyMap() {
+ return Collections.emptyMap();
+ }
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list