- Timestamp:
- 2011-08-12T09:57:26+12:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DBInfo.java
r24254 r24393 22 22 import java.util.HashMap; 23 23 import java.util.Set; 24 /** class to hold info from a gdbm (or equiv) query 25 * maps a String key to a list of Strings (values) 26 * at the moment, the user must know if something has a single value or not 24 25 /** 26 * class to hold info from a gdbm (or equiv) query maps a String key to a list 27 * of Strings (values) at the moment, the user must know if something has a 28 * single value or not 27 29 */ 28 public class DBInfo { 30 public class DBInfo 31 { 32 protected HashMap info_map_; 29 33 30 protected HashMap info_map_; 34 public DBInfo() 35 { 36 info_map_ = new HashMap(); 37 } 31 38 32 public DBInfo() { 33 info_map_ = new HashMap(); 34 } 39 // methods for keys that can have a single value 35 40 36 // methods for keys that can have a single value 41 /** set the value for a key - replaces any existing value */ 42 public void setInfo(String key, String value) 43 { 44 Vector v = new Vector(); 45 v.add(value); 46 info_map_.put(key, v); 47 } 37 48 38 /** set the value for a key - replaces any existing value */ 39 public void setInfo(String key, String value) { 40 Vector v = new Vector(); 41 v.add(value); 42 info_map_.put(key, v); 43 } 49 /** 50 * get the value - used for keys that have one value, otherwise just returns 51 * the first one 52 */ 53 public String getInfo(String key) 54 { 55 Vector items = (Vector) info_map_.get(key); 56 if (items == null) 57 { 58 return ""; 59 } 60 return (String) items.firstElement(); 61 } 44 62 45 /** get the value - used for keys that have one value, otherwise just 46 * returns the first one */ 47 public String getInfo(String key) { 48 Vector items = (Vector)info_map_.get(key); 49 if (items==null) { 50 return ""; 63 // methods for keys that can have multiple values 64 65 /** add a value to a key - for keys that can have multiple values */ 66 public void addInfo(String key, String value) 67 { 68 Vector v = (Vector) info_map_.get(key); 69 if (v == null) 70 { 71 v = new Vector(); 72 } 73 v.add(value); 74 info_map_.put(key, v); 51 75 } 52 return (String)items.firstElement();53 }54 76 55 /** get the value for the key at offset. If offset out of bounds, 56 * just return the first one. */ 57 public String getInfoOffset(String key, int offset) { 58 Vector items = (Vector)info_map_.get(key); 59 if (items==null) { 60 return ""; 77 /** 78 * return a vector of all values associated with a key 79 * 80 * @return Vector of Strings 81 */ 82 public Vector getMultiInfo(String key) 83 { 84 return (Vector) info_map_.get(key); 61 85 } 62 if(offset >= 0 && offset < items.size()) {63 return (String)items.get(offset);64 } // else65 return (String)items.firstElement();66 }67 86 87 /** returns a list of all the keys in the info */ 88 public Set getKeys() 89 { 90 return info_map_.keySet(); 91 } 68 92 69 // methods for keys that can have multiple values 70 71 /** add a value to a key - for keys that can have multiple values */ 72 public void addInfo(String key, String value) { 73 Vector v = (Vector)info_map_.get(key); 74 if (v==null) { 75 v = new Vector(); 93 /** returns the Info as a string */ 94 public String toString() 95 { 96 return info_map_.toString(); 97 76 98 } 77 v.add(value);78 info_map_.put(key, v);79 }80 /** return a vector of all values associated with a key81 * @return Vector of Strings82 */83 public Vector getMultiInfo(String key) {84 return (Vector)info_map_.get(key);85 }86 87 /** returns a list of all the keys in the info */88 public Set getKeys() {89 return info_map_.keySet();90 }91 /** returns the Info as a string */92 public String toString() {93 return info_map_.toString();94 95 }96 99 }
Note:
See TracChangeset
for help on using the changeset viewer.