Java Reference
In-Depth Information
1 package weiss.util;
2
3 public class HashMap<KeyType,ValueType> extends MapImpl<KeyType,ValueType>
4 {
5 public HashMap( )
6 { super( new HashSet<Map.Entry<KeyType,ValueType>>( ) ); }
7
8 public HashMap( Map<KeyType,ValueType> other )
9 { super( other ); }
10
11 protected Map.Entry<KeyType,ValueType> makePair( KeyType key, ValueType value )
12 { return new Pair<KeyType,ValueType>( key, value ); }
13
14 protected Set<KeyType> makeEmptyKeySet( )
15 { return new HashSet<KeyType>( ); }
16
17 protected Set<Map.Entry<KeyType,ValueType>>
18 clonePairSet( Set<Map.Entry<KeyType,ValueType>> pairSet )
19 {
20 return new HashSet<Map.Entry<KeyType,ValueType>>( pairSet );
21 }
22
23 private static final class Pair<KeyType,ValueType>
24 extends MapImpl.Pair<KeyType,ValueType>
25 {
26 public Pair( KeyType k, ValueType v )
27 { super( k, v ); }
28
29 public int hashCode( )
30 {
31 KeyType k = getKey( );
32 return k == null ? 0 : k.hashCode( );
33 }
34
35 public boolean equals( Object other )
36 {
37 if( other instanceof Map.Entry )
38 {
39 KeyType thisKey = getKey( );
40 KeyType otherKey = ((Map.Entry<KeyType,ValueType>) other).getKey( );
41
42 if( thisKey == null )
43 return thisKey == otherKey;
44 return thisKey.equals( otherKey );
45 }
46 else
47 return false;
48 }
49 }
50 }
figure 20.19
The HashMap class
 
Search WWH ::




Custom Search