1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt;
18
19 import java.util.HashMap;
20 import java.util.Set;
21
22 /***
23 * Collective for <code>Betwixt</code> optional behaviour hints.
24 * An option links a name with a value (both strings).
25 *
26 * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
27 * @since 0.5
28 */
29 public class Options {
30 /*** Empty string array for use with toArray */
31 private static final String[] EMPTY_STRING_ARRAY = {};
32 /*** Option values indexed by name */
33 private HashMap valuesByName = new HashMap();
34
35 /***
36 * Gets the value (if any) associated with the given name.
37 * @param name <code>String</code>, not null
38 * @return the associated value, or null if no value is assocated
39 */
40 public String getValue(String name) {
41 return (String) valuesByName.get(name);
42 }
43
44 /***
45 * Gets the names of each option.
46 * @return
47 */
48 public String[] getNames() {
49 Set names = valuesByName.keySet();
50 return (String[]) names.toArray(EMPTY_STRING_ARRAY);
51 }
52
53 /***
54 * Adds the option.
55 * The rule with options is that the last call to set the
56 * value with a given name wins.
57 * @param name <code>String</code> name, not null
58 * @param value <code>Strong</code> name, not null
59 */
60 public void addOption(String name, String value) {
61 valuesByName.put(name, value);
62 }
63 }