[java-support] branch master updated: Add regex predicate.
Scott Cantor
cantor.2 at osu.edu
Fri Jun 2 13:56:51 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=7cec0efad608ed26098959712024c2ce4f2dae3f
The following commit(s) were added to refs/heads/master by this push:
new 7cec0ef Add regex predicate.
7cec0ef is described below
commit 7cec0efad608ed26098959712024c2ce4f2dae3f
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Fri Jun 2 13:56:49 2017 -0400
Add regex predicate.
---
.../java/support/logic/RegexPredicate.java | 67 ++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/logic/RegexPredicate.java b/src/main/java/net/shibboleth/utilities/java/support/logic/RegexPredicate.java
new file mode 100644
index 0000000..a92c213
--- /dev/null
+++ b/src/main/java/net/shibboleth/utilities/java/support/logic/RegexPredicate.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.utilities.java.support.logic;
+
+import java.util.regex.Pattern;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Predicate;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
+/**
+ * A {@link Predicate} that checks that a given input string matches a regular expression. If a given
+ * input is <code>null</code> this predicate returns <code>false</code>.
+ *
+ * @since 7.4.0
+ */
+public class RegexPredicate implements Predicate<CharSequence> {
+
+ /** Regular expression. */
+ @Nullable private Pattern pattern;
+
+ /**
+ * Pattern constructor.
+ *
+ * @param p the pattern to match the input against
+ */
+ public RegexPredicate(@Nonnull final Pattern p) {
+ pattern = p;
+ }
+
+ /**
+ * String constructor.
+ *
+ * @param s the pattern to match the input against
+ */
+ public RegexPredicate(@Nonnull @NotEmpty final String s) {
+ pattern = Pattern.compile(s);
+ }
+
+ /** {@inheritDoc} */
+ public boolean apply(final CharSequence input) {
+ if (input == null) {
+ return false;
+ }
+
+ return pattern.matcher(input).matches();
+ }
+
+}
\ 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