package weiss.util; /** * Hash table implementation of the Map. */ public class HashMap extends MapImpl { /** * Construct an empty HashMap. */ public HashMap( ) { super( new HashSet>( ) ); } /** * Construct a HashMap with same key/value pairs as another map. * @param other the other map. */ public HashMap( Map other ) { super( other ); } protected Map.Entry makePair( KeyType key, ValueType value ) { return new Pair( key, value ); } protected Set makeEmptyKeySet( ) { return new HashSet( ); } protected Set> clonePairSet( Set> pairSet ) { return new HashSet>( pairSet ); } private static final class Pair extends MapImpl.Pair { public Pair( KeyType k, ValueType v ) { super( k, v ); } public int hashCode( ) { KeyType k = getKey( ); return k == null ? 0 : k.hashCode( ); } public boolean equals( Object other ) { if( other instanceof Map.Entry ) { KeyType thisKey = getKey( ); KeyType otherKey = ((Map.Entry) other).getKey( ); if( thisKey == null ) return thisKey == otherKey; return thisKey.equals( otherKey ); } else return false; } } }