commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject [1/3] [lang] LANG-1270: Add StringUtils#isAnyNotEmpty and #isAnyNotBlank (closes #193)
Date Wed, 19 Oct 2016 16:55:14 GMT
Repository: commons-lang
Updated Branches:
  refs/heads/master 8592cfe49 -> 3b12d4fe5


LANG-1270: Add StringUtils#isAnyNotEmpty and #isAnyNotBlank (closes #193)


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/5acf310d
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/5acf310d
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/5acf310d

Branch: refs/heads/master
Commit: 5acf310d08b2bc5182cf936616ef70938cb2c499
Parents: 8592cfe
Author: Pierre Templier <pierre.templier@gmail.com>
Authored: Sat Sep 24 00:49:32 2016 +0200
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Wed Oct 19 18:53:35 2016 +0200

----------------------------------------------------------------------
 .../org/apache/commons/lang3/StringUtils.java   | 74 ++++++++++++++++++--
 .../lang3/StringUtilsEmptyBlankTest.java        | 26 +++++++
 2 files changed, 93 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/5acf310d/src/main/java/org/apache/commons/lang3/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 8791394..cec4fa6 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -256,7 +256,36 @@ public class StringUtils {
       }
       return false;
     }
-    
+
+    /**
+     * <p>Checks if any one of the CharSequences are not empty ("") or null.</p>
+     *
+     * <pre>
+     * StringUtils.isAnyNotEmpty(null)             = false
+     * StringUtils.isAnyNotEmpty(null, "foo")      = true
+     * StringUtils.isAnyNotEmpty("", "bar")        = true
+     * StringUtils.isAnyNotEmpty("bob", "")        = true
+     * StringUtils.isAnyNotEmpty("  bob  ", null)  = true
+     * StringUtils.isAnyNotEmpty(" ", "bar")       = true
+     * StringUtils.isAnyNotEmpty("foo", "bar")     = true
+     * </pre>
+     *
+     * @param css  the CharSequences to check, may be null or empty
+     * @return {@code true} if any of the CharSequences are empty or null
+     * @since 3.6
+     */
+    public static boolean isAnyNotEmpty(final CharSequence... css) {
+      if (ArrayUtils.isEmpty(css)) {
+        return true;
+      }
+      for (final CharSequence cs : css) {
+        if (isNotEmpty(cs)) {
+          return true;
+        }
+      }
+      return false;
+    }
+
     /**
      * <p>Checks if none of the CharSequences are empty ("") or null.</p>
      *
@@ -276,7 +305,8 @@ public class StringUtils {
      */
     public static boolean isNoneEmpty(final CharSequence... css) {
       return !isAnyEmpty(css);
-    }    
+    }
+
     /**
      * <p>Checks if a CharSequence is whitespace, empty ("") or null.</p>
      *
@@ -326,9 +356,9 @@ public class StringUtils {
     public static boolean isNotBlank(final CharSequence cs) {
         return !isBlank(cs);
     }
-    
-        /**
-     * <p>Checks if any one of the CharSequences are blank ("") or null and not whitespace
only..</p>
+
+    /**
+     * <p>Checks if any one of the CharSequences are blank ("") or null and not whitespace
only.</p>
      *
      * <pre>
      * StringUtils.isAnyBlank(null)             = true
@@ -356,9 +386,39 @@ public class StringUtils {
       }
       return false;
     }
-    
+
+    /**
+     * <p>Checks if any one of the CharSequences are not blank ("") or null and not
whitespace only.</p>
+     *
+     * <pre>
+     * StringUtils.isAnyNotBlank(null)             = false
+     * StringUtils.isAnyNotBlank(null, "foo")      = true
+     * StringUtils.isAnyNotBlank(null, null)       = false
+     * StringUtils.isAnyNotBlank("", "bar")        = true
+     * StringUtils.isAnyNotBlank("bob", "")        = true
+     * StringUtils.isAnyNotBlank("  bob  ", null)  = true
+     * StringUtils.isAnyNotBlank(" ", "bar")       = true
+     * StringUtils.isAnyNotBlank("foo", "bar")     = false
+     * </pre>
+     *
+     * @param css  the CharSequences to check, may be null or empty
+     * @return {@code true} if any of the CharSequences are not blank or null or whitespace
only
+     * @since 3.6
+     */
+    public static boolean isAnyNotBlank(final CharSequence... css) {
+      if (ArrayUtils.isEmpty(css)) {
+        return true;
+      }
+      for (final CharSequence cs : css) {
+        if (isNotBlank(cs)) {
+          return true;
+        }
+      }
+      return false;
+    }
+
     /**
-     * <p>Checks if none of the CharSequences are blank ("") or null and whitespace
only..</p>
+     * <p>Checks if none of the CharSequences are blank ("") or null and whitespace
only.</p>
      *
      * <pre>
      * StringUtils.isNoneBlank(null)             = false

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/5acf310d/src/test/java/org/apache/commons/lang3/StringUtilsEmptyBlankTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEmptyBlankTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEmptyBlankTest.java
index b3d33fc..78e16a9 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsEmptyBlankTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsEmptyBlankTest.java
@@ -57,6 +57,19 @@ public class StringUtilsEmptyBlankTest  {
     }
 
     @Test
+    public void testIsAnyNotEmpty() {
+        assertFalse(StringUtils.isAnyNotEmpty((String) null));
+        assertTrue(StringUtils.isAnyNotEmpty((String[]) null));
+        assertTrue(StringUtils.isAnyNotEmpty(null, "foo"));
+        assertTrue(StringUtils.isAnyNotEmpty("", "bar"));
+        assertTrue(StringUtils.isAnyNotEmpty("bob", ""));
+        assertTrue(StringUtils.isAnyNotEmpty("  bob  ", null));
+        assertTrue(StringUtils.isAnyNotEmpty(" ", "bar"));
+        assertTrue(StringUtils.isAnyNotEmpty("foo", "bar"));
+        assertFalse(StringUtils.isAnyNotEmpty("", null));
+    }
+
+    @Test
     public void testIsNoneEmpty() {
         assertFalse(StringUtils.isNoneEmpty((String) null));
         assertFalse(StringUtils.isNoneEmpty((String[]) null));
@@ -100,6 +113,19 @@ public class StringUtilsEmptyBlankTest  {
     }
 
     @Test
+    public void testIsAnyNotBlank() {
+        assertFalse(StringUtils.isAnyNotBlank((String) null));
+        assertTrue(StringUtils.isAnyNotBlank((String[]) null));
+        assertTrue(StringUtils.isAnyNotBlank(null, "foo"));
+        assertFalse(StringUtils.isAnyNotBlank(null, null));
+        assertTrue(StringUtils.isAnyNotBlank("", "bar"));
+        assertTrue(StringUtils.isAnyNotBlank("bob", ""));
+        assertTrue(StringUtils.isAnyNotBlank("  bob  ", null));
+        assertTrue(StringUtils.isAnyNotBlank(" ", "bar"));
+        assertTrue(StringUtils.isAnyNotBlank("foo", "bar"));
+    }
+
+    @Test
     public void testIsNoneBlank() {
         assertFalse(StringUtils.isNoneBlank((String) null));
         assertFalse(StringUtils.isNoneBlank((String[]) null));


Mime
View raw message