From f6c0d481a6bfe13c2373f92159735becae798cfb Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Tue, 10 Oct 2006 15:55:52 +0000 Subject: [PATCH] indexOf takes an Object now --- .../main/contactlist/ContactListModel.java | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java index 4876253b0..b60d6ae59 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListModel.java @@ -183,13 +183,32 @@ public ImageIcon getMetaContactStatusIcon(MetaContact contact) { .getMetaContactStatus(contact))); } + /** + * If the given object is instance of MetaContact or MetaContactGroup + * returns the index of this meta contact or group, otherwiser returns -1. + * @param o the object, which index we search + * @return the index of the given object if it founds it, otherwise -1 + */ + public int indexOf(Object o) + { + if(o instanceof MetaContact){ + return this.indexOf((MetaContact)o); + } + else if(o instanceof MetaContactGroup){ + return this.indexOf((MetaContactGroup)o); + } + else { + return -1; + } + } + /** * Returns the index of the given MetaContact. * * @param contact The MetaContact to search for. * @return The index of the given MetaContact. */ - public int indexOf(MetaContact contact) { + private int indexOf(MetaContact contact) { int index = -1; @@ -216,7 +235,7 @@ public int indexOf(MetaContact contact) { * @param group The given MetaContactGroup to search for. * @return The index of the given MetaContactGroup. */ - public int indexOf(MetaContactGroup group) { + private int indexOf(MetaContactGroup group) { int index = -1; int currentIndex = 0; @@ -227,7 +246,7 @@ public int indexOf(MetaContactGroup group) { currentIndex += this.indexOf(parentGroup); - currentIndex += countDirectChildContacts(parentGroup); + currentIndex += countChildContacts(parentGroup); currentIndex += parentGroup.indexOf(group) + 1; @@ -277,33 +296,6 @@ public int countContactsAndSubgroups(MetaContactGroup parentGroup) { } return count; } - - /** - * Returns the number of all child contacts of the given - * MetaContactGroup. - * - * @param parentGroup The parent MetaContactGroup. - * @return The number of all children of the given MetaContactGroup - */ - public int countDirectChildContacts(MetaContactGroup parentGroup) { - - int count = 0; - - if (parentGroup != null && !this.isGroupClosed(parentGroup)) { - if (showOffline) { - count = parentGroup.countChildContacts(); - } - else { - Iterator i = parentGroup.getChildContacts(); - while (i.hasNext()) { - MetaContact contact = (MetaContact) i.next(); - if (isContactOnline(contact)) - count++; - } - } - } - return count; - } /** * Recursively searches the given group in depth for the element at the