KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > transaction > DoubleKeyedHashMap


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.transaction;
19
20 import java.util.Map JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Collection JavaDoc;
23
24 /**
25  * <b>Really</b> stupid implementation of a double keyed map.
26  *
27  * @version $Rev: 158827 $ $Date: 2005-03-23 12:11:56 -0800 (Wed, 23 Mar 2005) $
28  */

29 public final class DoubleKeyedHashMap {
30     private final Map JavaDoc map = new HashMap JavaDoc();
31
32     public Object JavaDoc put(Object JavaDoc key1, Object JavaDoc key2, Object JavaDoc value) {
33         return map.put(new Key(key1, key2), value);
34     }
35
36     public Object JavaDoc get(Object JavaDoc key1, Object JavaDoc key2) {
37         return map.get(new Key(key1, key2));
38     }
39
40     public Object JavaDoc remove(Object JavaDoc key1, Object JavaDoc key2) {
41         return map.remove(new Key(key1, key2));
42     }
43
44     public Collection JavaDoc values() {
45         return map.values();
46     }
47
48     public void clear() {
49         map.clear();
50     }
51
52     public boolean isEmpty() {
53         return map.isEmpty();
54     }
55
56     private final static class Key {
57         private final Object JavaDoc part1;
58         private final Object JavaDoc part2;
59
60         public Key(Object JavaDoc part1, Object JavaDoc part2) {
61             this.part1 = part1;
62             this.part2 = part2;
63         }
64
65         public int hashCode() {
66             return part1.hashCode() ^ part2.hashCode();
67         }
68
69         public boolean equals(Object JavaDoc obj) {
70             if (obj instanceof Key) {
71                 Key other = (Key) obj;
72                 return this.part1.equals(other.part1) && this.part2.equals(other.part2);
73             } else {
74                 return false;
75             }
76         }
77     }
78 }
79
Popular Tags