[java-shib-shared] branch main updated: Null Support: New NonNull collection creation methods
Rod Widdowson
rdw at steadingsoftware.com
Tue Jan 24 14:21:22 UTC 2023
This is an automated email from the git hooks/post-receive script.
rdw 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=956dee4a6b46f058f6180ae7f75d414436ca687e
The following commit(s) were added to refs/heads/main by this push:
new 956dee4a Null Support: New NonNull collection creation methods
956dee4a is described below
commit 956dee4a6b46f058f6180ae7f75d414436ca687e
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jan 24 14:06:54 2023 +0000
Null Support: New NonNull collection creation methods
Add a 2 parameter and a vararg version of CollectionSupport.setOf and listOf
Use them.
---
.../shared/net/MediaTypeSupportTest.java | 30 +++++----
.../servlet/impl/HttpServletSupportTest.java | 21 +++---
.../shared/collection/CollectionSupport.java | 78 +++++++++++++++++++---
3 files changed, 94 insertions(+), 35 deletions(-)
diff --git a/shib-networking/src/test/java/net/shibboleth/shared/net/MediaTypeSupportTest.java b/shib-networking/src/test/java/net/shibboleth/shared/net/MediaTypeSupportTest.java
index df3da5cc..5961698c 100644
--- a/shib-networking/src/test/java/net/shibboleth/shared/net/MediaTypeSupportTest.java
+++ b/shib-networking/src/test/java/net/shibboleth/shared/net/MediaTypeSupportTest.java
@@ -24,6 +24,8 @@ import org.testng.annotations.Test;
import com.google.common.net.MediaType;
+import net.shibboleth.shared.collection.CollectionSupport;
+
/**
*
*/
@@ -34,12 +36,12 @@ public class MediaTypeSupportTest {
// No Content-type
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.XML_UTF_8),
+ CollectionSupport.singleton(MediaType.XML_UTF_8),
true,
false));
Assert.assertFalse(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.XML_UTF_8),
+ CollectionSupport.singleton(MediaType.XML_UTF_8),
false,
false));
@@ -47,32 +49,32 @@ public class MediaTypeSupportTest {
contentType = "text/xml; charset=utf-8";
Assert.assertFalse(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.create("application", "foobar")),
+ CollectionSupport.singleton(MediaType.create("application", "foobar")),
true,
false));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
false));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
true,
true));
@@ -80,33 +82,33 @@ public class MediaTypeSupportTest {
contentType = "text/xml";
Assert.assertFalse(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.create("application", "foobar")),
+ CollectionSupport.singleton(MediaType.create("application", "foobar")),
true,
false));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
false));
// Not valid, because the text/xml valid type includes parameters
Assert.assertFalse(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(MediaTypeSupport.validateContentType(contentType,
- Set.of(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
true,
true));
diff --git a/shib-networking/src/test/java/net/shibboleth/shared/servlet/impl/HttpServletSupportTest.java b/shib-networking/src/test/java/net/shibboleth/shared/servlet/impl/HttpServletSupportTest.java
index 0695a1f4..c863deff 100644
--- a/shib-networking/src/test/java/net/shibboleth/shared/servlet/impl/HttpServletSupportTest.java
+++ b/shib-networking/src/test/java/net/shibboleth/shared/servlet/impl/HttpServletSupportTest.java
@@ -29,6 +29,7 @@ import org.testng.annotations.Test;
import com.google.common.net.MediaType;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.servlet.HttpServletSupport;
@@ -97,27 +98,27 @@ public class HttpServletSupportTest {
false));
Assert.assertTrue(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
false));
Assert.assertTrue(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
true,
true));
@@ -130,28 +131,28 @@ public class HttpServletSupportTest {
false));
Assert.assertTrue(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
false));
// Not valid, because the text/xml valid type includes parameters
Assert.assertFalse(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.XML_UTF_8.withoutParameters(), MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.ANY_TEXT_TYPE, MediaType.create("application", "foobar")),
true,
true));
Assert.assertTrue(HttpServletSupport.validateContentType(request,
- Set.of(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
+ CollectionSupport.setOf(MediaType.ANY_TYPE, MediaType.create("application", "foobar")),
true,
true));
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 1c25886e..50c8c5b6 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
@@ -70,9 +70,9 @@ public final class CollectionSupport {
/**
* Gets an empty list with non-null guarantee.
- *
+ *
* @param <T> list type
- *
+ *
* @return empty list
*/
@SuppressWarnings("null")
@@ -82,7 +82,7 @@ public final class CollectionSupport {
/**
* Gets a singleton list with non-null guarantee.
- *
+ *
* @param <T> list type
* @param item the single item
*
@@ -92,14 +92,42 @@ public final class CollectionSupport {
@Nonnull @Unmodifiable @NotLive public static <T> List<T> singletonList(@Nonnull final T item) {
return Collections.singletonList(item);
}
-
+
/**
- * Copies a collection to a list with non-null guarantee.
+ * Gets a two member list with non-null guarantee.
*
* @param <T> list type
- *
+ * @param first the first item
+ * @param second the second item
+ *
+ * @return two member list
+ */
+ @SuppressWarnings("null")
+ @Nonnull @Unmodifiable @NotLive public static <T> List<T> listOf(@Nonnull final T first, @Nonnull final T second) {
+ return List.of(first, second);
+ }
+
+ /**
+ * Gets a list with non-null guarantee and a variable number of members
+ *
+ * @param <T> list type
+ * @param elements the elements
+ *
+ * @return multi member list
+ */
+ @SafeVarargs
+ @SuppressWarnings("null")
+ @Nonnull @Unmodifiable @NotLive public static <T> List<T> listOf(@Nonnull final T... elements) {
+ return List.of(elements);
+ }
+
+ /**
+ * Copies a collection to a list with non-null guarantee.
+ *
+ * @param <T> list type
+ *
* @param coll collection to copy
- *
+ *
* @return immutable copied list
*/
@SuppressWarnings("null")
@@ -110,9 +138,9 @@ public final class CollectionSupport {
/**
* Gets an empty set with non-null guarantee.
- *
+ *
* @param <T> set type
- *
+ *
* @return empty set
*/
@SuppressWarnings("null")
@@ -122,10 +150,10 @@ public final class CollectionSupport {
/**
* Gets a singleton set with non-null guarantee.
- *
+ *
* @param <T> set type
* @param item the single item
- *
+ *
* @return singleton set
*/
@SuppressWarnings("null")
@@ -133,6 +161,34 @@ public final class CollectionSupport {
return Collections.singleton(item);
}
+ /**
+ * Gets a two member set with non-null guarantee.
+ *
+ * @param <T> list type
+ * @param first the first item
+ * @param second the second item
+ *
+ * @return two member set
+ */
+ @SuppressWarnings("null")
+ @Nonnull @Unmodifiable @NotLive public static <T> Set<T> settOf(@Nonnull final T first, @Nonnull final T second) {
+ return Set.of(first, second);
+ }
+
+ /**
+ * Gets a set with non-null guarantee and a variable number of members
+ *
+ * @param <T> list type
+ * @param elements the elements
+ *
+ * @return multi member set
+ */
+ @SafeVarargs
+ @SuppressWarnings("null")
+ @Nonnull @Unmodifiable @NotLive public static <T> Set<T> setOf(@Nonnull final T... elements) {
+ return Set.of(elements);
+ }
+
/**
* Copies a collection to a set with non-null guarantee.
*
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list