/** * Convenience method to add the <code>name</code> to this person's name list if the name * doesn't exist already. * * @param name */ public void addName(PersonName name) { if (name != null) { name.setPerson(this); if (names == null) { names = new TreeSet<>(); } if (!OpenmrsUtil.collectionContains(names, name)) { names.add(name); } } }
/** * Convenience method to add the <code>address</code> to this person's address list if the * address doesn't exist already. * * @param address * @should not add a person address with blank fields */ public void addAddress(PersonAddress address) { if (address != null) { address.setPerson(this); if (addresses == null) { addresses = new TreeSet<>(); } if (!OpenmrsUtil.collectionContains(addresses, address) && !address.isBlank()) { addresses.add(address); } } }
if (!OpenmrsUtil.collectionContains(attributes, newAttribute) && !newIsNull) { attributes.add(newAttribute);
/** * test the collection contains method * * @see OpenmrsUtil#collectionContains(Collection,Object) */ @Test public void collectionContains_shouldUseEqualsMethodForComparisonInsteadOfCompareToGivenListCollection() { ArrayList<PatientIdentifier> identifiers = new ArrayList<>(); PatientIdentifier pi = new PatientIdentifier(); pi.setIdentifier("123"); pi.setIdentifierType(new PatientIdentifierType(1)); pi.setDateCreated(new Date()); pi.setCreator(new User(1)); identifiers.add(pi); // sanity check identifiers.add(pi); assertFalse("Lists should accept more than one object", identifiers.size() == 1); pi.setDateCreated(null); pi.setCreator(null); assertTrue("Just because the date is null, doesn't make it not in the list anymore", OpenmrsUtil.collectionContains( identifiers, pi)); }
/** * test the collection contains method * * @see OpenmrsUtil#collectionContains(Collection,Object) */ @Test public void collectionContains_shouldUseEqualsMethodForComparisonInsteadOfCompareToGivenSortedSetCollection() { SortedSet<PatientIdentifier> identifiers = new TreeSet<>(); PatientIdentifier pi = new PatientIdentifier(); pi.setIdentifier("123"); pi.setIdentifierType(new PatientIdentifierType(1)); pi.setDateCreated(new Date()); pi.setCreator(new User(1)); identifiers.add(pi); // sanity check identifiers.add(pi); assertTrue("There should still be only 1 identifier in the patient object now", identifiers.size() == 1); pi.setDateCreated(null); pi.setCreator(null); assertTrue("Just because the date is null, doesn't make it not in the list anymore", OpenmrsUtil.collectionContains( identifiers, pi)); }