comparison 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
comparison
equal deleted inserted replaced
902:89ba3ffcf552 903:7779b37d1d05
1 /**
2 *
3 */
4 package digilib.util;
5
6 import java.util.HashSet;
7 import java.util.StringTokenizer;
8
9 /**
10 * @author casties
11 *
12 */
13 @SuppressWarnings("serial")
14 public class OptionsSet extends HashSet<String> {
15
16 protected String optionSep = ",";
17
18 public OptionsSet() {
19 super();
20 }
21
22 /** Constructor with String of options.
23 * @param s
24 */
25 public OptionsSet(String s) {
26 super();
27 parseString(s);
28 }
29
30 /** Adds all options from String to Set.
31 * @param s
32 */
33 public void parseString(String s) {
34 if (s != null) {
35 StringTokenizer i = new StringTokenizer(s, optionSep);
36 while (i.hasMoreTokens()) {
37 String opt = i.nextToken();
38 this.add(opt);
39 }
40 }
41 }
42
43 public boolean hasOption(String opt) {
44 return this.contains(opt);
45 }
46
47 public String toString() {
48 StringBuffer b = new StringBuffer();
49 for (String s: this) {
50 if (b.length() > 0) {
51 b.append(optionSep);
52 }
53 b.append(s);
54 }
55 return b.toString();
56 }
57
58
59 public String getOptionSep() {
60 return optionSep;
61 }
62
63 public void setOptionSep(String optionSep) {
64 this.optionSep = optionSep;
65 }
66
67 }