corda/classpath/java/lang/StringBuilder.java

45 lines
968 B
Java

package java.lang;
public class StringBuilder {
private Cell chain;
private int length;
public StringBuilder append(String s) {
chain = new Cell(s, chain);
length += s.length();
return this;
}
public StringBuilder append(Object o) {
return append(o == null ? "null" : o.toString());
}
public StringBuilder append(int v) {
return append(String.valueOf(v));
}
public StringBuilder append(long v) {
return append(String.valueOf(v));
}
public String toString() {
char[] array = new char[length];
int index = length;
for (Cell c = chain; c != null; c = c.next) {
index -= c.value.length();
c.value.getChars(0, c.value.length(), array, index);
}
return new String(array, 0, length, false);
}
private static class Cell {
public final String value;
public final Cell next;
public Cell(String value, Cell next) {
this.value = value;
this.next = next;
}
}
}