Implements (poor) hashCode() for CandidatePair and Candidate so they may at least be added to HashMap.

This commit is contained in:
Lyubomir Marinov 2016-03-24 11:51:49 -05:00
parent 8230c3d69f
commit eb0e3d3fb8
2 changed files with 28 additions and 0 deletions

View File

@ -341,6 +341,20 @@ public abstract class Candidate<T extends Candidate<?>>
&& getFoundation().equals(candidate.getFoundation());
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
// Even if the following hashCode algorithm has drawbacks because of it
// simplicity, it is better than nothing because at least it allows
// Candidate and, respectively, CandidatePair to be used as HashMap
// keys.
return
getParentComponent().hashCode() + getTransportAddress().hashCode();
}
/**
* Returns a reference to the <tt>Component</tt> that this candidate belongs
* to.

View File

@ -456,6 +456,20 @@ public class CandidatePair
&& remoteCandidate.equals(candidatePair.remoteCandidate);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
// Even if the following hashCode algorithm has drawbacks because of it
// simplicity, it is better than nothing because at least it allows
// CandidatePair to be used as a HashMap key.
// XXX While localCandidate is not final, the parentComponent is
// supposedly effectively final.
return getLocalCandidate().getParentComponent().hashCode();
}
/**
* Returns a String representation of this <tt>CandidatePair</tt>.
*