commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r226922 - in /jakarta/commons/proper/lang/trunk/src: java/org/apache/commons/lang/text/StrBuilder.java test/org/apache/commons/lang/text/StrBuilderTest.java
Date Tue, 02 Aug 2005 01:03:47 GMT
Author: ggregory
Date: Mon Aug  1 18:03:45 2005
New Revision: 226922

URL: http://svn.apache.org/viewcvs?rev=226922&view=rev
Log:
[Bug 35966] - [lang] StrBuilderTest#testReplaceStringString fails. From Nathan Beyer nbeyer@kc.rr.com.

Modified:
    jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java

Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java?rev=226922&r1=226921&r2=226922&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
(original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
Mon Aug  1 18:03:45 2005
@@ -1031,7 +1031,7 @@
     public StrBuilder replace(int startIndex, int endIndex, String str) {
         endIndex = validateRange(startIndex, endIndex);
         int insertLen = str.length();
-        int removeLen = endIndex = startIndex;
+        int removeLen = endIndex - startIndex;
         int newSize = size - removeLen + insertLen;
         if (insertLen > removeLen) {
             ensureCapacity(newSize);
@@ -1462,12 +1462,15 @@
      * @return this, to enable chaining
      */
     public StrBuilder reverse() {
+        if (size == 0) {
+            return this;
+        }
+        
         int half = size / 2;
-        char swap;
-        for (int i = 0; i < half; i++) {
-            swap = buf[i];
-            buf[i] = buf[size - i];
-            buf[size - i] = swap;
+        for (int leftIdx = 0, rightIdx = size - 1; leftIdx < half; leftIdx++,rightIdx--)
{
+            char swap = buf[leftIdx];
+            buf[leftIdx] = buf[rightIdx];
+            buf[rightIdx] = swap;
         }
         return this;
     }

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java?rev=226922&r1=226921&r2=226922&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
(original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
Mon Aug  1 18:03:45 2005
@@ -1324,11 +1324,25 @@
         assertEquals("", sb.toString());
     }
     
-    public void toStringBuffer() {
+    public void testStringBuffer() {
         StrBuilder sb = new StrBuilder();
         assertEquals (new StringBuffer().toString(), sb.toStringBuffer().toString());
         
         sb.append("junit");
         assertEquals(new StringBuffer("junit").toString(), sb.toStringBuffer().toString());
+    }
+    
+    public void testReverse() {
+        StrBuilder sb = new StrBuilder();
+        
+        String actual = sb.reverse().toString();
+        assertEquals ("", actual);
+        
+        sb.append(true);
+        actual = sb.reverse().toString();
+        assertEquals("eurt", actual);
+        
+        actual = sb.reverse().toString();
+        assertEquals("true", actual);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message