Applying my patch to LANG-355, making StrBuilder implement Appendable
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@795604 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4351e7a1a1
commit
944f642f0b
|
@ -71,7 +71,7 @@ import org.apache.commons.lang.SystemUtils;
|
|||
* @since 2.2
|
||||
* @version $Id$
|
||||
*/
|
||||
public class StrBuilder implements CharSequence {
|
||||
public class StrBuilder implements CharSequence, Appendable {
|
||||
|
||||
/**
|
||||
* The extra capacity for new builders.
|
||||
|
@ -462,6 +462,36 @@ public class StrBuilder implements CharSequence {
|
|||
return append(obj.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()}.
|
||||
|
|
|
@ -138,6 +138,9 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
|
||||
sb.append(new StrBuilder("yes"));
|
||||
assertEquals("foobazyes", sb.toString());
|
||||
|
||||
sb.append((CharSequence) "Seq");
|
||||
assertEquals("foobazyesSeq", sb.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -214,6 +217,9 @@ public class StrBuilderAppendInsertTest extends TestCase {
|
|||
|
||||
sb.append("abcbardef", 3, 3);
|
||||
assertEquals("foobar", sb.toString());
|
||||
|
||||
sb.append( (CharSequence)"abcbardef", 4, 3);
|
||||
assertEquals("foobarard", sb.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue