source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DBInfo.java@ 24254

Last change on this file since 24254 was 24254, checked in by ak19, 13 years ago

Commits for ticket 770 concerning the display of multiple values for a metadata (like dc.Title) when classified by that metadata. So when the user browses by dc.Title, they no longer merely see a doc listed once for each dc.Title assigned but under the same (first retrieved) dc.Title, but they should now see the doc listed once for each dc.Title assigned to it with a different dc.Title value each time.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
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 */
19package org.greenstone.gsdl3.util;
20
21import java.util.Vector;
22import java.util.HashMap;
23import 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 */
28public 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 /** 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 "";
61 }
62 if(offset >= 0 && offset < items.size()) {
63 return (String)items.get(offset);
64 } // else
65 return (String)items.firstElement();
66 }
67
68
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();
76 }
77 v.add(value);
78 info_map_.put(key, v);
79 }
80 /** return a vector of all values associated with a key
81 * @return Vector of Strings
82 */
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}
Note: See TracBrowser for help on using the repository browser.