/** * Indicates whether some other object is "equal to" this one which in terms of contact groups * translates to having the equal names and matching subgroups and child contacts. The resolved * status of contactgroups and contacts is deliberately ignored so that groups and/or contacts * would be assumed equal even if it differs. * * <p> * * @param obj the reference object with which to compare. * @return <code>true</code> if this contact group has the equal child contacts and subgroups to * those of the <code>obj</code> argument. */ @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof MockContactGroup)) return false; MockContactGroup mockGroup = (MockContactGroup) obj; if (!mockGroup.getGroupName().equals(getGroupName()) || !mockGroup.getUID().equals(getUID()) || mockGroup.countContacts() != countContacts() || mockGroup.countSubgroups() != countSubgroups()) return false; // traverse child contacts Iterator<Contact> theirContacts = mockGroup.contacts(); while (theirContacts.hasNext()) { MockContact theirContact = (MockContact) theirContacts.next(); MockContact ourContact = (MockContact) getContact(theirContact.getAddress()); if (ourContact == null || !ourContact.equals(theirContact)) return false; } // traverse subgroups Iterator<ContactGroup> theirSubgroups = mockGroup.subgroups(); while (theirSubgroups.hasNext()) { MockContactGroup theirSubgroup = (MockContactGroup) theirSubgroups.next(); MockContactGroup ourSubgroup = (MockContactGroup) getGroup(theirSubgroup.getGroupName()); if (ourSubgroup == null || !ourSubgroup.equals(theirSubgroup)) return false; } return true; }