You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/03/22 22:46:03 UTC
git commit: DELTASPIKE-78 fixed utils
Updated Branches:
refs/heads/master bdbb4b30a -> a66fa0288
DELTASPIKE-78 fixed utils
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/a66fa028
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/a66fa028
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/a66fa028
Branch: refs/heads/master
Commit: a66fa028893cc72a6f6277735b50feac20b6edd8
Parents: bdbb4b3
Author: gpetracek <gp...@apache.org>
Authored: Thu Mar 22 22:43:43 2012 +0100
Committer: gpetracek <gp...@apache.org>
Committed: Thu Mar 22 22:43:43 2012 +0100
----------------------------------------------------------------------
.../apache/deltaspike/core/util/StringUtils.java | 38 ++++++
.../deltaspike/test/api/util/StringUtilsTest.java | 35 +++++
.../security/impl/AuthenticatorSelectorImpl.java | 4 +-
.../deltaspike/security/impl/util/Strings.java | 101 ---------------
4 files changed, 75 insertions(+), 103 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a66fa028/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/StringUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/StringUtils.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/StringUtils.java
new file mode 100644
index 0000000..e6761ac
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/StringUtils.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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 org.apache.deltaspike.core.util;
+
+import javax.enterprise.inject.Typed;
+
+@Typed()
+public abstract class StringUtils
+{
+ /**
+ * Constructor which prevents the instantiation of this class
+ */
+ private StringUtils()
+ {
+ // prevent instantiation
+ }
+
+ public static boolean isEmpty(String string)
+ {
+ return string == null || string.trim().isEmpty();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a66fa028/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/util/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/util/StringUtilsTest.java b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/util/StringUtilsTest.java
new file mode 100644
index 0000000..883ce2d
--- /dev/null
+++ b/deltaspike/core/api/src/test/java/org/apache/deltaspike/test/api/util/StringUtilsTest.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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 org.apache.deltaspike.test.api.util;
+
+import org.apache.deltaspike.core.util.StringUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class StringUtilsTest
+{
+ @Test
+ public void emptyStringDetection()
+ {
+ Assert.assertTrue(StringUtils.isEmpty(null));
+ Assert.assertTrue(StringUtils.isEmpty(""));
+ Assert.assertTrue(StringUtils.isEmpty(" "));
+ Assert.assertFalse(StringUtils.isEmpty(" a "));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a66fa028/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/AuthenticatorSelectorImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/AuthenticatorSelectorImpl.java b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/AuthenticatorSelectorImpl.java
index 23a730c..215ee53 100644
--- a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/AuthenticatorSelectorImpl.java
+++ b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/AuthenticatorSelectorImpl.java
@@ -26,10 +26,10 @@ import javax.inject.Inject;
import org.apache.deltaspike.core.api.literal.NamedLiteral;
import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.util.StringUtils;
import org.apache.deltaspike.security.api.AuthenticatorSelector;
import org.apache.deltaspike.security.impl.jaas.JaasAuthenticator;
import org.apache.deltaspike.security.impl.management.IdmAuthenticator;
-import org.apache.deltaspike.security.impl.util.Strings;
import org.apache.deltaspike.security.spi.Authenticator;
/**
@@ -66,7 +66,7 @@ public class AuthenticatorSelectorImpl implements AuthenticatorSelector
return authenticators.select(authenticatorClass).get();
}
- if (!Strings.isEmpty(authenticatorName))
+ if (!StringUtils.isEmpty(authenticatorName))
{
Instance<Authenticator> selected = authenticators.select(new NamedLiteral(authenticatorName));
if (selected.isAmbiguous())
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a66fa028/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/util/Strings.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/util/Strings.java b/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/util/Strings.java
deleted file mode 100644
index c242817..0000000
--- a/deltaspike/modules/security/impl/src/main/java/org/apache/deltaspike/security/impl/util/Strings.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF 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 org.apache.deltaspike.security.impl.util;
-
-/**
- * String utility methods
- */
-public class Strings
-{
- private Strings()
- {
-
- }
-
- public static String unqualify(String name)
- {
- return unqualify(name, '.');
- }
-
- public static String unqualify(String name, char sep)
- {
- return name.substring(name.lastIndexOf(sep) + 1, name.length());
- }
-
- public static boolean isEmpty(String string)
- {
- int len = string.length();
- if (string == null || len == 0)
- {
- return true;
- }
-
- for (int i = 0; i < len; i++)
- {
- if ((Character.isWhitespace(string.charAt(i)) == false))
- {
- return false;
- }
- }
- return true;
- }
-
- public static String toClassNameString(String sep, Object... objects)
- {
- if (objects.length == 0)
- {
- return "";
- }
-
- StringBuilder builder = new StringBuilder();
- for (Object object : objects)
- {
- builder.append(sep);
- if (object == null)
- {
- builder.append("null");
- }
- else
- {
- builder.append(object.getClass().getName());
- }
- }
- return builder.substring(sep.length());
- }
-
- public static String toString(Object... objects)
- {
- return toString(" ", objects);
- }
-
- public static String toString(String sep, Object... objects)
- {
- if (objects.length == 0)
- {
- return "";
- }
-
- StringBuilder builder = new StringBuilder();
- for (Object object : objects)
- {
- builder.append(sep).append(object);
- }
- return builder.substring(sep.length());
- }
-}
\ No newline at end of file