KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > jdiet > rt > MapEntryImpl


1 package spoon.jdiet.rt;
2
3
4 /**
5  * An implementation of the Map.Entry interface. This class is used by the code
6  * produced by the J2MEConverter processor as a replacement for Map.Entry which
7  * is not available with J2ME.
8  *
9  * @author Lionel Seinturier <Lionel.Seinturier@lifl.fr>
10  */

11 public class MapEntryImpl {
12         
13     private Object JavaDoc key;
14     private Object JavaDoc value;
15
16     public MapEntryImpl(Object JavaDoc key, Object JavaDoc value) {
17         this.key = key;
18         this.value = value;
19     }
20     
21     public Object JavaDoc getKey() {
22         return key;
23     }
24
25     public Object JavaDoc getValue() {
26         return value;
27     }
28
29     public Object JavaDoc setValue(Object JavaDoc value) {
30         /*
31          * Map.Entry.setValue() writes back values to the Map.
32          * The operation is not supported as we can not implement this behavior
33          * with Enumeration and Hashtable.
34          *
35          * Do not use UnsupportedOperationException (not in the J2ME API.)
36          */

37         throw new RuntimeException JavaDoc(
38                 "Method MapEntryImpl.setValue(Object) not supported");
39     }
40
41     public boolean equals(Object JavaDoc o) {
42         if( ! (o instanceof MapEntryImpl) ) {
43             return false;
44         }
45         MapEntryImpl e2 = (MapEntryImpl) o;
46         return ( key==null ? e2.getKey()==null : key.equals(e2.getKey())) &&
47                ( value==null ? e2.getValue()==null : value.equals(e2.getValue()));
48         
49     }
50
51     public int hashCode() {
52         return ( key==null ? 0 : key.hashCode() ) ^
53                ( value==null ? 0 : value.hashCode() );
54     }
55
56 }
57
Popular Tags