[java-shib-shared] branch main updated: Add NonnullFunction and convert reloadable service strategies to it.

Scott Cantor cantor.2 at osu.edu
Mon Nov 28 20:53:31 UTC 2022


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=93fc5b197e7a5e31b9aee16781df65411781ed03

The following commit(s) were added to refs/heads/main by this push:
     new 93fc5b19 Add NonnullFunction and convert reloadable service strategies to it.
93fc5b19 is described below

commit 93fc5b197e7a5e31b9aee16781df65411781ed03
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Nov 28 15:53:28 2022 -0500

    Add NonnullFunction and convert reloadable service strategies to it.
---
 .../service/ApplicationContextServiceStrategy.java    |  5 ++---
 .../spring/service/ClassBasedServiceStrategy.java     |  6 +++---
 .../spring/service/ReloadableSpringService.java       |  5 +++--
 .../NonnullFunction.java}                             | 19 ++++++++++++-------
 .../shibboleth/shared/primitive/NonnullSupplier.java  |  4 +++-
 5 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/shib-service/src/main/java/net/shibboleth/shared/spring/service/ApplicationContextServiceStrategy.java b/shib-service/src/main/java/net/shibboleth/shared/spring/service/ApplicationContextServiceStrategy.java
index 1ebb0276..4558c3ae 100644
--- a/shib-service/src/main/java/net/shibboleth/shared/spring/service/ApplicationContextServiceStrategy.java
+++ b/shib-service/src/main/java/net/shibboleth/shared/spring/service/ApplicationContextServiceStrategy.java
@@ -17,14 +17,13 @@
 
 package net.shibboleth.shared.spring.service;
 
-import java.util.function.Function;
-
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.springframework.context.ApplicationContext;
 
 import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.logic.NonnullFunction;
 import net.shibboleth.shared.service.ServiceException;
 
 /**
@@ -34,7 +33,7 @@ import net.shibboleth.shared.service.ServiceException;
  * @since 5.4.0
  */
 public class ApplicationContextServiceStrategy implements
