I havent yet looked at the entire code, but i believe the reason why the contains method is returning false, has to do with the logic present in the equals and the hashcode method:
Originally posted by kwame Iwegbue:
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Patient)) return false;
final Patient patient = (Patient) o;
return getDemographics()
.getLastname()
.equals(patient.getDemographics().getLastname());
}
public int hashCode() {
int result;
result = (getDemographics() != null ? getDemographics().hashCode() : 0);
result = 29 * result + (user != null ? user.hashCode() : 0);
return result;
}
Can you try printing out the hashcode values for each of the patient objects in
u.getPatients()
and also the hashcode of the patient that you are checking for:
Patient patient = patientDAO .findById(getDelete_id(), true);
This will help you to figure out whether the logic involved in the equals or the hashcode method is not right