annotate servlet/src/digilib/util/OptionsSet.java @ 854:1e2e9599d84c stream

(slightly) fixed enhance and colop in linux.
author robcast
date Mon, 07 Mar 2011 11:59:11 +0100
parents 0885f5ca5b24
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
547
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
1 /**
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
2 *
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
3 */
557
0885f5ca5b24 more refactoring and rearranging
robcast
parents: 547
diff changeset
4 package digilib.util;
547
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
5
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
6 import java.util.HashSet;
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
7 import java.util.StringTokenizer;
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
8
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
9 /**
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
10 * @author casties
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
11 *
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
12 */
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
13 @SuppressWarnings("serial")
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
14 public class OptionsSet extends HashSet<String> {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
15
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
16 protected String optionSep = ",";
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
17
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
18 public OptionsSet() {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
19 super();
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
20 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
21
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
22 /** Constructor with String of options.
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
23 * @param s
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
24 */
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
25 public OptionsSet(String s) {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
26 super();
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
27 parseString(s);
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
28 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
29
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
30 /** Adds all options from String to Set.
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
31 * @param s
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
32 */
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
33 public void parseString(String s) {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
34 if (s != null) {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
35 StringTokenizer i = new StringTokenizer(s, optionSep);
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
36 while (i.hasMoreTokens()) {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
37 String opt = i.nextToken();
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
38 this.add(opt);
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
39 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
40 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
41 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
42
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
43 public boolean hasOption(String opt) {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
44 return this.contains(opt);
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
45 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
46
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
47 public String toString() {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
48 StringBuffer b = new StringBuffer();
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
49 for (String s: this) {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
50 if (b.length() > 0) {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
51 b.append(optionSep);
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
52 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
53 b.append(s);
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
54 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
55 return b.toString();
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
56 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
57
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
58
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
59 public String getOptionSep() {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
60 return optionSep;
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
61 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
62
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
63 public void setOptionSep(String optionSep) {
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
64 this.optionSep = optionSep;
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
65 }
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
66
e1094c5ec032 more cleanup and refactoring
robcast
parents:
diff changeset
67 }