[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;
|
---|
[24393] | 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
|
---|
[9874] | 29 | */
|
---|
[24393] | 30 | public class DBInfo
|
---|
| 31 | {
|
---|
[25635] | 32 | protected HashMap<String, Vector<String>> info_map_;
|
---|
[9874] | 33 |
|
---|
[24393] | 34 | public DBInfo()
|
---|
| 35 | {
|
---|
[25635] | 36 | info_map_ = new HashMap<String, Vector<String>>();
|
---|
[24393] | 37 | }
|
---|
[9874] | 38 |
|
---|
[24393] | 39 | // methods for keys that can have a single value
|
---|
[9874] | 40 |
|
---|
[24393] | 41 | /** set the value for a key - replaces any existing value */
|
---|
| 42 | public void setInfo(String key, String value)
|
---|
| 43 | {
|
---|
[25635] | 44 | Vector<String> v = new Vector<String>();
|
---|
[24393] | 45 | v.add(value);
|
---|
| 46 | info_map_.put(key, v);
|
---|
| 47 | }
|
---|
[9874] | 48 |
|
---|
[24393] | 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 | {
|
---|
[29058] | 55 | Vector<String> items = info_map_.get(key);
|
---|
[24393] | 56 | if (items == null)
|
---|
| 57 | {
|
---|
| 58 | return "";
|
---|
| 59 | }
|
---|
[29058] | 60 | return items.firstElement();
|
---|
[24393] | 61 | }
|
---|
[9874] | 62 |
|
---|
[24393] | 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 | {
|
---|
[25635] | 68 | Vector<String> v = info_map_.get(key);
|
---|
[24393] | 69 | if (v == null)
|
---|
| 70 | {
|
---|
[25635] | 71 | v = new Vector<String>();
|
---|
[24393] | 72 | }
|
---|
| 73 | v.add(value);
|
---|
| 74 | info_map_.put(key, v);
|
---|
[9874] | 75 | }
|
---|
| 76 |
|
---|
[24393] | 77 | /**
|
---|
| 78 | * return a vector of all values associated with a key
|
---|
| 79 | *
|
---|
| 80 | * @return Vector of Strings
|
---|
| 81 | */
|
---|
[25635] | 82 | public Vector<String> getMultiInfo(String key)
|
---|
[24393] | 83 | {
|
---|
[25635] | 84 | return info_map_.get(key);
|
---|
[24254] | 85 | }
|
---|
| 86 |
|
---|
[24393] | 87 | /** returns a list of all the keys in the info */
|
---|
[25635] | 88 | public Set<String> getKeys()
|
---|
[24393] | 89 | {
|
---|
| 90 | return info_map_.keySet();
|
---|
[9874] | 91 | }
|
---|
| 92 |
|
---|
[24393] | 93 | /** returns the Info as a string */
|
---|
| 94 | public String toString()
|
---|
| 95 | {
|
---|
| 96 | return info_map_.toString();
|
---|
[9874] | 97 |
|
---|
[24393] | 98 | }
|
---|
[9874] | 99 | }
|
---|