source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/MultiMap.java@ 7306

Last change on this file since 7306 was 5800, checked in by cs025, 21 years ago

Adding gs3build

  • Property svn:keywords set to Author Date Id Revision
File size: 1.3 KB
Line 
1package org.greenstone.gsdl3.gs3build.util;
2
3import java.util.List;
4import java.util.Map;
5import java.util.Set;
6import java.util.HashMap;
7import java.util.ArrayList;
8
9public class MultiMap
10{ Map map;
11
12 public MultiMap()
13 { this.map = new HashMap();
14 }
15
16 public boolean containsKey(Object key)
17 { return this.map.containsKey(key);
18 }
19
20 public void setOnly(Object key, Object value)
21 { List child = new ArrayList();
22 child.add(value);
23 this.map.put(key, child);
24 }
25
26 public void put(Object key, Object value)
27 { List children;
28
29 children = (List) this.map.get(key);
30 if (children == null)
31 { children = new ArrayList();
32 this.map.put(key, children);
33 }
34 children.add(value);
35 }
36
37 public Object get(Object key)
38 { List list = this.getAll(key);
39 if (list == null)
40 { return null;
41 }
42 return list.get(0);
43 }
44
45 public List getAll(Object key)
46 { return (List) this.map.get(key);
47 }
48
49 public void remove(Object key)
50 { this.map.remove(key);
51 }
52
53 public boolean remove(Object key, Object value)
54 { if (!this.map.containsKey(key))
55 { return false;
56 }
57
58 List children = (List) this.map.get(key);
59
60 if (children != null)
61 { for (int i = 0; i < children.size(); i ++)
62 { if (children.get(i).equals(value))
63 { children.remove(i);
64 return true;
65 }
66 }
67 }
68 return false;
69 }
70
71 public Set keySet()
72 { return this.map.keySet();
73 }
74}
Note: See TracBrowser for help on using the repository browser.