Mercurial > hg > digilib-old
diff common/src/main/java/digilib/util/OptionsSet.java @ 903:7779b37d1d05
refactored into maven modules per servlet type.
can build servlet-api 2.3 and 3.0 via profile now!
author | robcast |
---|---|
date | Tue, 26 Apr 2011 20:24:31 +0200 |
parents | servlet/src/main/java/digilib/util/OptionsSet.java@ba1eb2d821a2 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/src/main/java/digilib/util/OptionsSet.java Tue Apr 26 20:24:31 2011 +0200 @@ -0,0 +1,67 @@ +/** + * + */ +package digilib.util; + +import java.util.HashSet; +import java.util.StringTokenizer; + +/** + * @author casties + * + */ +@SuppressWarnings("serial") +public class OptionsSet extends HashSet<String> { + + protected String optionSep = ","; + + public OptionsSet() { + super(); + } + + /** Constructor with String of options. + * @param s + */ + public OptionsSet(String s) { + super(); + parseString(s); + } + + /** Adds all options from String to Set. + * @param s + */ + public void parseString(String s) { + if (s != null) { + StringTokenizer i = new StringTokenizer(s, optionSep); + while (i.hasMoreTokens()) { + String opt = i.nextToken(); + this.add(opt); + } + } + } + + public boolean hasOption(String opt) { + return this.contains(opt); + } + + public String toString() { + StringBuffer b = new StringBuffer(); + for (String s: this) { + if (b.length() > 0) { + b.append(optionSep); + } + b.append(s); + } + return b.toString(); + } + + + public String getOptionSep() { + return optionSep; + } + + public void setOptionSep(String optionSep) { + this.optionSep = optionSep; + } + +}