equals and hashCode
Hi,
I have this class,
publicclass ReceitaEstadoVO{
private String regiao;
private Date data;
privatedouble valor;
publicboolean equals(Object obj){
boolean result =false;
if(objinstanceof ReceitaEstadoVO){
ReceitaEstadoVO receitaEstado = (ReceitaEstadoVO)obj;
if((receitaEstado.getData().compareTo(this.data) == 0) && receitaEstado.getRegiao().equals(this.regiao))
result =true;
}
return result;
}
publicint hashCode(){
int result = 17;
result = 37*result + regiao.hashCode();
result = 37*result + data.hashCode();
return result;
}
}
so, two objects are equals if they have the same Date and region. My doubt is if thisif((receitaEstado.getData().compareTo(this.data) == 0)
is a correct way to compare Dates and
result = 37*result + data.hashCode();
is the correct way to incorporate the date in the hashCode?
Thanks in advance,
Manuel Leiria

