title: HashMap implementation that allows to override hash and equals method
body: <p>In Java you can override the equals and hash method of the HashMap's key object to determine how the hash code is generated and when two key objects should be considered equal.</p>
  
  <p>Is there any Map implementation that allows to define the hash and equals on in the Map class by overriding its hash method (and determining key equality by an equals(key1,key2) method that can be overridden)?</p>
  
  <p><strong>Use case:</strong></p>
  
  <p>Ĺets assume we have a Objects of class GeoData, containing the fields:  country, region, city. We want access two Maps: map <strong><em>x</em></strong> stores the number of inhabitants of each region and map <strong><em>y</em></strong> the number of inhabitants of each city.</p>
  
  <p>To get both informations for a GeoData object we first need to extract country and region from that object, then create a new Object of class X that defines hash and equals considering country and region and use it as key for map <strong><em>x</em></strong>. Additionally we need to do the same with country, region and city. Create a new Object of class Y and use that get the value from map <strong><em>y</em></strong>.</p>
  
  <p>Wouldn't it be easier if we extend a Map implementation for each of these maps <strong><em>x</em></strong> and <strong><em>y</em></strong> and override a hash(GeoData key) and equals(GeoData key1,GeoData key2) method, which would also avoid to create new key objects for every access?</p>
  
  <p>hash(GeoData key) could then either use country and region in map <strong><em>x</em></strong>, or country,region and city in map <strong><em>y</em></strong> for hash code calculation.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Correctly marked as duplicate. <a href="https://stackoverflow.com/a/20030782/2148569">This</a> answer suggesting apache commons-collections AbstractHashMap is what I was looking for.</p>