commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r795604 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/text/StrBuilder.java test/org/apache/commons/lang/text/StrBuilderAppendInsertTest.java
Date Sun, 19 Jul 2009 19:41:50 GMT
Author: bayard
Date: Sun Jul 19 19:41:50 2009
New Revision: 795604

URL: http://svn.apache.org/viewvc?rev=795604&view=rev
Log:
Applying my patch to LANG-355, making StrBuilder implement Appendable

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

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java?rev=795604&r1=795603&r2=795604&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java Sun Jul
19 19:41:50 2009
@@ -71,7 +71,7 @@
  * @since 2.2
  * @version $Id$
  */
-public class StrBuilder implements CharSequence {
+public class StrBuilder implements CharSequence, Appendable {
 
     /**
      * The extra capacity for new builders.
@@ -463,6 +463,36 @@
     }
 
     /**
+     * Appends a CharSequence to this string builder.
+     * Appending null will call {@link #appendNull()}.
+     *
+     * @param seq  the CharSequence to append
+     * @return this, to enable chaining
+     */
+    public StrBuilder append(CharSequence seq) {
+        if (seq == null) {
+            return appendNull();
+        } 
+        return append(seq.toString());        
+    }
+
+    /**
+     * Appends part of a CharSequence to this string builder.
+     * Appending null will call {@link #appendNull()}.
+     *
+     * @param seq  the CharSequence to append
+     * @param startIndex  the start index, inclusive, must be valid
+     * @param length  the length to append, must be valid
+     * @return this, to enable chaining
+     */
+    public StrBuilder append(CharSequence seq, int startIndex, int length) {
+        if (seq == null) {
+            return appendNull();
+        } 
+        return append(seq.toString(), startIndex, length);
+    }
+
+    /**
      * Appends a string to this string builder.
      * Appending null will call {@link #appendNull()}.
      *

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderAppendInsertTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderAppendInsertTest.java?rev=795604&r1=795603&r2=795604&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderAppendInsertTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderAppendInsertTest.java
Sun Jul 19 19:41:50 2009
@@ -138,6 +138,9 @@
 
         sb.append(new StrBuilder("yes"));
         assertEquals("foobazyes", sb.toString());
+
+        sb.append((CharSequence) "Seq");
+        assertEquals("foobazyesSeq", sb.toString());
     }
 
     //-----------------------------------------------------------------------
@@ -214,6 +217,9 @@
 
         sb.append("abcbardef", 3, 3);
         assertEquals("foobar", sb.toString());
+
+        sb.append( (CharSequence)"abcbardef", 4, 3);
+        assertEquals("foobarard", sb.toString());
     }
 
     //-----------------------------------------------------------------------



Mime
View raw message