commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1299411 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/ main/java/org/apache/commons/lang3/exception/ main/java/org/apache/commons/lang3/text/ test/java/org/apache/commons/lang3/
Date Sun, 11 Mar 2012 17:55:30 GMT
Author: ggregory
Date: Sun Mar 11 17:55:29 2012
New Revision: 1299411

URL: http://svn.apache.org/viewvc?rev=1299411&view=rev
Log:
Eat own dog food: StringUtils#isEmpty(String) and replace some but not all String#length()
== 0 with String#isEmpty()

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSetUtils.java
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrMatcher.java
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSetUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSetUtils.java?rev=1299411&r1=1299410&r2=1299411&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSetUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSetUtils.java Sun
Mar 11 17:55:29 2012
@@ -143,7 +143,7 @@ public class CharSetUtils {
             return null;
         }
         if (str.length() == 0 || deepEmpty(set)) {
-            return "";
+            return StringUtils.EMPTY;
         }
         return modify(str, set, true);
     }

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java?rev=1299411&r1=1299410&r2=1299411&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java Sun Mar
11 17:55:29 2012
@@ -183,11 +183,8 @@ public class ClassUtils {
      * @param className  the className to get the short name for
      * @return the class name of the class without the package name or an empty string
      */
-    public static String getShortClassName(String className) {
-        if (className == null) {
-            return StringUtils.EMPTY;
-        }
-        if (className.length() == 0) {
+    public static String getShortClassName(String className) {   
+        if (StringUtils.isEmpty(className)) {
             return StringUtils.EMPTY;
         }
 
@@ -289,7 +286,7 @@ public class ClassUtils {
      * @return the package name or an empty string
      */
     public static String getPackageName(String className) {
-        if (className == null || className.length() == 0) {
+        if (StringUtils.isEmpty(className)) {
             return StringUtils.EMPTY;
         }
 

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java?rev=1299411&r1=1299410&r2=1299411&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/LocaleUtils.java Sun
Mar 11 17:55:29 2012
@@ -235,7 +235,7 @@ public class LocaleUtils {
             for (int i = 0; i < locales.size(); i++) {
                 Locale locale = locales.get(i);
                 if (countryCode.equals(locale.getCountry()) &&
-                        locale.getVariant().length() == 0) {
+                        locale.getVariant().isEmpty()) {
                     langs.add(locale);
                 }
             }
@@ -268,7 +268,7 @@ public class LocaleUtils {
                 Locale locale = locales.get(i);
                 if (languageCode.equals(locale.getLanguage()) &&
                         locale.getCountry().length() != 0 &&
-                        locale.getVariant().length() == 0) {
+                        locale.getVariant().isEmpty()) {
                     countries.add(locale);
                 }
             }

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java?rev=1299411&r1=1299410&r2=1299411&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
Sun Mar 11 17:55:29 2012
@@ -647,7 +647,7 @@ public class ExceptionUtils {
             String token = frames.nextToken();
             // Determine if the line starts with <whitespace>at
             int at = token.indexOf("at");
-            if (at != -1 && token.substring(0, at).trim().length() == 0) {
+            if (at != -1 && token.substring(0, at).trim().isEmpty()) {
                 traceStarted = true;
                 list.add(token);
             } else if (traceStarted) {

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrMatcher.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrMatcher.java?rev=1299411&r1=1299410&r2=1299411&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrMatcher.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrMatcher.java
Sun Mar 11 17:55:29 2012
@@ -187,7 +187,7 @@ public abstract class StrMatcher {
      * @return a new Matcher for the given characters
      */
     public static StrMatcher charSetMatcher(String chars) {
-        if (chars == null || chars.length() == 0) {
+        if (StringUtils.isEmpty(chars)) {
             return NONE_MATCHER;
         }
         if (chars.length() == 1) {

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java?rev=1299411&r1=1299410&r2=1299411&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java
Sun Mar 11 17:55:29 2012
@@ -23,6 +23,7 @@ import java.util.ListIterator;
 import java.util.NoSuchElementException;
 
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
 
 /**
  * Tokenizes a string based based on delimiters (separators)
@@ -650,7 +651,7 @@ public class StrTokenizer implements Lis
      * @param tok  the token to add
      */
     private void addToken(List<String> list, String tok) {
-        if (tok == null || tok.length() == 0) {
+        if (StringUtils.isEmpty(tok)) {
             if (isIgnoreEmptyTokens()) {
                 return;
             }

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java?rev=1299411&r1=1299410&r2=1299411&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java
Sun Mar 11 17:55:29 2012
@@ -86,8 +86,8 @@ public class LocaleUtilsTest extends Tes
         assertNotNull("valid locale", locale);
         assertEquals(language, locale.getLanguage());
         //country and variant are empty
-        assertTrue(locale.getCountry() == null || locale.getCountry().length() == 0);
-        assertTrue(locale.getVariant() == null || locale.getVariant().length() == 0);
+        assertTrue(locale.getCountry() == null || locale.getCountry().isEmpty());
+        assertTrue(locale.getVariant() == null || locale.getVariant().isEmpty());
     }
 
     /**
@@ -103,7 +103,7 @@ public class LocaleUtilsTest extends Tes
         assertEquals(language, locale.getLanguage());
         assertEquals(country, locale.getCountry());
         //variant is empty
-        assertTrue(locale.getVariant() == null || locale.getVariant().length() == 0);
+        assertTrue(locale.getVariant() == null || locale.getVariant().isEmpty());
     }
 
     /**
@@ -393,7 +393,7 @@ public class LocaleUtilsTest extends Tes
                 Locale locale = iterator.next();
                 // should have an en empty variant
                 assertTrue(locale.getVariant() == null
-                        || locale.getVariant().length() == 0);
+                        || locale.getVariant().isEmpty());
                 assertEquals(country, locale.getCountry());
                 if (language.equals(locale.getLanguage())) {
                     found = true;
@@ -443,7 +443,7 @@ public class LocaleUtilsTest extends Tes
                 Locale locale = iterator.next();
                 // should have an en empty variant
                 assertTrue(locale.getVariant() == null
-                        || locale.getVariant().length() == 0);
+                        || locale.getVariant().isEmpty());
                 assertEquals(language, locale.getLanguage());
                 if (countrie.equals(locale.getCountry())) {
                     found = true;



Mime
View raw message