6129 |
12 Feb 21 |
nicklas |
1 |
package net.sf.basedb.varsearch.util; |
6129 |
12 Feb 21 |
nicklas |
2 |
|
6129 |
12 Feb 21 |
nicklas |
3 |
|
6129 |
12 Feb 21 |
nicklas |
4 |
/** |
6129 |
12 Feb 21 |
nicklas |
StringBuilder-like wrapper that ignore null values that are |
6129 |
12 Feb 21 |
nicklas |
appended. |
6129 |
12 Feb 21 |
nicklas |
@author nicklas |
6129 |
12 Feb 21 |
nicklas |
8 |
*/ |
6129 |
12 Feb 21 |
nicklas |
9 |
public class NullSafeStringBuilder |
6129 |
12 Feb 21 |
nicklas |
10 |
{ |
6129 |
12 Feb 21 |
nicklas |
11 |
|
6129 |
12 Feb 21 |
nicklas |
12 |
|
6129 |
12 Feb 21 |
nicklas |
13 |
private final StringBuilder sb; |
6129 |
12 Feb 21 |
nicklas |
14 |
|
6129 |
12 Feb 21 |
nicklas |
15 |
public NullSafeStringBuilder() |
6129 |
12 Feb 21 |
nicklas |
16 |
{ |
6129 |
12 Feb 21 |
nicklas |
17 |
this.sb = new StringBuilder(); |
6129 |
12 Feb 21 |
nicklas |
18 |
} |
6129 |
12 Feb 21 |
nicklas |
19 |
|
6129 |
12 Feb 21 |
nicklas |
20 |
/** |
6129 |
12 Feb 21 |
nicklas |
Get access to actual StringBuilder. |
6129 |
12 Feb 21 |
nicklas |
22 |
*/ |
6129 |
12 Feb 21 |
nicklas |
23 |
public StringBuilder sb() |
6129 |
12 Feb 21 |
nicklas |
24 |
{ |
6129 |
12 Feb 21 |
nicklas |
25 |
return sb; |
6129 |
12 Feb 21 |
nicklas |
26 |
} |
6129 |
12 Feb 21 |
nicklas |
27 |
|
6129 |
12 Feb 21 |
nicklas |
28 |
/** |
6129 |
12 Feb 21 |
nicklas |
Append a string, ignoring null values. |
6129 |
12 Feb 21 |
nicklas |
30 |
*/ |
6129 |
12 Feb 21 |
nicklas |
31 |
public NullSafeStringBuilder append(String str) |
6129 |
12 Feb 21 |
nicklas |
32 |
{ |
6129 |
12 Feb 21 |
nicklas |
33 |
if (str != null) sb.append(str); |
6129 |
12 Feb 21 |
nicklas |
34 |
return this; |
6129 |
12 Feb 21 |
nicklas |
35 |
} |
6129 |
12 Feb 21 |
nicklas |
36 |
|
6129 |
12 Feb 21 |
nicklas |
37 |
@Override |
6129 |
12 Feb 21 |
nicklas |
38 |
public String toString() |
6129 |
12 Feb 21 |
nicklas |
39 |
{ |
6129 |
12 Feb 21 |
nicklas |
40 |
return sb.toString(); |
6129 |
12 Feb 21 |
nicklas |
41 |
} |
6129 |
12 Feb 21 |
nicklas |
42 |
|
6129 |
12 Feb 21 |
nicklas |
43 |
} |