01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.util;
20:
21: import java.util.ArrayList;
22: import java.util.HashMap;
23: import java.util.Map;
24: import java.util.Set;
25: import java.util.Hashtable;
26: import java.io.Serializable;
27:
28: /**
29: * This will make a hash map which can contain multiple entries for the same hash value.
30: */
31: public class MultipleEntryHashMap {
32:
33: private Map table;
34:
35: public MultipleEntryHashMap() {
36: this .table = new Hashtable(1);
37: }
38:
39: /**
40: * If you call get once in this, it will remove that item from the map
41: *
42: * @param key
43: * @return
44: */
45: public Object get(Object key) {
46: ArrayList list = (ArrayList) table.get(key);
47: if (list != null && list.size() > 0) {
48: Object o = list.get(0);
49: list.remove(0);
50: // if (list.size() == 0) {
51: // table.remove(key);
52: // }
53: return o;
54: }
55:
56: return null;
57:
58: }
59:
60: public Object put(Object key, Object value) {
61: ArrayList list = (ArrayList) table.get(key);
62: if (list == null) {
63: ArrayList listToBeAdded = new ArrayList();
64: table.put(key, listToBeAdded);
65: listToBeAdded.add(value);
66: } else {
67: list.add(value);
68: }
69:
70: return value;
71: }
72:
73: public Set keySet() {
74:
75: return table.keySet();
76: }
77: }
|