Ejemplo n.º 1
0
  /**
   * Returns the group that is parent of the specified mockContact or null if no parent was found.
   *
   * @param mockContact the contact whose parent we're looking for.
   * @return the MockContactGroup instance that mockContact belongs to or null if no parent was
   *     found.
   */
  public MockContactGroup findContactParent(MockContact mockContact) {
    if (contacts.contains(mockContact)) return this;

    Iterator<ContactGroup> subGroupsIter = subgroups();
    while (subGroupsIter.hasNext()) {
      MockContactGroup subgroup = (MockContactGroup) subGroupsIter.next();

      MockContactGroup parent = subgroup.findContactParent(mockContact);
      if (parent != null) return parent;
    }
    return null;
  }
Ejemplo n.º 2
0
  /**
   * Returns the contact with the specified id or null if no such contact exists.
   *
   * @param id the id of the contact we're looking for.
   * @return MockContact
   */
  public MockContact findContactByID(String id) {
    // first go through the contacts that are direct children.
    Iterator<Contact> contactsIter = contacts();

    while (contactsIter.hasNext()) {
      MockContact mContact = (MockContact) contactsIter.next();

      if (mContact.getAddress().equals(id)) return mContact;
    }

    // if we didn't find it here, let's try in the subougroups
    Iterator<ContactGroup> groupsIter = subgroups();

    while (groupsIter.hasNext()) {
      MockContactGroup mGroup = (MockContactGroup) groupsIter.next();
      MockContact mContact = mGroup.findContactByID(id);

      if (mContact != null) return mContact;
    }

    return null;
  }
Ejemplo n.º 3
0
  /**
   * 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;
  }
Ejemplo n.º 4
0
 /**
  * Removes the specified contact group from the this group's subgroups.
  *
  * @param subgroup the MockContactGroup subgroup to remove.
  */
 public void removeSubGroup(MockContactGroup subgroup) {
   this.subGroups.remove(subgroup);
   subgroup.setParentGroup(null);
 }
Ejemplo n.º 5
0
 /**
  * Adds the specified contact group to the contained by this group.
  *
  * @param subgroup the MockContactGroup to add as a subgroup to this group.
  */
 public void addSubgroup(MockContactGroup subgroup) {
   this.subGroups.add(subgroup);
   subgroup.setParentGroup(this);
 }