svn commit: r1865844 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1865844 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java

mthl
Author: mthl
Date: Sat Aug 24 12:56:36 2019
New Revision: 1865844

URL: http://svn.apache.org/viewvc?rev=1865844&view=rev
Log:
Improved: Remove unused code in ‘UtilValidate’
(OFBIZ-11172)

The code was not used in Java/Groovy/FreeMarker/XML in the framework
or official plugins.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java?rev=1865844&r1=1865843&r2=1865844&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java Sat Aug 24 12:56:36 2019
@@ -20,7 +20,6 @@ package org.apache.ofbiz.base.util;
 
 import java.sql.Timestamp;
 import java.util.Collection;
-import java.util.Locale;
 import java.util.Map;
 
 import org.apache.commons.validator.routines.EmailValidator;
@@ -81,9 +80,6 @@ public final class UtilValidate {
     /** digit characters */
     public static final String digits = "0123456789";
 
-    /** hex digit characters */
-    private static final String hexDigits = digits + "abcdefABCDEF";
-
     /** lower-case letter characters */
     public static final String lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
 
@@ -242,69 +238,6 @@ public final class UtilValidate {
         return stringBuilder.toString();
     }
 
-    /** Removes all characters which do NOT appear in string bag from string s. */
-    public static String stripCharsNotInBag(String s, String bag) {
-        int i;
-        StringBuilder stringBuilder = new StringBuilder("");
-
-        // Search through string's characters one by one.
-        // If character is in bag, append to returnString.
-        for (i = 0; i < s.length(); i++) {
-            char c = s.charAt(i);
-
-            if (bag.indexOf(c) != -1) {
-                stringBuilder.append(c);
-            }
-        }
-        return stringBuilder.toString();
-    }
-
-    /** Removes all whitespace characters from s.
-     *  Member whitespace(see above) defines which characters are considered whitespace. */
-    public static String stripWhitespace(String s) {
-        return stripCharsInBag(s, whitespace);
-    }
-
-    /** Returns true if single character c(actually a string) is contained within string s. */
-    public static boolean charInString(char c, String s) {
-        return (s.indexOf(c) != -1);
-    }
-
-    /** Removes initial(leading) whitespace characters from s.
-     *  Member whitespace(see above) defines which characters are considered whitespace. */
-    public static String stripInitialWhitespace(String s) {
-        int i = 0;
-
-        while ((i < s.length()) && charInString(s.charAt(i), whitespace)) {
-            i++;
-        }
-        return s.substring(i);
-    }
-
-    /** Returns true if character c is an English letter (A .. Z, a..z).
-     *
-     *  NOTE: Need i18n version to support European characters.
-     *  This could be tricky due to different character
-     *  sets and orderings for various languages and platforms. */
-    public static boolean isLetter(char c) {
-        return Character.isLetter(c);
-    }
-
-    /** Returns true if character c is a digit (0 .. 9). */
-    public static boolean isDigit(char c) {
-        return Character.isDigit(c);
-    }
-
-    /** Returns true if character c is a letter or digit. */
-    public static boolean isLetterOrDigit(char c) {
-        return Character.isLetterOrDigit(c);
-    }
-
-    /** Returns true if character c is a letter or digit. */
-    public static boolean isHexDigit(char c) {
-        return hexDigits.indexOf(c) >= 0;
-    }
-
     /** Returns true if all characters in string s are numbers.
      *
      *  Accepts non-signed integers only. Does not accept floating
@@ -322,7 +255,7 @@ public final class UtilValidate {
             // Check that current character is number.
             char c = s.charAt(i);
 
-            if (!isDigit(c)) {
+            if (!Character.isDigit(c)) {
                 return false;
             }
         }
@@ -336,7 +269,7 @@ public final class UtilValidate {
      *
      *  Does not accept floating point, exponential notation, etc.
      */
-    public static boolean isSignedInteger(String s) {
+    private static boolean isSignedInteger(String s) {
         if (isEmpty(s)) {
             return defaultEmptyOK;
         }
@@ -463,7 +396,7 @@ public final class UtilValidate {
                     return false;
                 }
             } else {
-                if (!isDigit(c)) {
+                if (!Character.isDigit(c)) {
                     return false;
                 }
             }
@@ -575,7 +508,7 @@ public final class UtilValidate {
             // Check that current character is letter.
             char c = s.charAt(i);
 
-            if (!isLetter(c)) {
+            if (!Character.isLetter(c)) {
                 return false;
             }
         }
@@ -602,7 +535,7 @@ public final class UtilValidate {
             // Check that current character is number or letter.
             char c = s.charAt(i);
 
-            if (!isLetterOrDigit(c)) {
+            if (!Character.isLetterOrDigit(c)) {
                 return false;
             }
         }
@@ -1184,7 +1117,7 @@ public final class UtilValidate {
      *   @param     cc - a string representing a credit card number; Sample number: 6331100000000096 (16 digits)
      *   @return  true, if the credit card number is a valid Solo card number, false otherwise
      */
-    public static boolean isSolo(String cc) {
+    private static boolean isSolo(String cc) {
         String first4digs = cc.substring(0, 4);
         String first2digs = cc.substring(0, 2);
         if (((cc.length() == 16) || (cc.length() == 18) || (cc.length() == 19)) &&
@@ -1198,7 +1131,7 @@ public final class UtilValidate {
      *   @param    cc - a string representing a credit card number; Sample number: 4175000000000001(16 digits)
      *   @return  true, if the credit card number is a valid Visa Electron card number, false otherwise
      */
-    public static boolean isVisaElectron(String cc) {
+    private static boolean isVisaElectron(String cc) {
         String first6digs = cc.substring(0, 6);
         String first4digs = cc.substring(0, 4);
 
@@ -1323,123 +1256,6 @@ public final class UtilValidate {
         return false;
     }
 
-
-    /** isNotPoBox returns true if address argument does not contain anything that looks like a a PO Box. */
-    public static boolean isNotPoBox(String s) {
-        if (isEmpty(s)) {
-            return defaultEmptyOK;
-        }
-
-        // strings to check from Greg's program
-        // "P.O. B"
-        // "P.o.B"
-        // "P.O B"
-        // "PO. B"
-        // "P O B"
-        // "PO B"
-        // "P.0. B"
-        // "P0 B"
-
-        String sl = s.toLowerCase(Locale.getDefault());
-        if (sl.indexOf("p.o. b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p.o.b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p.o b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p o b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("po b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("pobox") != -1) {
-            return false;
-        }
-        if (sl.indexOf("po#") != -1) {
-            return false;
-        }
-        if (sl.indexOf("po #") != -1) {
-            return false;
-        }
-
-        // now with 0's for them sneaky folks
-        if (sl.indexOf("p.0. b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p.0.b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p.0 b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p 0 b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p0 b") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p0box") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p0#") != -1) {
-            return false;
-        }
-        if (sl.indexOf("p0 #") != -1) {
-            return false;
-        }
-        return true;
-    }
-
-    public static boolean isValidUpc(String upc) {
-        if (upc == null || upc.length() != 12) {
-            throw new IllegalArgumentException("Invalid UPC length; must be 12 characters");
-        }
-
-        char csum = upc.charAt(11);
-        char calcSum = calcUpcChecksum(upc);
-        return csum == calcSum;
-    }
-
-    public static char calcUpcChecksum(String upc) {
-        return calcChecksum(upc, 12);
-    }
-
-    public static boolean isValidEan(String ean) {
-        if (ean == null || ean.length() != 13) {
-            throw new IllegalArgumentException("Invalid EAN length; must be 13 characters");
-        }
-        char csum = ean.charAt(12);
-        char calcSum = calcChecksum(ean, 12);
-        return csum == calcSum;
-    }
-
-    public static char calcChecksum(String value, int length) {
-        if (value != null && value.length() == length + 1) {
-            value = value.substring(0, length);
-        }
-        if (value == null || value.length() != length) {
-            throw new IllegalArgumentException("Illegal size of value; must be either" + length + " or " + (length + 1) + " characters");
-        }
-        int oddsum = 0;
-        int evensum = 0;
-        for (int i = value.length() - 1; i >= 0; i--) {
-            if ((value.length() - i) % 2 == 0) {
-                evensum += Character.digit(value.charAt(i), 10);
-            } else {
-                oddsum += Character.digit(value.charAt(i), 10);
-            }
-        }
-        int check = 10 - ((evensum + 3 * oddsum) % 10);
-        if (check >= 10) {
-            check = 0;
-        }
-        return Character.forDigit(check, 10);
-    }
-
     public static String checkValidDatabaseId(String fieldStr) {
         if (fieldStr.indexOf(' ') >= 0) {
             return "[space found at position " + (fieldStr.indexOf(' ') + 1) + "]";
@@ -1481,22 +1297,12 @@ public final class UtilValidate {
         return isValid;
     }
 
-    public static boolean isValidDatabaseId(String fieldStr, StringBuilder errorDetails) {
-        boolean isValid = true;
-        String checkMessage = checkValidDatabaseId(fieldStr);
-        if (checkMessage != null) {
-            isValid = false;
-            errorDetails.append(checkMessage);
-        }
-        return isValid;
-    }
-
     public static boolean isValidPhoneNumber(String phoneNumber, Delegator delegator) {
         String geoId = EntityUtilProperties.getPropertyValue("general", "country.geo.id.default", delegator);
         return isValidPhoneNumber(phoneNumber, geoId, delegator);
     }
 
-    public static boolean isValidPhoneNumber(String phoneNumber, String geoId, Delegator delegator) {
+    private static boolean isValidPhoneNumber(String phoneNumber, String geoId, Delegator delegator) {
         boolean isValid = false;
         try {
             GenericValue geo = EntityQuery.use(delegator).from("Geo").where("geoId", geoId).cache().queryOne();