This is an automated email from the ASF dual-hosted git repository.

mbrohl pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 569cebdadd Improved: Added isEmpty Interface to StringWrapper 
(OFBIZ-10197)
569cebdadd is described below

commit 569cebdadd6b17682c33da6defcef3cbd82d6085
Author: Cheng Hu Shan <cheng-hu.s...@ecomify.de>
AuthorDate: Tue Feb 7 09:56:26 2023 +0100

    Improved: Added isEmpty Interface to StringWrapper (OFBIZ-10197)
    
    Added convenience API to check if contained theString is null/empty
    (interface IsEmpty, see UtilValidate.isEmpty) and isEmpty method
---
 .../java/org/apache/ofbiz/base/util/StringUtil.java | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
index 8aa11971d8..9715ba2318 100644
--- a/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
+++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
@@ -35,6 +35,7 @@ import java.util.stream.Collectors;
 
 import org.apache.commons.codec.DecoderException;
 import org.apache.commons.codec.binary.Hex;
+import org.apache.ofbiz.base.lang.IsEmpty;
 
 /**
  * Misc String Utility Functions
@@ -407,20 +408,25 @@ public final class StringUtil {
     }
 
     /**
-     * A super-lightweight object to wrap a String object. Mainly used with 
FTL templates
-     * to avoid the general HTML auto-encoding that is now done through the 
Screen Widget.
+     * A super-lightweight object to wrap a String object. Mainly used with FTL
+     * templates to avoid the general HTML auto-encoding that is now done 
through
+     * the Screen Widget.
      */
-    public static class StringWrapper {
+    public static class StringWrapper implements IsEmpty {
         public static final StringWrapper EMPTY_STRING_WRAPPER = new 
StringWrapper("");
 
         private String theString;
-        protected StringWrapper() { }
+
+        protected StringWrapper() {
+        }
+
         public StringWrapper(String theString) {
             this.theString = theString;
         }
 
         /**
          * Fairly simple method used for the plus (+) base concatenation in 
Groovy.
+         *
          * @param value
          * @return the wrapped string, plus the value
          */
@@ -435,5 +441,12 @@ public final class StringUtil {
         public String toString() {
             return this.theString;
         }
+
+        /**
+         * @return true, if wrapped string is null or empty; false otherwise
+         */
+        public boolean isEmpty() {
+            return (theString == null || theString.isEmpty());
+        }
     }
 }

Reply via email to