A BigInteter is too big to be converted into an integer. But I have to store objects with an id (SHA 512) in a HashMap and need a hash function without many collisions.
I tried this. however, I am not sure if there is no clustering somewhere.
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Advertisement other = (Advertisement) obj;
return this.getId().equals(other.getId());
}
@Override
public int hashCode() {
return new BigInteger(getId(), 16).hashCode();
}
would be a cast to an integer (bi.intValue()) more efficient?