You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/09/27 19:21:13 UTC

svn commit: r1391112 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/text/ main/java/org/apache/commons/lang3/time/ test/java/org/apache/commons/lang3/text/ test/java/org/apache/commons/lang3/time/

Author: sebb
Date: Thu Sep 27 17:21:12 2012
New Revision: 1391112

URL: http://svn.apache.org/viewvc?rev=1391112&view=rev
Log:
StringBuffer => StringBuilder where being used as a local-only buffer

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java?rev=1391112&r1=1391111&r2=1391112&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/ExtendedMessageFormat.java Thu Sep 27 17:21:12 2012
@@ -330,7 +330,7 @@ public class ExtendedMessageFormat exten
     private int readArgumentIndex(String pattern, ParsePosition pos) {
         int start = pos.getIndex();
         seekNonWs(pattern, pos);
-        StringBuffer result = new StringBuffer();
+        StringBuilder result = new StringBuilder();
         boolean error = false;
         for (; !error && pos.getIndex() < pattern.length(); next(pos)) {
             char c = pattern.charAt(pos.getIndex());

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java?rev=1391112&r1=1391111&r2=1391112&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java Thu Sep 27 17:21:12 2012
@@ -413,14 +413,14 @@ public class DurationFormatUtils {
      */
     static String format(Token[] tokens, int years, int months, int days, int hours, int minutes, int seconds,
             int milliseconds, boolean padWithZeros) {
-        StringBuffer buffer = new StringBuffer();
+        StringBuilder buffer = new StringBuilder();
         boolean lastOutputSeconds = false;
         int sz = tokens.length;
         for (int i = 0; i < sz; i++) {
             Token token = tokens[i];
             Object value = token.getValue();
             int count = token.getCount();
-            if (value instanceof StringBuffer) {
+            if (value instanceof StringBuilder) {
                 buffer.append(value.toString());
             } else {
                 if (value == y) {
@@ -485,7 +485,9 @@ public class DurationFormatUtils {
         ArrayList<Token> list = new ArrayList<Token>(array.length);
 
         boolean inLiteral = false;
-        StringBuffer buffer = null;
+        // Although the buffer is stored in a Token, the Tokens are only
+        // used internally, so cannot be accessed by other threads
+        StringBuilder buffer = null;
         Token previous = null;
         int sz = array.length;
         for(int i=0; i<sz; i++) {
@@ -502,7 +504,7 @@ public class DurationFormatUtils {
                       buffer = null;
                       inLiteral = false;
                   } else {
-                      buffer = new StringBuffer();
+                      buffer = new StringBuilder();
                       list.add(new Token(buffer));
                       inLiteral = true;
                   }
@@ -516,7 +518,7 @@ public class DurationFormatUtils {
                 case 'S'  : value = S; break;
                 default   : 
                   if(buffer == null) {
-                      buffer = new StringBuffer();
+                      buffer = new StringBuilder();
                       list.add(new Token(buffer));
                   }
                   buffer.append(ch);
@@ -625,7 +627,7 @@ public class DurationFormatUtils {
                 if (this.count != tok2.count) {
                     return false;
                 }
-                if (this.value instanceof StringBuffer) {
+                if (this.value instanceof StringBuilder) {
                     return this.value.toString().equals(tok2.value.toString());
                 } else if (this.value instanceof Number) {
                     return this.value.equals(tok2.value);

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java?rev=1391112&r1=1391111&r2=1391112&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java Thu Sep 27 17:21:12 2012
@@ -111,7 +111,7 @@ public class ExtendedMessageFormatTest {
                 nf = NumberFormat.getCurrencyInstance(locale);
                 emf = new ExtendedMessageFormat(pattern, locale, registry);
             }
-            StringBuffer expected = new StringBuffer();
+            StringBuilder expected = new StringBuilder();
             expected.append("Name: ");
             expected.append(args[0].toString().toUpperCase());
             expected.append(" DOB: ");
@@ -338,7 +338,7 @@ public class ExtendedMessageFormatTest {
      * @param locale Locale
      */
     private void checkBuiltInFormat(String pattern, Map<String, ?> registry, Object[] args, Locale locale) {
-        StringBuffer buffer = new StringBuffer();
+        StringBuilder buffer = new StringBuilder();
         buffer.append("Pattern=[");
         buffer.append(pattern);
         buffer.append("], locale=[");

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java?rev=1391112&r1=1391111&r2=1391112&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java Thu Sep 27 17:21:12 2012
@@ -47,7 +47,7 @@ public class DateFormatUtilsTest {
         Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
         c.set(2005,0,1,12,0,0);
         c.setTimeZone(TimeZone.getDefault());
-        StringBuffer buffer = new StringBuffer ();
+        StringBuilder buffer = new StringBuilder ();
         int year = c.get(Calendar.YEAR);
         int month = c.get(Calendar.MONTH) + 1;
         int day = c.get(Calendar.DAY_OF_MONTH);
@@ -71,7 +71,7 @@ public class DateFormatUtilsTest {
         Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
         c.set(2005,0,1,12,0,0);
         c.setTimeZone(TimeZone.getDefault());
-        StringBuffer buffer = new StringBuffer ();
+        StringBuilder buffer = new StringBuilder ();
         int year = c.get(Calendar.YEAR);
         int month = c.get(Calendar.MONTH) + 1;
         int day = c.get(Calendar.DAY_OF_MONTH);

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java?rev=1391112&r1=1391111&r2=1391112&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java Thu Sep 27 17:21:12 2012
@@ -347,30 +347,30 @@ public class DurationFormatUtilsTest {
         // tests the ISO8601-like
         assertArrayEquals(new DurationFormatUtils.Token[]{
             new DurationFormatUtils.Token(DurationFormatUtils.H, 1),
-            new DurationFormatUtils.Token(new StringBuffer(":"), 1),
+            new DurationFormatUtils.Token(new StringBuilder(":"), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.m, 2),
-            new DurationFormatUtils.Token(new StringBuffer(":"), 1),
+            new DurationFormatUtils.Token(new StringBuilder(":"), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.s, 2),
-            new DurationFormatUtils.Token(new StringBuffer("."), 1),
+            new DurationFormatUtils.Token(new StringBuilder("."), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.S, 3)}, DurationFormatUtils.lexx("H:mm:ss.SSS"));
 
         // test the iso extended format
         assertArrayEquals(new DurationFormatUtils.Token[]{
-            new DurationFormatUtils.Token(new StringBuffer("P"), 1),
+            new DurationFormatUtils.Token(new StringBuilder("P"), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.y, 4),
-            new DurationFormatUtils.Token(new StringBuffer("Y"), 1),
+            new DurationFormatUtils.Token(new StringBuilder("Y"), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.M, 1),
-            new DurationFormatUtils.Token(new StringBuffer("M"), 1),
+            new DurationFormatUtils.Token(new StringBuilder("M"), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.d, 1),
-            new DurationFormatUtils.Token(new StringBuffer("DT"), 1),
+            new DurationFormatUtils.Token(new StringBuilder("DT"), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.H, 1),
-            new DurationFormatUtils.Token(new StringBuffer("H"), 1),
+            new DurationFormatUtils.Token(new StringBuilder("H"), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.m, 1),
-            new DurationFormatUtils.Token(new StringBuffer("M"), 1),
+            new DurationFormatUtils.Token(new StringBuilder("M"), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.s, 1),
-            new DurationFormatUtils.Token(new StringBuffer("."), 1),
+            new DurationFormatUtils.Token(new StringBuilder("."), 1),
             new DurationFormatUtils.Token(DurationFormatUtils.S, 1),
-            new DurationFormatUtils.Token(new StringBuffer("S"), 1)}, DurationFormatUtils
+            new DurationFormatUtils.Token(new StringBuilder("S"), 1)}, DurationFormatUtils
                 .lexx(DurationFormatUtils.ISO_EXTENDED_FORMAT_PATTERN));
 
         // test failures in equals