1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| package com.jeantessier.text; |
34 |
| |
35 |
| public class PrinterBuffer { |
36 |
| public static final String DEFAULT_INDENT_TEXT = " "; |
37 |
| |
38 |
| private final static String EOL = System.getProperty("line.separator", "\n"); |
39 |
| |
40 |
| private StringBuffer buffer = new StringBuffer(); |
41 |
| private String indentText = DEFAULT_INDENT_TEXT; |
42 |
| private int indentLevel = 0; |
43 |
| |
44 |
2494
| public String getIndentText() {
|
45 |
2494
| return indentText;
|
46 |
| } |
47 |
| |
48 |
8
| public void setIndentText(String indentText) {
|
49 |
8
| this.indentText = indentText;
|
50 |
| } |
51 |
| |
52 |
1
| public PrinterBuffer append(boolean b) {
|
53 |
1
| buffer.append(b);
|
54 |
1
| return this;
|
55 |
| } |
56 |
| |
57 |
1
| public PrinterBuffer append(char c) {
|
58 |
1
| buffer.append(c);
|
59 |
1
| return this;
|
60 |
| } |
61 |
| |
62 |
1
| public PrinterBuffer append(char[] str, int offset, int len) {
|
63 |
1
| buffer.append(str, offset, len);
|
64 |
1
| return this;
|
65 |
| } |
66 |
| |
67 |
1
| public PrinterBuffer append(char[] s) {
|
68 |
1
| buffer.append(s);
|
69 |
1
| return this;
|
70 |
| } |
71 |
| |
72 |
1
| public PrinterBuffer append(double d) {
|
73 |
1
| buffer.append(d);
|
74 |
1
| return this;
|
75 |
| } |
76 |
| |
77 |
2
| public PrinterBuffer append(float f) {
|
78 |
2
| buffer.append(f);
|
79 |
2
| return this;
|
80 |
| } |
81 |
| |
82 |
19
| public PrinterBuffer append(int i) {
|
83 |
19
| buffer.append(i);
|
84 |
19
| return this;
|
85 |
| } |
86 |
| |
87 |
1
| public PrinterBuffer append(long l) {
|
88 |
1
| buffer.append(l);
|
89 |
1
| return this;
|
90 |
| } |
91 |
| |
92 |
347
| public PrinterBuffer append(Object obj) {
|
93 |
347
| buffer.append(obj);
|
94 |
347
| return this;
|
95 |
| } |
96 |
| |
97 |
4125
| public PrinterBuffer append(String s) {
|
98 |
4125
| buffer.append(s);
|
99 |
4125
| return this;
|
100 |
| } |
101 |
| |
102 |
1122
| public PrinterBuffer indent() {
|
103 |
1122
| for (int i=0; i< indentLevel; i++) {
|
104 |
2488
| buffer.append(getIndentText());
|
105 |
| } |
106 |
| |
107 |
1122
| return this;
|
108 |
| } |
109 |
| |
110 |
1241
| public PrinterBuffer eol() {
|
111 |
1241
| buffer.append(EOL);
|
112 |
1241
| return this;
|
113 |
| } |
114 |
| |
115 |
322
| public void raiseIndent() {
|
116 |
322
| indentLevel++;
|
117 |
| } |
118 |
| |
119 |
301
| public void lowerIndent() {
|
120 |
301
| indentLevel--;
|
121 |
| } |
122 |
| |
123 |
18
| public int length() {
|
124 |
18
| return buffer.length();
|
125 |
| } |
126 |
| |
127 |
119
| public String toString() {
|
128 |
119
| return buffer.toString();
|
129 |
| } |
130 |
| } |