1.1 --- a/src/org/sonews/util/StringTemplate.java Sun Aug 29 17:28:58 2010 +0200
1.2 +++ b/src/org/sonews/util/StringTemplate.java Mon Jun 06 20:12:21 2011 +0200
1.3 @@ -26,72 +26,67 @@
1.4 * @author Christian Lins
1.5 * @since sonews/0.5.0
1.6 */
1.7 -public class StringTemplate
1.8 +public class StringTemplate
1.9 {
1.10
1.11 - private String str = null;
1.12 - private String templateDelimiter = "%";
1.13 - private Map<String, String> templateValues = new HashMap<String, String>();
1.14 -
1.15 - public StringTemplate(String str, final String templateDelimiter)
1.16 - {
1.17 - if(str == null || templateDelimiter == null)
1.18 - {
1.19 - throw new IllegalArgumentException("null arguments not allowed");
1.20 - }
1.21 + private String str = null;
1.22 + private String templateDelimiter = "%";
1.23 + private Map<String, String> templateValues = new HashMap<String, String>();
1.24
1.25 - this.str = str;
1.26 - this.templateDelimiter = templateDelimiter;
1.27 - }
1.28 -
1.29 - public StringTemplate(String str)
1.30 - {
1.31 - this(str, "%");
1.32 - }
1.33 -
1.34 - public StringTemplate set(String template, String value)
1.35 - {
1.36 - if(template == null || value == null)
1.37 - {
1.38 - throw new IllegalArgumentException("null arguments not allowed");
1.39 - }
1.40 -
1.41 - this.templateValues.put(template, value);
1.42 - return this;
1.43 - }
1.44 -
1.45 - public StringTemplate set(String template, long value)
1.46 - {
1.47 - return set(template, Long.toString(value));
1.48 - }
1.49 -
1.50 - public StringTemplate set(String template, double value)
1.51 - {
1.52 - return set(template, Double.toString(value));
1.53 - }
1.54 -
1.55 - public StringTemplate set(String template, Object obj)
1.56 - {
1.57 - if(template == null || obj == null)
1.58 - {
1.59 - throw new IllegalArgumentException("null arguments not allowed");
1.60 - }
1.61 + public StringTemplate(String str, final String templateDelimiter)
1.62 + {
1.63 + if (str == null || templateDelimiter == null) {
1.64 + throw new IllegalArgumentException("null arguments not allowed");
1.65 + }
1.66
1.67 - return set(template, obj.toString());
1.68 - }
1.69 -
1.70 - @Override
1.71 - public String toString()
1.72 - {
1.73 - String ret = str;
1.74 + this.str = str;
1.75 + this.templateDelimiter = templateDelimiter;
1.76 + }
1.77
1.78 - for(String key : this.templateValues.keySet())
1.79 - {
1.80 - String value = this.templateValues.get(key);
1.81 - ret = ret.replace(templateDelimiter + key, value);
1.82 - }
1.83 -
1.84 - return ret;
1.85 - }
1.86 + public StringTemplate(String str)
1.87 + {
1.88 + this(str, "%");
1.89 + }
1.90
1.91 + public StringTemplate set(String template, String value)
1.92 + {
1.93 + if (template == null || value == null) {
1.94 + throw new IllegalArgumentException("null arguments not allowed");
1.95 + }
1.96 +
1.97 + this.templateValues.put(template, value);
1.98 + return this;
1.99 + }
1.100 +
1.101 + public StringTemplate set(String template, long value)
1.102 + {
1.103 + return set(template, Long.toString(value));
1.104 + }
1.105 +
1.106 + public StringTemplate set(String template, double value)
1.107 + {
1.108 + return set(template, Double.toString(value));
1.109 + }
1.110 +
1.111 + public StringTemplate set(String template, Object obj)
1.112 + {
1.113 + if (template == null || obj == null) {
1.114 + throw new IllegalArgumentException("null arguments not allowed");
1.115 + }
1.116 +
1.117 + return set(template, obj.toString());
1.118 + }
1.119 +
1.120 + @Override
1.121 + public String toString()
1.122 + {
1.123 + String ret = str;
1.124 +
1.125 + for (String key : this.templateValues.keySet()) {
1.126 + String value = this.templateValues.get(key);
1.127 + ret = ret.replace(templateDelimiter + key, value);
1.128 + }
1.129 +
1.130 + return ret;
1.131 + }
1.132 }