-        Function<ApplicationContext, AbstractServiceableComponent<ApplicationContext>> {
+        NonnullFunction<ApplicationContext, AbstractServiceableComponent<ApplicationContext>> {
     
     /** {@inheritDoc} */
     @Nonnull public AbstractServiceableComponent<ApplicationContext> apply(@Nullable final ApplicationContext appContext) {
diff --git a/shib-service/src/main/java/net/shibboleth/shared/spring/service/ClassBasedServiceStrategy.java b/shib-service/src/main/java/net/shibboleth/shared/spring/service/ClassBasedServiceStrategy.java
index 7e9a2858..ade63af9 100644
--- a/shib-service/src/main/java/net/shibboleth/shared/spring/service/ClassBasedServiceStrategy.java
+++ b/shib-service/src/main/java/net/shibboleth/shared/spring/service/ClassBasedServiceStrategy.java
@@ -18,7 +18,6 @@
 package net.shibboleth.shared.spring.service;
 
 import java.util.Collection;
-import java.util.function.Function;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -28,6 +27,7 @@ import org.springframework.context.ApplicationContext;
 import net.shibboleth.shared.annotation.ParameterName;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.NonnullFunction;
 import net.shibboleth.shared.service.ServiceException;
 import net.shibboleth.shared.spring.service.impl.SpringServiceableComponent;
 
@@ -36,7 +36,7 @@ import net.shibboleth.shared.spring.service.impl.SpringServiceableComponent;
  * 
  * @param <T> the service type to look for
  */
-public class ClassBasedServiceStrategy<T> implements Function<ApplicationContext, AbstractServiceableComponent<T>> {
+public class ClassBasedServiceStrategy<T> implements NonnullFunction<ApplicationContext, AbstractServiceableComponent<T>> {
 
     /** The class we are looking for. */
     @Nonnull private final Class<T> serviceClaz;
@@ -52,7 +52,7 @@ public class ClassBasedServiceStrategy<T> implements Function<ApplicationContext
     }
 
     /** {@inheritDoc} */
-    @Nullable public AbstractServiceableComponent<T> apply(@Nullable final ApplicationContext appContext) {
+    @Nonnull public AbstractServiceableComponent<T> apply(@Nullable final ApplicationContext appContext) {
         
         if (appContext == null) {
             throw new ServiceException("Input ApplicationContext was null");
diff --git a/shib-service/src/main/java/net/shibboleth/shared/spring/service/ReloadableSpringService.java b/shib-service/src/main/java/net/shibboleth/shared/spring/service/ReloadableSpringService.java
index b136b0ff..5e6af58c 100644
--- a/shib-service/src/main/java/net/shibboleth/shared/spring/service/ReloadableSpringService.java
+++ b/shib-service/src/main/java/net/shibboleth/shared/spring/service/ReloadableSpringService.java
@@ -46,6 +46,7 @@ import net.shibboleth.shared.annotation.ParameterName;
 import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.logic.NonnullFunction;
 import net.shibboleth.shared.primitive.StringSupport;
 import net.shibboleth.shared.service.AbstractReloadableService;
 import net.shibboleth.shared.service.ServiceException;
@@ -89,7 +90,7 @@ public class ReloadableSpringService<T> extends AbstractReloadableService<T> imp
     @Nonnull private final Class<T> theClaz;
 
     /** How to summon up the {@link ServiceableComponent} from the {@link ApplicationContext}. */
-    @Nonnull private final Function<ApplicationContext, AbstractServiceableComponent<T>> serviceStrategy;
+    @Nonnull private final NonnullFunction<ApplicationContext,AbstractServiceableComponent<T>> serviceStrategy;
 
     /** Application context owning this engine. */
     @Nullable private ApplicationContext parentContext;
@@ -126,7 +127,7 @@ public class ReloadableSpringService<T> extends AbstractReloadableService<T> imp
      */
     public ReloadableSpringService(@Nonnull @ParameterName(name="claz") final Class<T> claz,
              @Nonnull @ParameterName(name="strategy")
-                final Function<ApplicationContext,AbstractServiceableComponent<T>> strategy) {
+                final NonnullFunction<ApplicationContext,AbstractServiceableComponent<T>> strategy) {
         theClaz = Constraint.isNotNull(claz, "Class cannot be null");
         serviceStrategy = Constraint.isNotNull(strategy, "Strategy cannot be null");
         factoryPostProcessors = Collections.emptyList();
diff --git a/shib-support/src/main/java/net/shibboleth/shared/primitive/NonnullSupplier.java b/shib-support/src/main/java/net/shibboleth/shared/logic/NonnullFunction.java
similarity index 71%
copy from shib-support/src/main/java/net/shibboleth/shared/primitive/NonnullSupplier.java
copy to shib-support/src/main/java/net/shibboleth/shared/logic/NonnullFunction.java
index 71e520d9..bc5da780 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/primitive/NonnullSupplier.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/logic/NonnullFunction.java
@@ -15,18 +15,23 @@
  * limitations under the License.
  */
 
-package net.shibboleth.shared.primitive;
+package net.shibboleth.shared.logic;
 
-import java.util.function.Supplier;
+import java.util.function.Function;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 /**
- * Implementation of {@link Supplier} that carries the nonnull annotation
- * on the {@link #get()} method.
+ * Implementation of {@link Function} that carries the nonnull annotation
+ * on the {@link #apply(Object)} method.
+ * 
+ * @param <T> input type
+ * @param <U> output type
  */
-public interface NonnullSupplier<T> extends Supplier<T> {
+public interface NonnullFunction<T,U> extends Function<T,U> {
 
     /** {@inheritDoc} */
-    @Override @Nonnull T get();
-}
+    @Nonnull U apply(@Nullable T input);
+
+}
\ No newline at end of file
diff --git a/shib-support/src/main/java/net/shibboleth/shared/primitive/NonnullSupplier.java b/shib-support/src/main/java/net/shibboleth/shared/primitive/NonnullSupplier.java
index 71e520d9..de78c766 100644
--- a/shib-support/src/main/java/net/shibboleth/shared/primitive/NonnullSupplier.java
+++ b/shib-support/src/main/java/net/shibboleth/shared/primitive/NonnullSupplier.java
@@ -24,9 +24,11 @@ import javax.annotation.Nonnull;
 /**
  * Implementation of {@link Supplier} that carries the nonnull annotation
  * on the {@link #get()} method.
+ * 
+ * @param <T> type of object supplied
  */
 public interface NonnullSupplier<T> extends Supplier<T> {
 
     /** {@inheritDoc} */
-    @Override @Nonnull T get();
+    @Nonnull T get();
 }

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


More information about the commits mailing list