[16869] | 1 | /*
|
---|
| 2 | * DBInfo.java
|
---|
| 3 | * Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org
|
---|
| 4 | *
|
---|
| 5 | * This program is free software; you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program; if not, write to the Free Software
|
---|
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 18 | */
|
---|
[9874] | 19 | package org.greenstone.gsdl3.util;
|
---|
| 20 |
|
---|
| 21 | import java.util.Vector;
|
---|
| 22 | import java.util.HashMap;
|
---|
| 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
|
---|
| 27 | */
|
---|
| 28 | public class DBInfo {
|
---|
| 29 |
|
---|
| 30 | protected HashMap info_map_;
|
---|
| 31 |
|
---|
| 32 | public DBInfo() {
|
---|
| 33 | info_map_ = new HashMap();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | // methods for keys that can have a single value
|
---|
| 37 |
|
---|
| 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 | }
|
---|
| 44 |
|
---|
| 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 "";
|
---|
| 51 | }
|
---|
| 52 | return (String)items.firstElement();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | // methods for keys that can have multiple values
|
---|
| 56 |
|
---|
| 57 | /** add a value to a key - for keys that can have multiple values */
|
---|
| 58 | public void addInfo(String key, String value) {
|
---|
| 59 | Vector v = (Vector)info_map_.get(key);
|
---|
| 60 | if (v==null) {
|
---|
| 61 | v = new Vector();
|
---|
| 62 | }
|
---|
| 63 | v.add(value);
|
---|
| 64 | info_map_.put(key, v);
|
---|
| 65 | }
|
---|
| 66 | /** return a vector of all values associated with a key
|
---|
| 67 | * @return Vector of Strings
|
---|
| 68 | */
|
---|
| 69 | public Vector getMultiInfo(String key) {
|
---|
| 70 | return (Vector)info_map_.get(key);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /** returns a list of all the keys in the info */
|
---|
| 74 | public Set getKeys() {
|
---|
| 75 | return info_map_.keySet();
|
---|
| 76 | }
|
---|
| 77 | /** returns the Info as a string */
|
---|
| 78 | public String toString() {
|
---|
| 79 | return info_map_.toString();
|
---|
| 80 |
|
---|
| 81 | }
|
---|
| 82 | }
|
---|