diff -r ed84c8bdd87b -r ca54040b4409 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 Sun Oct 30 22:13:32 2011 +0100 @@ -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; + } }