title: hashCode implementation for "equals any of some fields are equal"
body: <p>I want objects of a particular class to be equal if <em>one</em> of their fields are equal. How can I write a consistent hashCode method for such a class?</p>
  
  <p>(Disclaimer because I know this is not best practice: The class is a wrapper for another class and should be used for keys in Maps. It is intended that two different of these objects with one equal field would result in the same Map entry. Actually each of the fields would identify the underlying object on their own but I do not always have the same identifying field for two objects available. I cannot control and therefore change this "ambiguous" identification mechanism. Alternative solutions to tackle this are also welcome.)</p>
  
  <p>Are there strategies for implementing hashCode() accordingly? I only know of implementations involving conjunctions (as with &amp;&amp;) in equals. How to make sure that hashCode() is the same if either of the fields is equal?</p>
  
  <p>Here is the simplified equals method for which I would like to write a consistent hashCode() implementation:</p>
  
  <pre><code>public boolean equals(C other)
  {
      return (field1 != null &amp;&amp; field1.equals(other.field1))
              || (field2 != null &amp;&amp; field2.equals(other.field2))
              || (field3 != null &amp;&amp; field3.equals(other.field3));
  }
  </code></pre>
  
  <p>EDIT: as per the input data, no cases like (1, 2, 3) equals (1, 6, 7) can occur. The objects are only produced such that some of the fields can be null, but not contradicting as in the example. Simply put in practise the only combinations equal to (1, 2, 3) should be (1, 2, 3), (1, null, null), (null, 2, null), (1, 2, null) and so forth. I acknowledge that this approach is not particularly robust.</p>