1 2 12 package com.versant.core.util; 13 14 import java.util.Map ; 15 import java.util.Iterator ; 16 17 21 public final class StringList { 22 23 private char delim; 24 private StringBuffer buf; 25 private boolean first = true; 26 27 public StringList() { 28 this(StringListParser.DEFAULT_DELIM, 40); 29 } 30 31 public StringList(int initialSize) { 32 this(StringListParser.DEFAULT_DELIM, initialSize); 33 } 34 35 public StringList(char delim, int initialSize) { 36 this.delim = delim; 37 buf = new StringBuffer (initialSize); 38 } 39 40 43 public void append(int x) { 44 if (first) first = false; 45 else buf.append(delim); 46 buf.append(x); 47 } 48 49 52 public void append(boolean x) { 53 if (first) first = false; 54 else buf.append(delim); 55 buf.append(x ? 'Y' : 'N'); 56 } 57 58 61 public void append(double x) { 62 if (first) first = false; 63 else buf.append(delim); 64 buf.append(x); 65 } 66 67 71 public void append(String s) { 72 if (first) first = false; 73 else buf.append(delim); 74 buf.append(s); 75 } 76 77 80 public void append(Class c) { 81 if (first) first = false; 82 else buf.append(delim); 83 if (c == null) buf.append('-'); 84 else buf.append(c.getName()); 85 } 86 87 91 public void appendQuoted(String s) { 92 if (first) first = false; 93 else buf.append(delim); 94 if (s == null) { 95 buf.append('-'); 96 } else { 97 buf.append('"'); 98 int n = s.length(); 99 for (int i = 0; i < n; i++) { 100 char c = s.charAt(i); 101 if (c == '"') buf.append('"'); 102 buf.append(c); 103 } 104 buf.append('"'); 105 } 106 } 107 108 111 public void appendProperties(Map props) { 112 for (Iterator i = props.entrySet().iterator(); i.hasNext(); ) { 113 Map.Entry e = (Map.Entry )i.next(); 114 append((String )e.getKey()); 115 appendQuoted((String )e.getValue()); 116 } 117 } 118 119 122 public String toString() { return buf.toString(); } 123 124 127 public void reset() { 128 buf.setLength(0); 129 first = true; 130 } 131 132 135 public int length() { return buf.length(); } 136 137 } 138 | Popular Tags |