Rev 6914 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.erggroup.buildtool.utilities;import java.util.Iterator;/**** 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;}/*** Append a Set/List of strings (Sort of like a join)* @param itr - to iterate over the collection of strings* @return*/public StringAppender append(Iterator<String> itr){while(itr.hasNext()){append(itr.next());}return this;}public String toString(){return text.toString();}public StringBuilder getStringBuilder(){return text;}public int length() {return text.length();}}