For a HashMap that maps from a custom class, how to make it so that two equivalent keys will map to say value?
<p>I have a custom class, for example's sake let's say it's tuples without order.</p>

<pre><code>public class UnorderedTuple {  
    Integer i1 = null; Integer i2 = null;

    UnorderedTuple(Integer int1, Integer int2) { i1 = int1; i2 = int2; }

    boolean equals(UnorderedTuple t) { return t.i1 == i1 &amp;&amp; t.i2 == t2 || t.i2 == i1 &amp;&amp; t.i1 == i2; }
}
</code></pre>

<p>Like I said, a dumb example. Now, let's say i have</p>

<pre><code>Map&lt;UnorderedTuple, Integer&gt; m = new HashMap&lt;UnorderedTuple, Integer&gt;();
</code></pre>

<p>Ideally, I'd like this functionality:</p>

<pre><code>UnorderedTuple ut1 = new UnorderedTuple(1,2);
UnorderedTuple ut2 = new UnorderedTuple(2,1);

m.put(ut1,2);
m.put(ut2,3);
System.out.println(m.get(ut1)==3); //ideally returns true
</code></pre>

<p>Is there something I need to implement or extend such that I can have this functionality? In the same way that if you use 2 different, but equal strings, or Integers, or whatever as a key it will map it properly, but if I implement this as written, it treats ut1 and ut2 separately. Even if I construct ut1 and ut2 identically, it does the same thing.</p>

<p>Thanks for your help.</p>
