commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1057349 - in /commons/proper/lang/branches/LANG_2_X: RELEASE-NOTES.txt src/main/java/org/apache/commons/lang/text/StrBuilder.java src/site/changes/changes.xml src/test/java/org/apache/commons/lang/text/StrBuilderTest.java
Date Mon, 10 Jan 2011 20:40:50 GMT
Author: niallp
Date: Mon Jan 10 20:40:49 2011
New Revision: 1057349

URL: http://svn.apache.org/viewvc?rev=1057349&view=rev
Log:
LANG-302 Fix StrBuilder does not implement clone()

Modified:
    commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt
    commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/text/StrBuilder.java
    commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml
    commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/text/StrBuilderTest.java

Modified: commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt?rev=1057349&r1=1057348&r2=1057349&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt (original)
+++ commons/proper/lang/branches/LANG_2_X/RELEASE-NOTES.txt Mon Jan 10 20:40:49 2011
@@ -27,6 +27,7 @@ IMPROVEMENTS IN 2.6
     * [LANG-632] - DateUtils: provide a Date to Calendar convenience method
     * [LANG-576] - ObjectUtils: add clone methods to ObjectUtils
     * [LANG-667] - ObjectUtils: add a Null-safe compare() method
+    * [LANG-302] - StrBuilder: implement clone() method
     * [LANG-640] - StringUtils: add a normalizeSpace() method
     * [LANG-614] - StringUtils: add endsWithAny() method
     * [LANG-655] - StringUtils: add defaultIfBlank() method

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/text/StrBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/text/StrBuilder.java?rev=1057349&r1=1057348&r2=1057349&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/text/StrBuilder.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/text/StrBuilder.java
Mon Jan 10 20:40:49 2011
@@ -2577,6 +2577,20 @@ public class StrBuilder implements Clone
         return new StringBuffer(size).append(buffer, 0, size);
     }
 
+    /**
+     * Clone this object.
+     *
+     * @return a clone of this object
+     * @throws CloneNotSupportedException if clone is not supported
+     * @since 2.6
+     */
+    public Object clone() throws CloneNotSupportedException {
+        StrBuilder clone = (StrBuilder)super.clone();
+        clone.buffer = new char[buffer.length];
+        System.arraycopy(buffer, 0, clone.buffer, 0, buffer.length);
+        return clone;
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Validates parameters defining a range of the builder.

Modified: commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml?rev=1057349&r1=1057348&r2=1057349&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml (original)
+++ commons/proper/lang/branches/LANG_2_X/src/site/changes/changes.xml Mon Jan 10 20:40:49
2011
@@ -28,6 +28,7 @@
     <action type="add" issue="LANG-632">DateUtils: provide a Date to Calendar convenience
method</action>
     <action type="add" issue="LANG-576">ObjectUtils: add clone methods to ObjectUtils</action>
     <action type="add" issue="LANG-667">ObjectUtils: add a Null-safe compare() method</action>
+    <action type="add" issue="LANG-302">StrBuilder: implement clone() method</action>
     <action type="add" issue="LANG-640">StringUtils: add a normalizeSpace() method</action>
     <action type="add" issue="LANG-614">StringUtils: add endsWithAny() method</action>
     <action type="add" issue="LANG-655">StringUtils: add defaultIfBlank() method</action>

Modified: commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/text/StrBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/text/StrBuilderTest.java?rev=1057349&r1=1057348&r2=1057349&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/text/StrBuilderTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/text/StrBuilderTest.java
Mon Jan 10 20:40:49 2011
@@ -245,6 +245,33 @@ public class StrBuilderTest extends Test
     }
 
     //-----------------------------------------------------------------------
+    public void testClone() throws Exception {
+        StrBuilder sb = new StrBuilder();
+        sb.setNewLineText("NEWLINE");
+        sb.setNullText("NULLVALUE");
+        sb.append("abc");
+        assertEquals("before", "abc", sb.toString());
+
+        // Clone
+        StrBuilder clone = (StrBuilder)sb.clone();
+        assertEquals("capacity", sb.capacity(), clone.capacity());
+        assertEquals("size", sb.size(), clone.size());
+        assertEquals("toString", sb.toString(), clone.toString());
+
+        // Modify Original
+        sb.append("def");
+        assertEquals("original-1", "abcdef", sb.toString());
+        assertEquals("different",  "abc", clone.toString());
+
+        // Modify Clone
+        clone.append((String)null);
+        assertEquals("append null", "abcNULLVALUE", clone.toString());
+        clone.appendNewLine();
+        assertEquals("append newline", "abcNULLVALUENEWLINE", clone.toString());
+        assertEquals("original-2",  "abcdef", sb.toString());
+    }
+
+    //-----------------------------------------------------------------------
     public void testCapacity() {
         StrBuilder sb = new StrBuilder();
         assertEquals(sb.buffer.length, sb.capacity());



Mime
View raw message