added an indexOf method in groups

cusax-fix
Emil Ivov 20 years ago
parent 1a491dc1c9
commit a6b8156be4

@ -123,6 +123,58 @@ public MetaContact getMetaContact(String metaContactID)
return null;
}
/**
* Returns the index of metaContact according to other contacts in this or
* -1 if metaContact does not belong to this group. The returned index is
* only valid until another contact has been added / removed or a contact
* has changed its status and hence - position. In such a case a REORDERED
* event is fired.
*
* @param metaContact the <tt>MetaContact</tt> whose index we're looking
* for.
* @return the index of <tt>metaContact</tt> in the list of child contacts
* or -1 if <tt>metaContact</tt>.
*/
public int indexOf(MetaContact metaContact)
{
int i = 0;
synchronized (childContacts)
{
Iterator childrenIter = childContacts.iterator();
while (childrenIter.hasNext())
{
MetaContact current = (MetaContact) childrenIter.next();
if (current == metaContact)
{
return i;
}
i++;
}
}
//if we got here then metaContact is not in this list
return -1;
}
/**
* Returns the index of metaContactGroup in relation to other subgroups in
* this group or -1 if metaContact does not belong to this group. The
* returned index is only valid until another group has been added /
* removed or renamed In such a case a REORDERED event is fired.
*
* @param metaContactGroup the <tt>MetaContactGroup</tt> whose index we're
* looking for.
* @return the index of <tt>metaContactGroup</tt> in the list of child
* contacts or -1 if <tt>metaContact</tt>.
*/
public int indexOf(MetaContactGroup metaContactGroup)
{
return subgroups.indexOf(metaContactGroup);
}
/**
* Returns the meta contact encapsulating a contact belonging to the
* specified <tt>provider</tt> with the specified identifier.

@ -201,7 +201,7 @@ public int compareTo(Object o)
return (totalStatus - target.totalStatus) * 1000000
+ getDisplayName().compareTo(target.getDisplayName()) * 100000
+ getMetaUID().compareTo(target.getMetaUID());
+ getMetaUID().compareToIgnoreCase(target.getMetaUID());
}
/**
@ -272,25 +272,41 @@ void addProtoContact(Contact contact)
}
/**
* Called by MetaContact after a contact has chaned its status, so that the
* totalStatus field remains up to date.
*
* @return returns the reevaluated presence status index of this meta
* contact.
* Called by MetaContactListServiceImpl after a contact has changed its
* status, so that ordering in the parent group is updated.
*/
int reevalTotalStatus()
void reevalContact()
{
int totalStatus = 0;
synchronized (parentGroupModLock)
{
int totalStatus = 0;
//first lightremove or otherwise we won't be able to get hold of the
//contact
if (parentGroup != null)
{
parentGroup.lightRemoveMetaContact(this);
}
Iterator protoContacts = this.protoContacts.iterator();
Iterator protoContacts = this.protoContacts.iterator();
while (protoContacts.hasNext())
totalStatus += ((Contact)protoContacts.next()).getPresenceStatus()
.getStatus();
while (protoContacts.hasNext())
totalStatus += ( (Contact) protoContacts.next()).
getPresenceStatus()
.getStatus();
return totalStatus;
//now readd it and the contact would be automatically placed
//properly by the containing group
if (parentGroup != null)
{
parentGroup.lightAddMetaContact(this);
}
}
}
/**
* Removes the specified protocol specific contact from the contacts
* encapsulated in this <code>MetaContact</code>. The method also updates

@ -164,6 +164,34 @@ public MetaContact getMetaContact(ProtocolProviderService provider,
*/
public MetaContact getMetaContact(String metaUID);
/**
* Returns the index of metaContact in relation to other contacts in this or
* -1 if metaContact does not belong to this group. The returned index is
* only valid until another contact has been added / removed or a contact
* has changed its status and hence - position. In such a case a REORDERED
* event is fired.
*
* @param metaContact the <tt>MetaContact</tt> whose index we're looking
* for.
* @return the index of <tt>metaContact</tt> in the list of child contacts
* or -1 if <tt>metaContact</tt>.
*/
public int indexOf(MetaContact metaContact);
/**
* Returns the index of metaContactGroup in relation to other subgroups in
* this group or -1 if metaContact does not belong to this group. The
* returned index is only valid until another group has been added /
* removed or renamed In such a case a REORDERED event is fired.
*
* @param metaContactGroup the <tt>MetaContactGroup</tt> whose index we're
* looking for.
* @return the index of <tt>metaContactGroup</tt> in the list of child
* contacts or -1 if <tt>metaContact</tt>.
*/
public int indexOf(MetaContactGroup metaContactGroup);
/**
* Returns the meta contact on the specified index.
* @param index the index of the meta contact to return.

@ -332,4 +332,41 @@ public void testGetSubgroups()
//i don't think we could test anything else here without becoming
//redundant with TestMetaContactList
}
/**
* Goes over the contacts in one of the groups and verifies that indexOf
* returns properly for every one of them.
*/
public void testIndexOf1()
{
MetaContactGroup metaContactGroup = fixture.metaClService
.findMetaContactGroupByContactGroup(MetaContactListServiceLick
.topLevelMockGroup);
for ( int i = 0; i < metaContactGroup.countChildContacts(); i++)
{
MetaContact currentMetaContact = metaContactGroup.getMetaContact(i);
assertEquals("indexOf failed for " + currentMetaContact
, i, metaContactGroup.indexOf(currentMetaContact));
}
}
/**
* Goes over the subgroups in one the root group and verifies that indexOf
* returns properly for every one of them
*/
public void testIndexOf2()
{
MetaContactGroup metaContactGroup = fixture.metaClService.getRoot();
for ( int i = 0; i < metaContactGroup.countSubgroups(); i++)
{
MetaContactGroup currentMetaContactGroup
= metaContactGroup.getMetaContactSubgroup(i);
assertEquals("indexOf failed for " + currentMetaContactGroup
, i, metaContactGroup.indexOf(currentMetaContactGroup));
}
}
}

Loading…
Cancel
Save