MCPcopy Create free account
hub / github.com/ReadyTalk/avian / StringBuilder

Class StringBuilder

classpath/java/lang/StringBuilder.java:13–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11package java.lang;
12
13public class StringBuilder implements CharSequence, Appendable {
14 private static final int BufferSize = 32;
15
16 private Cell chain;
17 private int length;
18 private char[] buffer;
19 private int position;
20
21 public StringBuilder(String s) {
22 append(s);
23 }
24
25 public StringBuilder(int capacity) { }
26
27 public StringBuilder() {
28 this(0);
29 }
30
31 private void flush() {
32 if (position > 0) {
33 chain = new Cell(new String(buffer, 0, position, false), chain);
34 buffer = null;
35 position = 0;
36 }
37 }
38
39 public StringBuilder append(String s) {
40 if (s == null) {
41 return append("null");
42 } else {
43 if (s.length() > 0) {
44 if (buffer != null && s.length() <= buffer.length - position) {
45 s.getChars(0, s.length(), buffer, position);
46 position += s.length();
47 } else {
48 flush();
49 chain = new Cell(s, chain);
50 }
51 length += s.length();
52 }
53 return this;
54 }
55 }
56
57 public StringBuilder append(StringBuffer sb) {
58 return append(sb.toString());
59 }
60
61 public StringBuilder append(CharSequence sequence) {
62 return append(sequence.toString());
63 }
64
65 public Appendable append(CharSequence sequence, int start, int end) {
66 return append(sequence.subSequence(start, end));
67 }
68
69 public StringBuilder append(char[] b, int offset, int length) {
70 return append(new String(b, offset, length));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected