Subversion Repositories DevTools

Rev

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

package com.erggroup.buildtool.utilities;
/**
 * 
 * Class to simplify the appending of text to a string
 * Will append text with a configurable 'joiner'
 * 
 * The 'joiner' will only be used between strings. Not before the first or after the last
 * The 'joiner' may be changed on the fly
 * 
 * The append and join methods may be chained
 * 
 *
 */

public class StringAppender {
    String joiner;
    StringBuilder text = new StringBuilder();
    boolean skip = true;

    public StringAppender(String joiner)
    {
        setJoin(joiner);
    }
    
    public StringAppender setJoin(String joiner)
    {
        this.joiner = joiner;
        return this;
    }
    
    public StringAppender append(String text)
    {
        if ( !skip ) {
            this.text.append(joiner);
        }
        skip = false;
        this.text.append(text);
        return this;
    }
    
    public String toString()
    {
        return text.toString();
    }
    
    public StringBuilder getStringBuilder()
    {
        return text;
    }

    public int length() {
        return text.length();
    }
}