001package org.hl7.fhir.utilities;
002
003/**
004 * Encapsulates StringBuilder to build strings of values separated by comma
005 * @author Ewout
006 */
007
008public class CommaSeparatedStringBuilder {
009
010  boolean first = true;
011  String sep = ", ";
012  StringBuilder b = new StringBuilder();
013  int count = 0;
014
015  public CommaSeparatedStringBuilder() {
016  }
017  
018  public CommaSeparatedStringBuilder(String sep) {
019    this.sep = sep;
020  }
021
022  public void append(String value) {
023    if (!first)
024      b.append(sep);
025    b.append(value);
026    first = false;
027    count++;    
028  }
029  
030  public int length() {
031    return b.length();
032  }
033  
034  public int count() {
035    return count;
036  }
037
038  @Override
039  public String toString() {
040    return b.toString();
041  }
042
043  public void appendIfNotNull(String s) {
044   if (!Utilities.noString(s))
045     append(s);
046    
047  }
048}