diff -r ed84c8bdd87b -r da0c30d28e22 src/org/sonews/util/StringTemplate.java --- a/src/org/sonews/util/StringTemplate.java Sun Aug 29 17:28:58 2010 +0200 +++ b/src/org/sonews/util/StringTemplate.java Wed Sep 14 22:39:22 2011 +0200 @@ -26,72 +26,67 @@ * @author Christian Lins * @since sonews/0.5.0 */ -public class StringTemplate +public class StringTemplate { - private String str = null; - private String templateDelimiter = "%"; - private Map templateValues = new HashMap(); - - public StringTemplate(String str, final String templateDelimiter) - { - if(str == null || templateDelimiter == null) - { - throw new IllegalArgumentException("null arguments not allowed"); - } + private String str = null; + private String templateDelimiter = "%"; + private Map templateValues = new HashMap(); - this.str = str; - this.templateDelimiter = templateDelimiter; - } - - public StringTemplate(String str) - { - this(str, "%"); - } - - public StringTemplate set(String template, String value) - { - if(template == null || value == null) - { - throw new IllegalArgumentException("null arguments not allowed"); - } - - this.templateValues.put(template, value); - return this; - } - - public StringTemplate set(String template, long value) - { - return set(template, Long.toString(value)); - } - - public StringTemplate set(String template, double value) - { - return set(template, Double.toString(value)); - } - - public StringTemplate set(String template, Object obj) - { - if(template == null || obj == null) - { - throw new IllegalArgumentException("null arguments not allowed"); - } + public StringTemplate(String str, final String templateDelimiter) + { + if (str == null || templateDelimiter == null) { + throw new IllegalArgumentException("null arguments not allowed"); + } - return set(template, obj.toString()); - } - - @Override - public String toString() - { - String ret = str; + this.str = str; + this.templateDelimiter = templateDelimiter; + } - for(String key : this.templateValues.keySet()) - { - String value = this.templateValues.get(key); - ret = ret.replace(templateDelimiter + key, value); - } - - return ret; - } + public StringTemplate(String str) + { + this(str, "%"); + } + public StringTemplate set(String template, String value) + { + if (template == null || value == null) { + throw new IllegalArgumentException("null arguments not allowed"); + } + + this.templateValues.put(template, value); + return this; + } + + public StringTemplate set(String template, long value) + { + return set(template, Long.toString(value)); + } + + public StringTemplate set(String template, double value) + { + return set(template, Double.toString(value)); + } + + public StringTemplate set(String template, Object obj) + { + if (template == null || obj == null) { + throw new IllegalArgumentException("null arguments not allowed"); + } + + return set(template, obj.toString()); + } + + @Override + public String toString() + { + String ret = str; + + for (String key : this.templateValues.keySet()) { + String value = this.templateValues.get(key); + ret = ret.replace(templateDelimiter + key, value); + } + + return ret; + } }