[java-support] branch master updated: Add a Function to Predicate adapter.
Scott Cantor
cantor.2 at osu.edu
Thu Mar 23 15:48:41 EDT 2017
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=b3430003e971799ceae9350814422b5fb3041c90
The following commit(s) were added to refs/heads/master by this push:
new b343000 Add a Function to Predicate adapter.
b343000 is described below
commit b3430003e971799ceae9350814422b5fb3041c90
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Mar 23 15:48:32 2017 -0400
Add a Function to Predicate adapter.
---
.../java/support/logic/PredicateSupport.java | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/logic/PredicateSupport.java b/src/main/java/net/shibboleth/utilities/java/support/logic/PredicateSupport.java
index 4f6e764..0831f46 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/logic/PredicateSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/logic/PredicateSupport.java
@@ -18,7 +18,9 @@
package net.shibboleth.utilities.java.support.logic;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import com.google.common.base.Function;
import com.google.common.base.Predicate;
/**
@@ -65,4 +67,26 @@ public final class PredicateSupport {
@Nonnull public static Predicate<CharSequence> caseInsensitiveMatch(@Nonnull final String target) {
return new CaseInsensitiveStringMatchPredicate(target);
}
+
+ /**
+ * Creates a predicate that applies a function to an input and returns its result, or a default value
+ * if null.
+ *
+ * @param <T> type of function input
+ *
+ * @param function function to apply to input
+ * @param defValue default value if function returns null
+ *
+ * @return a predicate adapter
+ */
+ @Nonnull public static <T> Predicate<T> fromFunction(@Nonnull final Function<T,Boolean> function,
+ final boolean defValue) {
+ return new Predicate<T>() {
+ public boolean apply(@Nullable final T input) {
+ final Boolean result = function.apply(input);
+ return result != null ? result : defValue;
+ }
+ };
+ }
+
}
\ 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