1 | package org.greenstone.gsdl3.util;
|
---|
2 |
|
---|
3 | import java.util.Vector;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.Set;
|
---|
6 | /** class to hold info from a gdbm (or equiv) query
|
---|
7 | * maps a String key to a list of Strings (values)
|
---|
8 | * at the moment, the user must know if something has a single value or not
|
---|
9 | */
|
---|
10 | public class DBInfo {
|
---|
11 |
|
---|
12 | protected HashMap info_map_;
|
---|
13 |
|
---|
14 | public DBInfo() {
|
---|
15 | info_map_ = new HashMap();
|
---|
16 | }
|
---|
17 |
|
---|
18 | // methods for keys that can have a single value
|
---|
19 |
|
---|
20 | /** set the value for a key - replaces any existing value */
|
---|
21 | public void setInfo(String key, String value) {
|
---|
22 | Vector v = new Vector();
|
---|
23 | v.add(value);
|
---|
24 | info_map_.put(key, v);
|
---|
25 | }
|
---|
26 |
|
---|
27 | /** get the value - used for keys that have one value, otherwise just
|
---|
28 | * returns the first one */
|
---|
29 | public String getInfo(String key) {
|
---|
30 | Vector items = (Vector)info_map_.get(key);
|
---|
31 | if (items==null) {
|
---|
32 | return "";
|
---|
33 | }
|
---|
34 | return (String)items.firstElement();
|
---|
35 | }
|
---|
36 |
|
---|
37 | // methods for keys that can have multiple values
|
---|
38 |
|
---|
39 | /** add a value to a key - for keys that can have multiple values */
|
---|
40 | public void addInfo(String key, String value) {
|
---|
41 | Vector v = (Vector)info_map_.get(key);
|
---|
42 | if (v==null) {
|
---|
43 | v = new Vector();
|
---|
44 | }
|
---|
45 | v.add(value);
|
---|
46 | info_map_.put(key, v);
|
---|
47 | }
|
---|
48 | /** return a vector of all values associated with a key
|
---|
49 | * @return Vector of Strings
|
---|
50 | */
|
---|
51 | public Vector getMultiInfo(String key) {
|
---|
52 | return (Vector)info_map_.get(key);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /** returns a list of all the keys in the info */
|
---|
56 | public Set getKeys() {
|
---|
57 | return info_map_.keySet();
|
---|
58 | }
|
---|
59 | /** returns the Info as a string */
|
---|
60 | public String toString() {
|
---|
61 | return info_map_.toString();
|
---|
62 |
|
---|
63 | }
|
---|
64 | }
|
---|