public void addAttribute(HrStaffAttribute newAttribute) { newAttribute.setHrStaff(this); boolean newIsNull = !StringUtils.hasText(newAttribute.getValue()); for (HrStaffAttribute currentAttribute : getActiveAttributes()) { if (currentAttribute.equals(newAttribute)) return; // if we have the same HrStaffAttributeId, don't add the new attribute else if (currentAttribute .getHrStaffAttributeType() .equals(newAttribute.getHrStaffAttributeType())) { if (currentAttribute.getValue() != null && currentAttribute.getValue().equals(newAttribute.getValue())) // this staff already has this attribute return; // if the to-be-added attribute isn't already voided itself // and if we have the same type, different value if (newAttribute.isVoided() == false || newIsNull) { if (currentAttribute.getCreator() != null) currentAttribute.voidAttribute("New value: " + newAttribute.getValue()); else // remove the attribute if it was just temporary (didn't have a creator // attached to it yet) removeAttribute(currentAttribute); } } } if (!OpenmrsUtil.collectionContains(hrStaffAttributes, newAttribute) && !newIsNull) hrStaffAttributes.add(newAttribute); }