aa
SB.java
Go to the documentation of this file.
1
package
com.cliffc.aa.util;
2
3
import
com
.
cliffc
.
aa
.
type
.
Type
;
4
8
public
final
class
SB
{
9
private
final
StringBuilder
_sb
;
10
private
int
_indent
= 0;
11
public
SB
( ) {
_sb
=
new
StringBuilder( ); }
12
public
SB
(String
s
) {
_sb
=
new
StringBuilder(
s
); }
13
public
SB
p
( String
s
) {
_sb
.append(
s
);
return
this
; }
14
public
SB
p
(
Type
t ) {
_sb
.append(t.
toString
());
return
this
; }
15
public
SB
p
(
float
s
) {
16
if
( Float.isNaN(
s
) )
17
_sb
.append(
"Float.NaN"
);
18
else
if
( Float.isInfinite(
s
) ) {
19
_sb
.append(
s
> 0 ?
"Float.POSITIVE_INFINITY"
:
"Float.NEGATIVE_INFINITY"
);
20
}
else
_sb
.append(
s
);
21
return
this
;
22
}
23
public
SB
p
(
double
s
) {
24
if
( Double.isNaN(
s
) )
25
_sb
.append(
"Double.NaN"
);
26
else
if
( Double.isInfinite(
s
) ) {
27
_sb
.append(
s
> 0 ?
"Double.POSITIVE_INFINITY"
:
"Double.NEGATIVE_INFINITY"
);
28
}
else
_sb
.append(
s
);
29
return
this
;
30
}
31
public
SB
p
(
char
s
) {
_sb
.append(
s
);
return
this
; }
32
public
SB
p
(
int
s
) {
_sb
.append(
s
);
return
this
; }
33
public
SB
p
(
long
s
) {
_sb
.append(
s
);
return
this
; }
34
public
SB
p
(
boolean
s
) {
_sb
.append(
s
);
return
this
; }
35
// Not spelled "p" on purpose: too easy to accidentally say "p(1.0)" and
36
// suddenly call the autoboxed version.
37
public
SB
pobj
( Object
s
) {
_sb
.append(
s
.
toString
());
return
this
; }
38
public
SB
i
(
int
d ) {
for
(
int
i
=0;
i
<d+
_indent
;
i
++ )
p
(
" "
);
return
this
; }
39
public
SB
i
( ) {
return
i
(0); }
40
public
SB
ip
(String
s
) {
return
i
().
p
(
s
); }
41
public
SB
s
() {
_sb
.append(
' '
);
return
this
; }
42
43
// Increase indentation
44
public
SB
ii
(
int
i
) {
_indent
+=
i
;
return
this
; }
45
// Decrease indentation
46
public
SB
di
(
int
i
) {
_indent
-=
i
;
return
this
; }
47
48
public
SB
nl
( ) {
return
p
(System.lineSeparator()); }
49
50
// Delete last char. Useful when doing string-joins and JSON printing and an
51
// extra seperater char needs to be removed:
52
//
53
// sb.p('[');
54
// for( Foo foo : foos )
55
// sb.p(foo).p(',');
56
// sb.unchar().p(']'); // remove extra trailing comma
57
//
58
public
SB
unchar
() {
return
unchar
(1); }
59
public
SB
unchar
(
int
x) {
_sb
.setLength(
_sb
.length()-x);
return
this
; }
60
61
public
SB
clear
() {
_sb
.setLength(0);
return
this
; }
62
@Override
public
String
toString
() {
return
_sb
.toString(); }
63
}
com.cliffc.aa.util.SB.p
SB p(char s)
Definition:
SB.java:31
com.cliffc.aa.util.SB.ii
SB ii(int i)
Definition:
SB.java:44
com.cliffc
com.cliffc.aa.type.Type.toString
final String toString()
Definition:
Type.java:127
com.cliffc.aa.util.SB.di
SB di(int i)
Definition:
SB.java:46
com.cliffc.aa.type.Type
an implementation of language AA
Definition:
Type.java:94
com.cliffc.aa.util.SB.clear
SB clear()
Definition:
SB.java:61
com.cliffc.aa.util.SB.p
SB p(int s)
Definition:
SB.java:32
com.cliffc.aa.util.SB.pobj
SB pobj(Object s)
Definition:
SB.java:37
com.cliffc.aa.util.SB.p
SB p(boolean s)
Definition:
SB.java:34
com.cliffc.aa.util.SB._indent
int _indent
Definition:
SB.java:10
com.cliffc.aa.util.SB.unchar
SB unchar()
Definition:
SB.java:58
com.cliffc.aa.util.SB.i
SB i()
Definition:
SB.java:39
com.cliffc.aa.util.SB.ip
SB ip(String s)
Definition:
SB.java:40
com.cliffc.aa.util.SB.s
SB s()
Definition:
SB.java:41
com.cliffc.aa.util.SB.p
SB p(double s)
Definition:
SB.java:23
com.cliffc.aa.util.SB.p
SB p(float s)
Definition:
SB.java:15
com.cliffc.aa.util.SB.p
SB p(long s)
Definition:
SB.java:33
com.cliffc.aa.util.SB.p
SB p(Type t)
Definition:
SB.java:14
com.cliffc.aa.util.SB.SB
SB(String s)
Definition:
SB.java:12
com.cliffc.aa.util.SB
Tight/tiny StringBuilder wrapper.
Definition:
SB.java:8
com.cliffc.aa.util.SB._sb
final StringBuilder _sb
Definition:
SB.java:9
com.cliffc.aa
Definition:
AA.java:1
com.cliffc.aa.util.SB.nl
SB nl()
Definition:
SB.java:48
com.cliffc.aa.util.SB.unchar
SB unchar(int x)
Definition:
SB.java:59
com.cliffc.aa.util.SB.p
SB p(String s)
Definition:
SB.java:13
com.cliffc.aa.util.SB.i
SB i(int d)
Definition:
SB.java:38
com
com.cliffc.aa.util.SB.SB
SB()
Definition:
SB.java:11
com.cliffc.aa.util.SB.toString
String toString()
Definition:
SB.java:62
com.cliffc.aa.type
Definition:
Bits.java:1
src
main
java
com
cliffc
aa
util
SB.java
Generated by
1.8.18