source: trunk/gsdl3/src/java/org/greenstone/gsdl3/util/DBInfo.java@ 9874

Last change on this file since 9874 was 9874, checked in by kjdon, 19 years ago

merged from branch ant-install-branch: merge 1

  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1package org.greenstone.gsdl3.util;
2
3import java.util.Vector;
4import java.util.HashMap;
5import 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 */
10public 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}
Note: See TracBrowser for help on using the repository browser.