Subversion Repositories DevTools

Rev

Rev 6914 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
package com.erggroup.buildtool.utilities;
2
/**
3
 * 
4
 * Class to simplify the appending of text to a string
5
 * Will append text with a configurable 'joiner'
6
 * 
7
 * The 'joiner' will only be used between strings. Not before the first or after the last
8
 * The 'joiner' may be changed on the fly
9
 * 
10
 * The append and join methods may be chained
11
 * 
12
 *
13
 */
14
 
15
public class StringAppender {
16
    String joiner;
17
    StringBuilder text = new StringBuilder();
18
    boolean skip = true;
19
 
20
    public StringAppender(String joiner)
21
    {
22
        setJoin(joiner);
23
    }
24
 
25
    public StringAppender setJoin(String joiner)
26
    {
27
        this.joiner = joiner;
28
        return this;
29
    }
30
 
31
    public StringAppender append(String text)
32
    {
33
        if ( !skip ) {
34
            this.text.append(joiner);
35
        }
36
        skip = false;
37
        this.text.append(text);
38
        return this;
39
    }
40
 
41
    public String toString()
42
    {
43
        return text.toString();
44
    }
45
 
46
    public StringBuilder getStringBuilder()
47
    {
48
        return text;
49
    }
50
 
51
    public int length() {
52
        return text.length();
53
    }
54
}