| TableExample.java |
1 package example;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 /**
7 * A class for showing how to test table-like objects.
8 * This idea can be used to fill different kind of data
9 * structures for test.
10 * @author vesal
11 *
12 */
13 public class TableExample {
14
15 private Map<String,String> items = new HashMap<String,String>();
16
17 /**
18 * Add new value with key to the table.
19 * Key is caseinsensitive.
20 * @param key key to use for value
21 * @param value value to add
22 *
23 * @example
24 * <pre name="test">
25 *
26 * TableExample table = new TableExample();
27 * table.add("1","red");
28 * table.add("2","blue");
29 * table.add("b","blue");
30 * table.add("B","BLUE");
31 *
32 * table.get("1") === "red";
33 * table.get("b") === "BLUE";
34 *
35 * </pre>
36 */
37 public void add(String key, String value) {
38 items.put(key.toLowerCase(),value);
39 }
40
41
42 /**
43 * Finds the value for key. Key is caseinsensitive.
44 * @param key for what the value is looked for
45 * @return the value for key, null if no value for key.
46 *
47 * @example
48 * <pre name="test">
49 *
50 * TableExample table = new TableExample();
51 * table.add("$key","$value");
52 *
53 * $key | $value
54 * -------------------
55 * 1 | red
56 * 2 | blue
57 * 3 | green
58 * 5 | yellow
59 * Y | YELLOW
60 * y | yellow
61 * red | red
62 * RED | RED
63 *
64 * table.get($key) === $result;
65 *
66 * $key | $result
67 * -------------------
68 * "1" | "red"
69 * "2" | "blue"
70 * "4" | null
71 * "5" | "yellow"
72 * "y" | "yellow"
73 * "Y" | "yellow"
74 * "red" | "RED"
75 * "RED" | "RED"
76 * "" | null
77 * null | null
78 *
79 * </pre>
80 *
81 */
82 public String get(String key) {
83 if ( key == null ) return null;
84 return items.get(key.toLowerCase());
85 }
86
87
88 /**
89 *
90 * @param args not used
91 */
92 public static void main(String[] args) {
93
94 }
95
96 }
97