diff options
author | Emil Ivov <emcho@jitsi.org> | 2009-04-24 18:57:44 +0000 |
---|---|---|
committer | Emil Ivov <emcho@jitsi.org> | 2009-04-24 18:57:44 +0000 |
commit | 6c2c4e338a5f6e868a2d0b2a28f4caad9e54f289 (patch) | |
tree | f6003cc1c7c09d30fdbf65fbef54ed29176f2466 /src/net/java/sip | |
parent | 92735bce739fea6d02d681e868f372d7c5e46ac1 (diff) | |
download | jitsi-6c2c4e338a5f6e868a2d0b2a28f4caad9e54f289.zip jitsi-6c2c4e338a5f6e868a2d0b2a28f4caad9e54f289.tar.gz jitsi-6c2c4e338a5f6e868a2d0b2a28f4caad9e54f289.tar.bz2 |
Masks duplicate contacts behind the protocol providers and thus addresses issue #657 ICQ/AIM, MSN, and XMPP report multiple parent groups for a single contact
This commit also removes the Contact.getContact(int) method so that contacts could be easily stored in hashmaps in order to optimize search operantions that allow avoiding contact duplicity.
Fixes some raw type warnings.
Diffstat (limited to 'src/net/java/sip')
21 files changed, 423 insertions, 628 deletions
diff --git a/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java b/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java index bd8b07c..7ef6fe9 100644 --- a/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java +++ b/src/net/java/sip/communicator/impl/contactlist/MclStorageManager.java @@ -38,7 +38,7 @@ import net.java.sip.communicator.util.xml.XMLUtils; * provider. Unresolved proto groups and contacts will be created for every one * of them. * <p> - * + * * @author Emil Ivov */ public class MclStorageManager @@ -220,7 +220,7 @@ public class MclStorageManager * Determines whether the storage manager has been properly started or in * other words that it has successfully found and read the xml contact list * file. - * + * * @return true if the storage manager has been successfully initialized and * false otherwise. */ @@ -245,7 +245,7 @@ public class MclStorageManager /** * Initializes the storage manager and makes it do initial load and parsing * of the contact list file. - * + * * @param bc a reference to the currently valid OSGI <tt>BundleContext</tt> * @param mclServImpl a reference to the currently valid instance of the * <tt>MetaContactListServiceImpl</tt> that we could use to pass @@ -370,7 +370,7 @@ public class MclStorageManager /** * Stores the contact list in its current state. - * + * * @throws IOException if writing fails. */ private void scheduleContactListStorage() throws IOException @@ -387,7 +387,7 @@ public class MclStorageManager /** * Writes the contact list on the hard disk. - * + * * @throws IOException in case writing fails. */ private void storeContactList0() throws IOException @@ -468,7 +468,7 @@ public class MclStorageManager /** * Returns the object that we use to lock when writing the contact list. - * + * * @return the object that we use to lock when writing the contact list. */ public Object getContactListRWLock() @@ -508,7 +508,7 @@ public class MclStorageManager /** * update persistent data in the dom object model for the given metacontact * and its contacts - * + * * @param metaContact MetaContact target meta contact */ private void updatePersistentDataForMetaContact(MetaContact metaContact) @@ -554,7 +554,7 @@ public class MclStorageManager /** * Fills the document with the tags necessary for it to be filled properly * as the meta contact list evolves. - * + * * @param mclServImpl the meta contact list service to use when * initializing the document. * @param contactListDoc the document to init. @@ -578,7 +578,7 @@ public class MclStorageManager * belonging to <tt>mclServiceImpl</tt> for every meta contact and meta * contact group stored in the (contactlist.xml) file that correspond to a * provider caring the specified <tt>accountID</tt>. - * + * * @param accountID the identifier of the account whose contacts we're * interested in. * @throws XMLException if a problem occurs while parsing contact list @@ -651,7 +651,7 @@ public class MclStorageManager * Parses <tt>groupNode</tt> and all of its subnodes, creating corresponding * instances through <tt>mclServiceImpl</tt> as children of * <tt>parentGroup</tt> - * + * * @param mclServImpl the <tt>MetaContactListServiceImpl</tt> for * creating new contacts and groups. * @param accountID a String identifier of the account whose contacts we're @@ -922,7 +922,7 @@ public class MclStorageManager * contain proto contacts originating from the specified account, an empty * list is returned. * <p> - * + * * @param metaContactNode the Element whose proto contacts we'd like to * extract. * @param accountID the id of the account whose contacts we're interested @@ -993,7 +993,7 @@ public class MclStorageManager /** * Creates a node element corresponding to <tt>protoContact</tt>. - * + * * @param protoContact the Contact whose element we'd like to create * @return a XML Element corresponding to <tt>protoContact</tt>. */ @@ -1029,7 +1029,7 @@ public class MclStorageManager /** * Creates a node element corresponding to <tt>protoGroup</tt>. - * + * * @param protoGroup the ContactGroup whose element we'd like to create * @return a XML Element corresponding to <tt>protoGroup</tt>. */ @@ -1065,8 +1065,8 @@ public class MclStorageManager /** * Creates a meta contact node element corresponding to <tt>metaContact</tt> * . - * - * + * + * * @param metaContact the MetaContact that the new node is about * @return the XML Element containing the persistent version of * <tt>metaContact</tt> @@ -1104,7 +1104,7 @@ public class MclStorageManager /** * Creates a meta contact group node element corresponding to * <tt>metaGroup</tt>. - * + * * @param metaGroup the MetaContactGroup that the new node is about * @return the XML Element containing the persistent version of * <tt>metaGroup</tt> @@ -1174,7 +1174,7 @@ public class MclStorageManager /** * Indicates that a MetaContact has been successfully added to the * MetaContact list. - * + * * @param evt the MetaContactListEvent containing the corresponding contact */ public void metaContactAdded(MetaContactEvent evt) @@ -1188,6 +1188,10 @@ public class MclStorageManager { logger.error("Couldn't find parent of a newly added contact: " + evt.getSourceMetaContact()); + if(logger.isTraceEnabled()) + logger.trace("The above exception occurred with the " + + "following stack trace: ", + new Exception()); return; } @@ -1219,7 +1223,7 @@ public class MclStorageManager * Creates XML nodes for the source metacontact group, its child meta * contacts and associated protogroups and adds them to the xml contact * list. - * + * * @param evt the MetaContactListEvent containing the corresponding contact */ public void metaContactGroupAdded(MetaContactGroupEvent evt) @@ -1271,7 +1275,7 @@ public class MclStorageManager /** * Removes the corresponding node from the xml document. - * + * * @param evt the MetaContactGroupEvent containing the corresponding contact */ public void metaContactGroupRemoved(MetaContactGroupEvent evt) @@ -1311,7 +1315,7 @@ public class MclStorageManager /** * Moves the corresponding node from its old parent to the node * corresponding to the new parent meta group. - * + * * @param evt the MetaContactListEvent containing the corresponding contact */ public void metaContactMoved(MetaContactMovedEvent evt) @@ -1325,6 +1329,10 @@ public class MclStorageManager { logger.error("Save after metacontact moved. new parent not found: " + evt.getNewParent()); + if(logger.isTraceEnabled()) + logger.error("The above exception has occurred with the " + +"following stack trace", + new Exception()); return; } @@ -1369,7 +1377,7 @@ public class MclStorageManager * updates theirs parent proto group uid-s to point to the first contact * group that is encapsulated by the newParent meta group and that belongs * to the same account as the contact itself. - * + * * @param metaContactNode the meta contact node whose child contacts we're * to update. * @param newParent a reference to the <tt>MetaContactGroup</tt> where @@ -1413,7 +1421,7 @@ public class MclStorageManager /** * Removes the corresponding node from the xml document. - * + * * @param evt the MetaContactListEvent containing the corresponding contact */ public void metaContactRemoved(MetaContactEvent evt) @@ -1451,7 +1459,7 @@ public class MclStorageManager /** * Changes the display name attribute of the specified meta contact node. - * + * * @param evt the MetaContactListEvent containing the corresponding contact */ public void metaContactRenamed(MetaContactRenamedEvent evt) @@ -1494,7 +1502,7 @@ public class MclStorageManager /** * Updates the data stored for the contact that caused this event. - * + * * @param evt the MetaContactListEvent containing the corresponding contact */ public void protoContactModified(ProtoContactEvent evt) @@ -1534,7 +1542,7 @@ public class MclStorageManager /** * Indicates that a MetaContact has been modified. - * + * * @param evt the MetaContactModifiedEvent containing the corresponding * contact */ @@ -1680,7 +1688,7 @@ public class MclStorageManager /** * Removes the corresponding node from the xml contact list. - * + * * @param evt a reference to the corresponding <tt>ProtoContactEvent</tt> */ public void protoContactRemoved(ProtoContactEvent evt) @@ -1722,7 +1730,7 @@ public class MclStorageManager /** * We simply ignore - we're not interested in this kind of events. - * + * * @param evt the <tt>MetaContactGroupEvent</tt> containing details of this * event. */ @@ -1734,7 +1742,7 @@ public class MclStorageManager /** * Determines the exact type of the change and acts accordingly by either * updating group name or . - * + * * @param evt the MetaContactListEvent containing the corresponding contact */ public void metaContactGroupModified(MetaContactGroupEvent evt) @@ -1749,6 +1757,10 @@ public class MclStorageManager { logger.error("Failed to find meta contact group: " + evt.getSourceMetaContactGroup()); + if(logger.isTraceEnabled()) + logger.trace("The above error occurred with the following " + +"stack trace: ", + new Exception()); return; } @@ -1816,7 +1828,7 @@ public class MclStorageManager * Indicates that a protocol specific <tt>Contact</tt> instance has been * added to the list of protocol specific buddies in this * <tt>MetaContact</tt> - * + * * @param evt a reference to the corresponding <tt>ProtoContactEvent</tt> */ public void protoContactAdded(ProtoContactEvent evt) @@ -1855,7 +1867,7 @@ public class MclStorageManager /** * Indicates that a protocol specific <tt>Contact</tt> instance has been * moved from within one <tt>MetaContact</tt> to another. - * + * * @param evt a reference to the <tt>ProtoContactMovedEvent</tt> instance. */ public void protoContactMoved(ProtoContactEvent evt) @@ -1912,7 +1924,7 @@ public class MclStorageManager /** * Returns the node corresponding to the meta contact with the specified uid * or null if no such node was found. - * + * * @param metaContactUID the UID String of the meta contact whose node we * are looking for. * @return the node corresponding to the meta contact with the specified UID @@ -1930,7 +1942,7 @@ public class MclStorageManager /** * Returns the node corresponding to the meta contact with the specified uid * or null if no such node was found. - * + * * @param metaContactGroupUID the UID String of the meta contact whose node * we are looking for. * @return the node corresponding to the meta contact group with the @@ -1975,7 +1987,7 @@ public class MclStorageManager /** * Returns a string representation of the descriptor. - * + * * @return a string representation of the descriptor. */ public String toString() @@ -1995,7 +2007,7 @@ public class MclStorageManager * Utility method that allows us to verify whether a ContactDescriptor * corresponding to a particular contact is already in a descriptor list * and thus eliminate duplicates. - * + * * @param contactAddress the address of the contact whose descriptor we * are looking for. * @param list the <tt>List</tt> of diff --git a/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java b/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java index abe2849..19a743f 100644 --- a/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java +++ b/src/net/java/sip/communicator/impl/contactlist/MetaContactListServiceImpl.java @@ -994,7 +994,7 @@ public class MetaContactListServiceImpl { /** @todo handle non persistent presence operation sets */ } - else + else { opSetPresence.moveContactToGroup(protoContact, protoGroup); } diff --git a/src/net/java/sip/communicator/impl/protocol/dict/ContactGroupDictImpl.java b/src/net/java/sip/communicator/impl/protocol/dict/ContactGroupDictImpl.java index 4b6bb94..0261322 100644 --- a/src/net/java/sip/communicator/impl/protocol/dict/ContactGroupDictImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/dict/ContactGroupDictImpl.java @@ -194,18 +194,6 @@ public class ContactGroupDictImpl subgroup.setParentGroup(null); } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return contacts.get(index); - } - /** * Returns the group that is parent of the specified dictGroup or null * if no parent was found. diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/ContactGroupGibberishImpl.java b/src/net/java/sip/communicator/impl/protocol/gibberish/ContactGroupGibberishImpl.java index 475ceb7..f7ee909 100644 --- a/src/net/java/sip/communicator/impl/protocol/gibberish/ContactGroupGibberishImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/ContactGroupGibberishImpl.java @@ -193,18 +193,6 @@ public class ContactGroupGibberishImpl subgroup.setParentGroup(null); } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (ContactGibberishImpl)contacts.get(index); - } - /** * Returns the group that is parent of the specified gibberishGroup or null * if no parent was found. diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ContactGroupIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ContactGroupIcqImpl.java index d217144..f8d2db4 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ContactGroupIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ContactGroupIcqImpl.java @@ -27,7 +27,15 @@ import net.kano.joustsim.oscar.oscar.service.ssi.*; public class ContactGroupIcqImpl extends AbstractContactGroupIcqImpl { - private List buddies = new LinkedList(); + /** + * Maps all UINs/Screenname-s to the actual contacts so that we could easily + * search the set of existing contacts. Note that we only store lowercase + * strings in the left column because screen names in AIM/ICQ are not case + * sensitive. + */ + private Map<String, ContactIcqImpl> buddies + = new Hashtable<String, ContactIcqImpl>(); + private boolean isResolved = false; /** @@ -39,7 +47,8 @@ public class ContactGroupIcqImpl * a list that would always remain empty. We only use it so that we're able * to extract empty iterators */ - private List dummyGroupsList = new LinkedList(); + private LinkedHashSet<ContactGroupIcqImpl> dummyGroupsList + = new LinkedHashSet<ContactGroupIcqImpl>(); /** * A variable that we use as a means of detecting changes in the name @@ -70,7 +79,7 @@ public class ContactGroupIcqImpl * resolved against the server. */ ContactGroupIcqImpl(MutableGroup joustSimGroup, - List groupMembers, + List<Buddy> groupMembers, ServerStoredContactListIcqImpl ssclCallback, boolean isResolved) { @@ -86,12 +95,22 @@ public class ContactGroupIcqImpl //their real addresses and we can only get a list of copies from the //group itself. - for (int i = 0; i < groupMembers.size(); i++) + Iterator<Buddy> buddies = groupMembers.iterator(); + while(buddies.hasNext()) { + Buddy buddy = buddies.next(); + //only add the buddy if it doesn't already exist in some other group + //this is necessary because AIM would allow having one and the + //same buddy in more than one group. + if(ssclCallback.findContactByJoustSimBuddy(buddy) != null) + { + continue; + } + // here we are not checking for AwaitingAuthorization buddies // as we are creating group with list of buddies // these checks must have been made already - addContact( new ContactIcqImpl((Buddy)groupMembers.get(i), + addContact( new ContactIcqImpl(buddy, ssclCallback, true, true) ); } } @@ -119,22 +138,12 @@ public class ContactGroupIcqImpl } /** - * Adds the specified contact at the specified position. - * @param contact the new contact to add to this group - * @param index the position where the new contact should be added. - */ - void addContact(int index, ContactIcqImpl contact) - { - buddies.add(index, contact); - } - - /** * Adds the specified contact to the end of this group. * @param contact the new contact to add to this group */ void addContact(ContactIcqImpl contact) { - addContact(countContacts(), contact); + buddies.put(contact.getUIN().toLowerCase(), contact); } @@ -144,31 +153,7 @@ public class ContactGroupIcqImpl */ void removeContact(ContactIcqImpl contact) { - removeContact(buddies.indexOf(contact)); - } - - /** - * Removes the contact with the specified index. - * @param index the index of the cntact to remove - */ - void removeContact(int index) - { - buddies.remove(index); - } - - /** - * Removes all buddies in this group and reinsterts them as specified - * by the <tt>newOrder</tt> param. Contacts not contained in the - * newOrder list are left at the end of this group. - * - * @param newOrder a list containing all contacts in the order that is - * to be applied. - * - */ - void reorderContacts(List newOrder) - { - buddies.removeAll(newOrder); - buddies.addAll(0, newOrder); + buddies.remove(contact); } /** @@ -181,24 +166,13 @@ public class ContactGroupIcqImpl */ public Iterator contacts() { - return buddies.iterator(); - } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (ContactIcqImpl) buddies.get(index); + return buddies.values().iterator(); } /** * Returns the <tt>Contact</tt> with the specified address or * identifier. - * @param id the addres or identifier of the <tt>Contact</tt> we are + * @param id the address or identifier of the <tt>Contact</tt> we are * looking for. * @return the <tt>Contact</tt> with the specified id or address. */ @@ -372,29 +346,6 @@ public class ContactGroupIcqImpl } /** - * Returns the index of icq contact encapsulating the specified joustSim - * buddy or -1 if no such buddy was found. - * - * @param joustSimBuddy the buddy whose encapsulating contact's index we're - * looking for. - * @return the index of the contact corresponding to the specified - * joustSimBuddy or null if no such contact was found. - */ - int findContactIndex(Buddy joustSimBuddy) - { - Iterator contacts = contacts(); - int i = 0; - while (contacts.hasNext()) - { - ContactIcqImpl item = (ContactIcqImpl) contacts.next(); - if(item.getJoustSimBuddy() == joustSimBuddy) - return i; - i++; - } - return -1; - } - - /** * Returns the index of contact in this group -1 if no such contact was * found. * @@ -427,19 +378,15 @@ public class ContactGroupIcqImpl */ ContactIcqImpl findContact(String screenName) { - Iterator contacts = contacts(); - while (contacts.hasNext()) - { - ContactIcqImpl item = (ContactIcqImpl) contacts.next(); - if(item.getJoustSimBuddy().getScreenname().getFormatted() - .equalsIgnoreCase(screenName)) - return item; - } - return null; + if(screenName == null) + return null; + + String lcScreenName = screenName.toLowerCase(); + return buddies.get(lcScreenName); } /** - * Sets the name copy field that we use as a means of detecing changes in + * Sets the name copy field that we use as a means of detecting changes in * the group name. */ void initNameCopy() @@ -538,7 +485,7 @@ public class ContactGroupIcqImpl ssclCallback.addAwaitingAuthorizationContact(buddy); continue; } - + ContactIcqImpl contact = findContact(buddy.getScreenname().getFormatted()); diff --git a/src/net/java/sip/communicator/impl/protocol/icq/RootContactGroupIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/RootContactGroupIcqImpl.java index c78b786..3abbc32 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/RootContactGroupIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/RootContactGroupIcqImpl.java @@ -19,13 +19,15 @@ public class RootContactGroupIcqImpl extends AbstractContactGroupIcqImpl { private String ROOT_CONTACT_GROUP_NAME = "ContactListRoot"; - private List subGroups = new LinkedList(); + private List<ContactGroupIcqImpl> subGroups + = new LinkedList<ContactGroupIcqImpl>(); private boolean isResolved = false; /** * An empty list that we use when returning an iterator. */ - private List dummyContacts = new LinkedList(); + private List<ContactIcqImpl> dummyContacts + = new LinkedList<ContactIcqImpl>(); private ProtocolProviderServiceIcqImpl ownerProvider = null; @@ -112,7 +114,7 @@ public class RootContactGroupIcqImpl * to be applied. * */ - void reorderSubGroups(List newOrder) + void reorderSubGroups(List<ContactGroupIcqImpl> newOrder) { subGroups.removeAll(newOrder); subGroups.addAll(0, newOrder); @@ -157,10 +159,10 @@ public class RootContactGroupIcqImpl */ public ContactGroup getGroup(String groupName) { - Iterator subgroups = subgroups(); + Iterator<ContactGroupIcqImpl> subgroups = subgroups(); while (subgroups.hasNext()) { - ContactGroupIcqImpl grp = (ContactGroupIcqImpl)subgroups.next(); + ContactGroupIcqImpl grp = subgroups.next(); if (grp.getGroupName().equals(groupName)) return grp; @@ -217,18 +219,6 @@ public class RootContactGroupIcqImpl } /** - * A dummy impl of the corresponding interface method - always returns null. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index, i.e. always - * null. - */ - public Contact getContact(int index) - { - return null; - } - - /** * Returns a string representation of the root contact group that contains * all subgroups and subcontacts of this group. * @@ -239,7 +229,7 @@ public class RootContactGroupIcqImpl StringBuffer buff = new StringBuffer(getGroupName()); buff.append(".subGroups="+countSubgroups()+":\n"); - Iterator subGroups = subgroups(); + Iterator<ContactGroupIcqImpl> subGroups = subgroups(); while (subGroups.hasNext()) { ContactGroup group = (ContactGroup) subGroups.next(); diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java index c647f7f..fe161e3 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java @@ -65,11 +65,6 @@ public class ServerStoredContactListIcqImpl private RootContactGroupIcqImpl rootGroup = new RootContactGroupIcqImpl(); /** - * Listeners that others registered with us for contact list events. - */ - private Vector contactListListeners = new Vector(); - - /** * The joust sim service that deals with server stored information. */ private SsiService jSimSsiService = null; @@ -89,17 +84,25 @@ public class ServerStoredContactListIcqImpl * Listeners that would receive event notifications for changes in group * names or other properties, removal or creation of groups. */ - private Vector serverStoredGroupListeners = new Vector(); + private Vector<ServerStoredGroupListener> serverStoredGroupListeners + = new Vector<ServerStoredGroupListener>(); /** * Used for retrieveing missing nicks on specified contacts */ private NickRetriever nickRetriever = null; - + /** * Used for retrieveing missing nicks on specified contacts */ - static String awaitingAuthorizationGroupName = new String("Awaiting authorization"); + static String awaitingAuthorizationGroupName + = new String("Awaiting authorization"); + + /** + * A map containing all contacts currently + */ + private Map<String, String> contactParentsMap + = new Hashtable<String, String>(); /** * Creates a ServerStoredContactList wrapper for the specified BuddyList. @@ -127,7 +130,7 @@ public class ServerStoredContactListIcqImpl if(icqProvider.USING_ICQ) { nickRetriever = new NickRetriever(); - + parentOperationSet.addContactPresenceStatusListener(nickRetriever); // start the nick retreiver thread @@ -196,10 +199,11 @@ public class ServerStoredContactListIcqImpl logger.trace("Will dispatch the following grp event: " + evt); - Iterator listeners = null; + Iterator<ServerStoredGroupListener> listeners = null; synchronized (serverStoredGroupListeners) { - listeners = new ArrayList(serverStoredGroupListeners).iterator(); + listeners = new ArrayList<ServerStoredGroupListener>( + serverStoredGroupListeners).iterator(); } while (listeners.hasNext()) @@ -232,8 +236,7 @@ public class ServerStoredContactListIcqImpl * @param index the index at which it was added. */ private void fireContactAdded( ContactGroupIcqImpl parentGroup, - ContactIcqImpl contact, - int index) + ContactIcqImpl contact) { //bail out if no one's listening if(parentOperationSet == null){ @@ -336,7 +339,7 @@ public class ServerStoredContactListIcqImpl */ public int findContactGroupIndex(Group joustSimGroup) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<Group> contactGroups = rootGroup.subgroups(); int index = 0; for (; contactGroups.hasNext(); index++) @@ -361,12 +364,11 @@ public class ServerStoredContactListIcqImpl */ public ContactGroupIcqImpl findContactGroup(String name) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<ContactGroupIcqImpl> contactGroups = rootGroup.subgroups(); while(contactGroups.hasNext()) { - ContactGroupIcqImpl contactGroup - = (ContactGroupIcqImpl) contactGroups.next(); + ContactGroupIcqImpl contactGroup = contactGroups.next(); if (contactGroup.getGroupName().equals(name)) return contactGroup; @@ -384,12 +386,11 @@ public class ServerStoredContactListIcqImpl */ public ContactGroupIcqImpl findContactGroup(Group joustSimGroup) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<ContactGroupIcqImpl> contactGroups = rootGroup.subgroups(); while(contactGroups.hasNext()) { - ContactGroupIcqImpl contactGroup - = (ContactGroupIcqImpl) contactGroups.next(); + ContactGroupIcqImpl contactGroup = contactGroups.next(); if (joustSimGroup == contactGroup.getJoustSimSourceGroup()) return contactGroup; @@ -408,13 +409,39 @@ public class ServerStoredContactListIcqImpl */ public ContactIcqImpl findContactByScreenName(String screenName) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<ContactGroupIcqImpl> contactGroups = rootGroup.subgroups(); ContactIcqImpl result = null; while(contactGroups.hasNext()) { - ContactGroupIcqImpl contactGroup - = (ContactGroupIcqImpl) contactGroups.next(); + ContactGroupIcqImpl contactGroup = contactGroups.next(); + + result = contactGroup.findContact(screenName); + + if (result != null) + return result; + + } + return null; + } + + /** + * Returns the Contact with the specified screenname (or icq UIN) or null if + * no such screenname was found. + * + * @param screenName the screen name (or ICQ UIN) of the contact to find. + * @return the <tt>Contact</tt> carrying the specified + * <tt>screenName</tt> or <tt>null</tt> if no such contact exits. + */ + public ContactIcqImpl findContactByJoustSimBuddy(Buddy buddy) + { + Iterator<ContactGroupIcqImpl> contactGroups = rootGroup.subgroups(); + String screenName = buddy.getScreenname().getFormatted(); + ContactIcqImpl result = null; + + while(contactGroups.hasNext()) + { + ContactGroupIcqImpl contactGroup = contactGroups.next(); result = contactGroup.findContact(screenName); @@ -437,12 +464,11 @@ public class ServerStoredContactListIcqImpl */ public ContactGroupIcqImpl findContactGroup(ContactIcqImpl child) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<ContactGroupIcqImpl> contactGroups = rootGroup.subgroups(); while(contactGroups.hasNext()) { - ContactGroupIcqImpl contactGroup - = (ContactGroupIcqImpl) contactGroups.next(); + ContactGroupIcqImpl contactGroup = contactGroups.next(); if( contactGroup.findContact(child.getJoustSimBuddy())!= null) return contactGroup; @@ -486,7 +512,7 @@ public class ServerStoredContactListIcqImpl //if the parent group is null then add necessary create the group if (theVolatileGroup == null) { - List emptyBuddies = new LinkedList(); + List<Buddy> emptyBuddies = new LinkedList<Buddy>(); theVolatileGroup = new ContactGroupIcqImpl( new VolatileGroup(), emptyBuddies, this, false); theVolatileGroup.addContact(newVolatileContact); @@ -499,9 +525,7 @@ public class ServerStoredContactListIcqImpl else { theVolatileGroup.addContact(newVolatileContact); - fireContactAdded(theVolatileGroup - , newVolatileContact - , theVolatileGroup.findContactIndex(volatileBuddy)); + fireContactAdded(theVolatileGroup, newVolatileContact); } return newVolatileContact; @@ -533,8 +557,7 @@ public class ServerStoredContactListIcqImpl parentGroup.addContact(newUnresolvedContact); fireContactAdded( parentGroup - , newUnresolvedContact - , parentGroup.findContactIndex(volatileBuddy)); + , newUnresolvedContact); return newUnresolvedContact; } @@ -552,7 +575,7 @@ public class ServerStoredContactListIcqImpl ContactGroupIcqImpl createUnresolvedContactGroup(String groupName) { //First create the new volatile contact; - List emptyBuddies = new LinkedList(); + List<Buddy> emptyBuddies = new LinkedList<Buddy>(); ContactGroupIcqImpl newUnresolvedGroup = new ContactGroupIcqImpl( new VolatileGroup(groupName), emptyBuddies, this, false); @@ -648,7 +671,7 @@ public class ServerStoredContactListIcqImpl { if(contact.isPersistent()) { - List contactsToMove = new ArrayList(); + List<Buddy> contactsToMove = new ArrayList<Buddy>(); contactsToMove.add(contact.getJoustSimBuddy()); @@ -660,8 +683,6 @@ public class ServerStoredContactListIcqImpl // if the contact buddy is volatile // just add the buddy to the new group // if everything is ok. The volatile contact will be reused - ContactGroupIcqImpl oldParent = - (ContactGroupIcqImpl)contact.getParentContactGroup(); addContact(newParent, contact.getUIN()); } @@ -716,7 +737,7 @@ public class ServerStoredContactListIcqImpl ContactGroupIcqImpl gr = (ContactGroupIcqImpl)getRootGroup().getGroup(i); - if(!gr.isPersistent() && + if(!gr.isPersistent() && !gr.getGroupName().equals(awaitingAuthorizationGroupName)) return gr; } @@ -737,32 +758,35 @@ public class ServerStoredContactListIcqImpl if(icqProvider.USING_ICQ) nickRetriever.addContact(c); } - + protected void addAwaitingAuthorizationContact(Buddy buddy) { - //Check whether a Awaiting authorization group already exists and if not create - //one - ContactGroupIcqImpl theAwaitingAuthorizationGroup = + //Check whether a Awaiting authorization group already exists and if + //not create one + ContactGroupIcqImpl theAwaitingAuthorizationGroup = findContactGroup(awaitingAuthorizationGroupName); - + if(theAwaitingAuthorizationGroup == null) { - List emptyBuddies = new LinkedList(); + List<Buddy> emptyBuddies = new LinkedList<Buddy>(); theAwaitingAuthorizationGroup = new ContactGroupIcqImpl( - new VolatileGroup(awaitingAuthorizationGroupName), emptyBuddies, this, false); + new VolatileGroup(awaitingAuthorizationGroupName), + emptyBuddies, + this, + false); this.rootGroup.addSubGroup(theAwaitingAuthorizationGroup); fireGroupEvent(theAwaitingAuthorizationGroup , ServerStoredGroupEvent.GROUP_CREATED_EVENT); - } + } ContactGroupIcqImpl oldParentGroup = null; - ContactIcqImpl newContact - = findContactByScreenName(buddy.getScreenname().getFormatted()); + ContactIcqImpl newContact = findContactByJoustSimBuddy(buddy); if(newContact != null) - oldParentGroup = (ContactGroupIcqImpl)newContact.getParentContactGroup(); + oldParentGroup = (ContactGroupIcqImpl)newContact + .getParentContactGroup(); boolean fireResolvedEvent = false; @@ -774,7 +798,7 @@ public class ServerStoredContactListIcqImpl else { oldParentGroup.removeContact(newContact); - + newContact.setJoustSimBuddy(buddy); newContact.setPersistent(true); if(!newContact.isResolved()) @@ -794,7 +818,7 @@ public class ServerStoredContactListIcqImpl //tell listeners about the added group if(oldParentGroup == null) { - fireContactAdded(theAwaitingAuthorizationGroup, newContact, index); + fireContactAdded(theAwaitingAuthorizationGroup, newContact); } else if(oldParentGroup != theAwaitingAuthorizationGroup) { @@ -808,32 +832,33 @@ public class ServerStoredContactListIcqImpl fireContactResolved(theAwaitingAuthorizationGroup, newContact); } } - + protected void moveAwaitingAuthorizationContact(ContactIcqImpl contact) { ContactGroupIcqImpl parentGroup = findGroup(contact.getJoustSimBuddy()); - + if(parentGroup == null) return; - + findContactGroup(awaitingAuthorizationGroupName).removeContact(contact); parentGroup.addContact(contact); - + fireContactMoved(findContactGroup(awaitingAuthorizationGroupName), parentGroup, contact, parentGroup.findContactIndex(contact)); } - + ContactGroupIcqImpl findGroup(Buddy buddy) { - Iterator iter = rootGroup.subgroups(); + Iterator<ContactGroupIcqImpl> iter = rootGroup.subgroups(); while (iter.hasNext()) { - ContactGroupIcqImpl elem = (ContactGroupIcqImpl) iter.next(); - + ContactGroupIcqImpl elem = iter.next(); + if(!elem.isPersistent() || !elem.isResolved()) continue; - - Iterator bs = elem.getJoustSimSourceGroup().getBuddiesCopy().iterator(); + + Iterator bs = elem.getJoustSimSourceGroup().getBuddiesCopy() + .iterator(); while (bs.hasNext()) { Buddy b = (Buddy) bs.next(); @@ -841,7 +866,7 @@ public class ServerStoredContactListIcqImpl return elem; } } - + return null; } @@ -889,7 +914,8 @@ public class ServerStoredContactListIcqImpl // set it to resolved, do the same with its child buddies, fire // the corresponding events and bail out. List newContacts = new ArrayList(); - List deletedContacts = new ArrayList(); + List<ContactIcqImpl> deletedContacts + = new ArrayList<ContactIcqImpl>(); newGroup.updateGroup((MutableGroup)group, buddies , newContacts, deletedContacts); @@ -898,7 +924,8 @@ public class ServerStoredContactListIcqImpl , ServerStoredGroupEvent.GROUP_RESOLVED_EVENT); //fire events for contacts that have been removed; - Iterator deletedContactsIter = deletedContacts.iterator(); + Iterator<ContactIcqImpl> deletedContactsIter + = deletedContacts.iterator(); while(deletedContactsIter.hasNext()) { ContactIcqImpl contact @@ -907,14 +934,15 @@ public class ServerStoredContactListIcqImpl } //fire events for that contacts have been resolved or added - Iterator contactsIter = newGroup.contacts(); + Iterator<ContactIcqImpl> contactsIter + = newGroup.contacts(); while(contactsIter.hasNext()) { ContactIcqImpl contact = (ContactIcqImpl)contactsIter.next(); if(newContacts.contains(contact)) - fireContactAdded(newGroup, contact, 0); + fireContactAdded(newGroup, contact); else fireContactResolved(newGroup, contact); } @@ -980,8 +1008,7 @@ public class ServerStoredContactListIcqImpl //same contact instance and issue a contact moved event instead of //a contact added event. ContactGroupIcqImpl oldParentGroup = null; - ContactIcqImpl newContact - = findContactByScreenName(buddy.getScreenname().getFormatted()); + ContactIcqImpl newContact = findContactByJoustSimBuddy(buddy); ContactGroupIcqImpl parentGroup = findContactGroup(joustSimGroup); boolean fireResolvedEvent = false; @@ -992,7 +1019,7 @@ public class ServerStoredContactListIcqImpl + joustSimGroup + " found for buddy: " + buddy); return; } - + if(buddy.isAwaitingAuthorization()) { addAwaitingAuthorizationContact(buddy); @@ -1029,7 +1056,7 @@ public class ServerStoredContactListIcqImpl //tell listeners about the added group if(oldParentGroup == null) { - fireContactAdded(parentGroup, newContact, index); + fireContactAdded(parentGroup, newContact); } else if(oldParentGroup != parentGroup) { @@ -1064,18 +1091,18 @@ public class ServerStoredContactListIcqImpl // this buddy is not in this group // it can be in awaiting authorization group // will search it there - - ContactGroupIcqImpl theAwaitingAuthorizationGroup = + + ContactGroupIcqImpl theAwaitingAuthorizationGroup = findContactGroup(awaitingAuthorizationGroupName); if(theAwaitingAuthorizationGroup != null) { - contactToRemove = + contactToRemove = theAwaitingAuthorizationGroup. findContact(buddy.getScreenname().getFormatted()); - + if(contactToRemove == null) return; - + theAwaitingAuthorizationGroup.removeContact(contactToRemove); buddy.removeBuddyListener(jsimBuddyListener); @@ -1106,31 +1133,8 @@ public class ServerStoredContactListIcqImpl public void buddiesReordered(BuddyList list, Group group, List oldBuddies, List newBuddies) { - ContactGroupIcqImpl contactGroup = findContactGroup(group); - - if (contactGroup == null) - { - logger.debug( - "buddies reordered event received for unknown group" - + group); - } - - List reorderedContacts = new ArrayList(); - Iterator newBuddiesIter = newBuddies.iterator(); - while (newBuddiesIter.hasNext()) - { - Buddy buddy = (Buddy) newBuddiesIter.next(); - ContactIcqImpl contact = contactGroup.findContact(buddy); - - //make sure that this was not an empty buddy. - if (contact == null) - continue; - reorderedContacts.add(contact); - } - - contactGroup.reorderContacts(reorderedContacts); - - fireContactsReordered(contactGroup); + //we don't support this any longer. check out SVN archives if + //you need it for some reason. } /** @@ -1147,11 +1151,12 @@ public class ServerStoredContactListIcqImpl public void groupsReordered(BuddyList list, List oldOrder, List newOrder) { - List reorderedGroups = new ArrayList(); - Iterator newOrderIter = newOrder.iterator(); + List<ContactGroupIcqImpl> reorderedGroups + = new ArrayList<ContactGroupIcqImpl>(); + Iterator<Group> newOrderIter = newOrder.iterator(); while (newOrderIter.hasNext()) { - Group group = (Group) newOrderIter.next(); + Group group = newOrderIter.next(); ContactGroupIcqImpl contactGroup = findContactGroup(group); //make sure that this was not an empty buddy. @@ -1352,7 +1357,8 @@ public class ServerStoredContactListIcqImpl /** * list with the accounts with missing nicknames */ - private Vector contactsForUpdate = new Vector(); + private Vector<ContactIcqImpl> contactsForUpdate + = new Vector<ContactIcqImpl>(); private boolean isReadyForRetreive = false; @@ -1360,7 +1366,7 @@ public class ServerStoredContactListIcqImpl { try { - Collection copyContactsForUpdate = null; + Collection<ContactIcqImpl> copyContactsForUpdate = null; while (true) { synchronized(contactsForUpdate){ @@ -1368,11 +1374,13 @@ public class ServerStoredContactListIcqImpl if(contactsForUpdate.isEmpty()) contactsForUpdate.wait(); - copyContactsForUpdate = new Vector(contactsForUpdate); + copyContactsForUpdate + = new Vector<ContactIcqImpl>(contactsForUpdate); contactsForUpdate.clear(); } - Iterator iter = copyContactsForUpdate.iterator(); + Iterator<ContactIcqImpl> iter + = copyContactsForUpdate.iterator(); while (iter.hasNext()) { ContactIcqImpl contact = (ContactIcqImpl) iter.next(); diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ContactGroupJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ContactGroupJabberImpl.java index 21e3f9c..a442fbd 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ContactGroupJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ContactGroupJabberImpl.java @@ -31,7 +31,15 @@ public class ContactGroupJabberImpl extends AbstractContactGroupJabberImpl { - private List buddies = new LinkedList(); + /** + * Maps all JIDs in our roster to the actual contacts so that we could + * easily search the set of existing contacts. Note that we only store + * lower case strings in the left column because JIDs in XMPP are not case + * sensitive. + */ + private Map<String, ContactJabberImpl> buddies + = new Hashtable<String, ContactJabberImpl>(); + private boolean isResolved = false; /** @@ -43,7 +51,8 @@ public class ContactGroupJabberImpl * a list that would always remain empty. We only use it so that we're able * to extract empty iterators */ - private List dummyGroupsList = new LinkedList(); + private List<ContactGroupJabberImpl> dummyGroupsList + = new LinkedList<ContactGroupJabberImpl>(); /** * A variable that we use as a means of detecting changes in the name @@ -73,7 +82,7 @@ public class ContactGroupJabberImpl */ ContactGroupJabberImpl( RosterGroup rosterGroup, - Iterator groupMembers, + Iterator<RosterEntry> groupMembers, ServerStoredContactListJabberImpl ssclCallback, boolean isResolved) { @@ -85,12 +94,21 @@ public class ContactGroupJabberImpl if(rosterGroup != null) this.nameCopy = rosterGroup.getName(); - Iterator iter = groupMembers; + Iterator<RosterEntry> iter = groupMembers; while (iter.hasNext()) { - RosterEntry item = (RosterEntry) iter.next(); + RosterEntry rEntry = iter.next(); - addContact( new ContactJabberImpl(item, ssclCallback, true, true) ); + //only add the buddy if it doesn't already exist in some other group + //this is necessary because XMPP would allow having one and the + //same buddy in more than one group. + if(ssclCallback.findContactById(rEntry.getUser()) != null) + { + continue; + } + + addContact( + new ContactJabberImpl(rEntry, ssclCallback, true, true)); } } @@ -127,22 +145,12 @@ public class ContactGroupJabberImpl } /** - * Adds the specified contact at the specified position. - * @param contact the new contact to add to this group - * @param index the position where the new contact should be added. - */ - void addContact(int index, ContactJabberImpl contact) - { - buddies.add(index, contact); - } - - /** * Adds the specified contact to the end of this group. * @param contact the new contact to add to this group */ void addContact(ContactJabberImpl contact) { - addContact(countContacts(), contact); + buddies.put(contact.getAddress().toLowerCase(), contact); } @@ -152,31 +160,7 @@ public class ContactGroupJabberImpl */ void removeContact(ContactJabberImpl contact) { - removeContact(buddies.indexOf(contact)); - } - - /** - * Removes the contact with the specified index. - * @param index the index of the cntact to remove - */ - void removeContact(int index) - { - buddies.remove(index); - } - - /** - * Removes all buddies in this group and reinsterts them as specified - * by the <tt>newOrder</tt> param. Contacts not contained in the - * newOrder list are left at the end of this group. - * - * @param newOrder a list containing all contacts in the order that is - * to be applied. - * - */ - void reorderContacts(List newOrder) - { - buddies.removeAll(newOrder); - buddies.addAll(0, newOrder); + buddies.remove(contact.getAddress().toLowerCase()); } /** @@ -189,18 +173,7 @@ public class ContactGroupJabberImpl */ public Iterator contacts() { - return buddies.iterator(); - } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (ContactJabberImpl) buddies.get(index); + return buddies.values().iterator(); } /** @@ -359,14 +332,9 @@ public class ContactGroupJabberImpl */ ContactJabberImpl findContact(String id) { - Iterator contacts = contacts(); - while (contacts.hasNext()) - { - ContactJabberImpl item = (ContactJabberImpl) contacts.next(); - if(item.getAddress().equals(id)) - return item; - } - return null; + if(id == null) + return null; + return buddies.get(id.toLowerCase()); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/RootContactGroupJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/RootContactGroupJabberImpl.java index c2eb786..0da1653 100755 --- a/src/net/java/sip/communicator/impl/protocol/jabber/RootContactGroupJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/RootContactGroupJabberImpl.java @@ -19,13 +19,23 @@ public class RootContactGroupJabberImpl extends AbstractContactGroupJabberImpl { private String ROOT_CONTACT_GROUP_NAME = "ContactListRoot"; - private List subGroups = new LinkedList(); + + /** + * Maps all JIDs in our roster to the actual contacts so that we could + * easily search the set of existing contacts. Note that we only store + * lower case strings in the left column because JIDs in XMPP are not case + * sensitive. + */ + private List<ContactGroupJabberImpl> subGroups + = new LinkedList<ContactGroupJabberImpl>(); + private boolean isResolved = false; /** * An empty list that we use when returning an iterator. */ - private List contacts = new LinkedList(); + private Map<String, ContactJabberImpl> contacts + = new Hashtable<String, ContactJabberImpl>(); private ProtocolProviderServiceJabberImpl ownerProvider = null; @@ -80,7 +90,7 @@ public class RootContactGroupJabberImpl */ void addContact(ContactJabberImpl contact) { - contacts.add(contact); + contacts.put(contact.getAddress(), contact); } /** @@ -111,21 +121,6 @@ public class RootContactGroupJabberImpl } /** - * Removes all contact sub groups and reinsterts them as specified - * by the <tt>newOrder</tt> param. Contact groups not contained in the - * newOrder list are left at the end of this group. - * - * @param newOrder a list containing all contact groups in the order that is - * to be applied. - * - */ - void reorderSubGroups(List newOrder) - { - subGroups.removeAll(newOrder); - subGroups.addAll(0, newOrder); - } - - /** * Returns the number of subgroups contained by this * <tt>RootContactGroupImpl</tt>. * @@ -185,16 +180,22 @@ public class RootContactGroupJabberImpl */ public Contact getContact(String id) { - Iterator contacts = contacts(); - while (contacts.hasNext()) - { - ContactJabberImpl c = (ContactJabberImpl)contacts.next(); - - if (c.getAddress().equals(id)) - return c; - } + return findContact(id); + } - return null; + /** + * Returns the contact encapsulating with the spcieified name or + * null if no such contact was found. + * + * @param id the id for the contact we're looking for. + * @return the <tt>ContactJabberImpl</tt> corresponding to the specified + * jid or null if no such contact existed. + */ + ContactJabberImpl findContact(String id) + { + if(id == null) + return null; + return contacts.get(id.toLowerCase()); } /** @@ -228,19 +229,7 @@ public class RootContactGroupJabberImpl */ public Iterator contacts() { - return contacts.iterator(); - } - - /** - * A dummy impl of the corresponding interface method - always returns null. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index, i.e. always - * null. - */ - public Contact getContact(int index) - { - return (Contact)contacts.get(index); + return contacts.values().iterator(); } /** @@ -270,7 +259,7 @@ public class RootContactGroupJabberImpl if(contactsIter.hasNext()) buff.append("\n"); } - + return buff.toString(); } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java index 356ab0b..989b830 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java @@ -42,7 +42,8 @@ public class ServerStoredContactListJabberImpl /** * The root contagroup. The container for all jabber buddies and groups. */ - private RootContactGroupJabberImpl rootGroup = new RootContactGroupJabberImpl(); + private RootContactGroupJabberImpl rootGroup + = new RootContactGroupJabberImpl(); /** * The operation set that created us and that we could use when dispatching @@ -276,13 +277,12 @@ public class ServerStoredContactListJabberImpl */ public ContactJabberImpl findContactById(String id) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<ContactGroupJabberImpl> contactGroups = rootGroup.subgroups(); ContactJabberImpl result = null; while(contactGroups.hasNext()) { - ContactGroupJabberImpl contactGroup - = (ContactGroupJabberImpl) contactGroups.next(); + ContactGroupJabberImpl contactGroup = contactGroups.next(); result = contactGroup.findContact(id); @@ -291,16 +291,8 @@ public class ServerStoredContactListJabberImpl } - Iterator rootContacts = rootGroup.contacts(); - while (rootContacts.hasNext()) - { - ContactJabberImpl item = (ContactJabberImpl) rootContacts.next(); - - if(item.getAddress().equalsIgnoreCase(id)) - return item; - } - - return null; + //try the root group now + return rootGroup.findContact(id); } /** @@ -1068,4 +1060,4 @@ public class ServerStoredContactListJabberImpl } } } -}
\ No newline at end of file +} diff --git a/src/net/java/sip/communicator/impl/protocol/mock/MockContactGroup.java b/src/net/java/sip/communicator/impl/protocol/mock/MockContactGroup.java index 2c03ead..66064e7 100644 --- a/src/net/java/sip/communicator/impl/protocol/mock/MockContactGroup.java +++ b/src/net/java/sip/communicator/impl/protocol/mock/MockContactGroup.java @@ -147,18 +147,6 @@ public class MockContactGroup subgroup.setParentGroup(null); } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (MockContact)contacts.get(index); - } - /** * Returns the group that is parent of the specified mockGroup or null * if no parent was found. diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ContactGroupMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ContactGroupMsnImpl.java index a6cecc8..9053102 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/ContactGroupMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/ContactGroupMsnImpl.java @@ -30,7 +30,15 @@ import net.sf.jml.MsnContact; public class ContactGroupMsnImpl extends AbstractContactGroupMsnImpl { - private List buddies = new LinkedList(); + + /** + * Maps all MSN IDs in our contact list to the actual contacts so that we + * could easily search the set of existing contacts. Note that we only store + * lower case strings in the left column because MSN IDs in XMPP are not + * case sensitive. + */ + private Map<String, ContactMsnImpl> buddies + = new Hashtable<String, ContactMsnImpl>(); private boolean isResolved = false; /** @@ -42,7 +50,8 @@ public class ContactGroupMsnImpl * a list that would always remain empty. We only use it so that we're able * to extract empty iterators */ - private List dummyGroupsList = new LinkedList(); + private List<ContactGroupMsnImpl> dummyGroupsList + = new LinkedList<ContactGroupMsnImpl>(); private ServerStoredContactListMsnImpl ssclCallback = null; @@ -62,8 +71,7 @@ public class ContactGroupMsnImpl * @param isResolved a boolean indicating whether or not the group has been * resolved against the server. */ - ContactGroupMsnImpl( - MsnGroup msnGroup, + ContactGroupMsnImpl(MsnGroup msnGroup, MsnContact[] groupMembers, ServerStoredContactListMsnImpl ssclCallback, boolean isResolved) @@ -74,8 +82,17 @@ public class ContactGroupMsnImpl for (int i = 0; i < groupMembers.length; i++) { - addContact( - new ContactMsnImpl(groupMembers[i], ssclCallback, true, true) ); + + //only add the contact if it doesn't already exist in some other + //group. this is necessary because MSN would allow having one and the + //same contact in more than one group. + if(ssclCallback.findContactById(groupMembers[i] + .getEmail().getEmailAddress()) != null) + { + continue; + } + addContact( new ContactMsnImpl( + groupMembers[i], ssclCallback, true, true)); } } @@ -102,56 +119,25 @@ public class ContactGroupMsnImpl } /** - * Adds the specified contact at the specified position. - * @param contact the new contact to add to this group - * @param index the position where the new contact should be added. - */ - void addContact(int index, ContactMsnImpl contact) - { - buddies.add(index, contact); - } - - /** * Adds the specified contact to the end of this group. * @param contact the new contact to add to this group */ void addContact(ContactMsnImpl contact) { - addContact(countContacts(), contact); + buddies.put(contact.getAddress().toLowerCase(), contact); } /** * Removes the specified contact from this contact group * @param contact the contact to remove. - */ - void removeContact(ContactMsnImpl contact) - { - removeContact(buddies.indexOf(contact)); - } - - /** - * Removes the contact with the specified index. - * @param index the index of the cntact to remove - */ - void removeContact(int index) - { - buddies.remove(index); - } - - /** - * Removes all buddies in this group and reinsterts them as specified - * by the <tt>newOrder</tt> param. Contacts not contained in the - * newOrder list are left at the end of this group. - * - * @param newOrder a list containing all contacts in the order that is - * to be applied. * + * @return <tt>true</tt> if the argument was a component of this vector; + * false otherwise. */ - void reorderContacts(List newOrder) + boolean removeContact(ContactMsnImpl contact) { - buddies.removeAll(newOrder); - buddies.addAll(0, newOrder); + return buddies.remove(contact.getAddress().toLowerCase()) != null; } /** @@ -164,18 +150,7 @@ public class ContactGroupMsnImpl */ public Iterator contacts() { - return buddies.iterator(); - } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (ContactMsnImpl) buddies.get(index); + return buddies.values().iterator(); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/msn/RootContactGroupMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/RootContactGroupMsnImpl.java index 4030fa8..04444c9 100755 --- a/src/net/java/sip/communicator/impl/protocol/msn/RootContactGroupMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/RootContactGroupMsnImpl.java @@ -207,18 +207,6 @@ public class RootContactGroupMsnImpl } /** - * A dummy impl of the corresponding interface method - always returns null. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index, i.e. always - * null. - */ - public Contact getContact(int index) - { - return null; - } - - /** * Returns the <tt>Contact</tt> with the specified address or * identifier. * @param id the addres or identifier of the <tt>Contact</tt> we are diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java index 455ed3d..3fd817b 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java @@ -30,11 +30,6 @@ public class ServerStoredContactListMsnImpl Logger.getLogger(ServerStoredContactListMsnImpl.class); /** - * The name of the Volatile group - */ - private static final String VOLATILE_GROUP_NAME = "NotInContactList"; - - /** * The root group. The container for all msn buddies and groups. */ private RootContactGroupMsnImpl rootGroup = new RootContactGroupMsnImpl(); @@ -56,7 +51,8 @@ public class ServerStoredContactListMsnImpl * Listeners that would receive event notifications for changes in group * names or other properties, removal or creation of groups. */ - private Vector serverStoredGroupListeners = new Vector(); + private Vector<ServerStoredGroupListener> serverStoredGroupListeners + = new Vector<ServerStoredGroupListener>(); /** * Manages and fires contact list modifications @@ -71,7 +67,7 @@ public class ServerStoredContactListMsnImpl */ private boolean isInitialized = false; - private Vector skipAddEvent = new Vector(); + private Vector<String> skipAddEvent = new Vector<String>(); /** * Creates a ServerStoredContactList wrapper for the specified BuddyList. @@ -100,8 +96,10 @@ public class ServerStoredContactListMsnImpl RegistrationStateChangeEvent evt) { if (evt.getNewState() == RegistrationState.UNREGISTERED - || evt.getNewState() == RegistrationState.AUTHENTICATION_FAILED - || evt.getNewState() == RegistrationState.CONNECTION_FAILED) + || evt.getNewState() + == RegistrationState.AUTHENTICATION_FAILED + || evt.getNewState() + == RegistrationState.CONNECTION_FAILED) { isInitialized = false; } @@ -123,7 +121,8 @@ public class ServerStoredContactListMsnImpl /** * Registers the specified group listener so that it would receive events * on group modification/creation/destruction. - * @param listener the ServerStoredGroupListener to register for group events + * @param listener the ServerStoredGroupListener to register for group + * events */ void addGroupListener(ServerStoredGroupListener listener) { @@ -171,16 +170,16 @@ public class ServerStoredContactListMsnImpl logger.trace("Will dispatch the following grp event: " + evt); - Iterator listeners = null; + Iterator<ServerStoredGroupListener> listeners = null; synchronized (serverStoredGroupListeners) { - listeners = new ArrayList(serverStoredGroupListeners).iterator(); + listeners = new ArrayList<ServerStoredGroupListener>( + serverStoredGroupListeners).iterator(); } while (listeners.hasNext()) { - ServerStoredGroupListener listener - = (ServerStoredGroupListener) listeners.next(); + ServerStoredGroupListener listener = listeners.next(); if (eventID == ServerStoredGroupEvent.GROUP_REMOVED_EVENT) listener.groupRemoved(evt); @@ -255,12 +254,11 @@ public class ServerStoredContactListMsnImpl */ public ContactGroupMsnImpl findContactGroup(String name) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<ContactGroupMsnImpl> contactGroups = rootGroup.subgroups(); while(contactGroups.hasNext()) { - ContactGroupMsnImpl contactGroup - = (ContactGroupMsnImpl) contactGroups.next(); + ContactGroupMsnImpl contactGroup = contactGroups.next(); if (contactGroup.getGroupName().equals(name)) return contactGroup; @@ -279,13 +277,12 @@ public class ServerStoredContactListMsnImpl */ public ContactMsnImpl findContactById(String id) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<ContactGroupMsnImpl> contactGroups = rootGroup.subgroups(); ContactMsnImpl result = null; while(contactGroups.hasNext()) { - ContactGroupMsnImpl contactGroup - = (ContactGroupMsnImpl) contactGroups.next(); + ContactGroupMsnImpl contactGroup = contactGroups.next(); result = contactGroup.findContact(id); @@ -294,7 +291,7 @@ public class ServerStoredContactListMsnImpl } - Iterator rootContacts = rootGroup.contacts(); + Iterator<ContactMsnImpl> rootContacts = rootGroup.contacts(); while (rootContacts.hasNext()) { ContactMsnImpl item = (ContactMsnImpl) rootContacts.next(); @@ -317,22 +314,21 @@ public class ServerStoredContactListMsnImpl */ public ContactGroup findContactGroup(ContactMsnImpl child) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<ContactGroupMsnImpl> contactGroups = rootGroup.subgroups(); while(contactGroups.hasNext()) { - ContactGroupMsnImpl contactGroup - = (ContactGroupMsnImpl) contactGroups.next(); + ContactGroupMsnImpl contactGroup = contactGroups.next(); if( contactGroup.findContact(child.getAddress())!= null) return contactGroup; } - Iterator contacts = rootGroup.contacts(); + Iterator<ContactMsnImpl> contacts = rootGroup.contacts(); while(contacts.hasNext()) { - ContactMsnImpl contact = (ContactMsnImpl) contacts.next(); + ContactMsnImpl contact = contacts.next(); if( contact.equals(child)) return rootGroup; @@ -566,7 +562,8 @@ public class ServerStoredContactListMsnImpl */ void removeContact(ContactMsnImpl contactToRemove) { - logger.trace("Removing msn contact " + contactToRemove.getSourceContact()); + logger.trace("Removing msn contact " + + contactToRemove.getSourceContact()); Email contactsEmail = contactToRemove.getSourceContact().getEmail(); @@ -613,7 +610,8 @@ public class ServerStoredContactListMsnImpl msnProvider.getMessenger(). copyFriend( contact.getSourceContact().getEmail(), - ((ContactGroupMsnImpl)newParent).getSourceGroup().getGroupId()); + ((ContactGroupMsnImpl)newParent).getSourceGroup() + .getGroupId()); } else { @@ -649,15 +647,16 @@ public class ServerStoredContactListMsnImpl } else { - logger.trace("Will Move from " + contact.getParentContactGroup() + logger.trace("Will Move from " + + contact.getParentContactGroup() + " to : " + newParent + " - contact: " + contact); // contactListModListenerImpl.waitForMove(contact.getAddress()); msnProvider.getMessenger().moveFriend( contact.getSourceContact().getEmail(), ( (ContactGroupMsnImpl) contact.getParentContactGroup()). getSourceGroup().getGroupId(), - ((ContactGroupMsnImpl)newParent).getSourceGroup().getGroupId() - ); + ((ContactGroupMsnImpl)newParent).getSourceGroup() + .getGroupId()); } } } @@ -688,12 +687,11 @@ public class ServerStoredContactListMsnImpl */ private ContactGroupMsnImpl findContactGroupByMsnId(String id) { - Iterator contactGroups = rootGroup.subgroups(); + Iterator<ContactGroupMsnImpl> contactGroups = rootGroup.subgroups(); while(contactGroups.hasNext()) { - ContactGroupMsnImpl contactGroup - = (ContactGroupMsnImpl) contactGroups.next(); + ContactGroupMsnImpl contactGroup = contactGroups.next(); if (contactGroup.getSourceGroup().getGroupId().equals(id)) return contactGroup; @@ -775,8 +773,8 @@ public class ServerStoredContactListMsnImpl * Returns true if the contact list is initialized and * ready for use, and false otherwise. * - * @return true if the contact list is initialized and ready for use and false - * otherwise + * @return true if the contact list is initialized and ready for use and + * false otherwise */ boolean isInitialized() { @@ -784,8 +782,8 @@ public class ServerStoredContactListMsnImpl } /** - * Waits for init in the contact list and populates the contacts and fills or - * resolves our contact list + * Waits for init in the contact list and populates the contacts and fills + * or resolves our contact list */ private class ContactListListener implements net.sf.jml.event.MsnContactListListener @@ -812,7 +810,8 @@ public class ServerStoredContactListMsnImpl if(item.isDefaultGroup()) continue; - ContactGroupMsnImpl group = findContactGroup(item.getGroupName()); + ContactGroupMsnImpl group + = findContactGroup(item.getGroupName()); if (group == null) { @@ -827,8 +826,8 @@ public class ServerStoredContactListMsnImpl rootGroup.addSubGroup(newGroup); //tell listeners about the added group - fireGroupEvent(newGroup - , ServerStoredGroupEvent.GROUP_CREATED_EVENT); + fireGroupEvent(newGroup, + ServerStoredGroupEvent.GROUP_CREATED_EVENT); } else { @@ -837,8 +836,8 @@ public class ServerStoredContactListMsnImpl group.setResolved(item); //fire an event saying that the group has been resolved - fireGroupEvent(group - , ServerStoredGroupEvent.GROUP_RESOLVED_EVENT); + fireGroupEvent(group, + ServerStoredGroupEvent.GROUP_RESOLVED_EVENT); /** @todo if something to delete . delete it */ } @@ -861,7 +860,10 @@ public class ServerStoredContactListMsnImpl { // if there is no such contact create it contact = new ContactMsnImpl( - item, ServerStoredContactListMsnImpl.this, true, true); + item, + ServerStoredContactListMsnImpl.this, + true, + true); rootGroup.addContact(contact); fireContactAdded(rootGroup, contact); @@ -911,20 +913,26 @@ public class ServerStoredContactListMsnImpl AuthorizationRequest authRequest = new AuthorizationRequest(); AuthorizationResponse authResponse = - parentOperationSet.getAuthorizationHandler().processAuthorisationRequest( - authRequest, contactImpl); + parentOperationSet.getAuthorizationHandler() + .processAuthorisationRequest( authRequest, contactImpl); - if (authResponse.getResponseCode() == AuthorizationResponse.IGNORE) + if (authResponse.getResponseCode() + == AuthorizationResponse.IGNORE) + { return; + } else if (authResponse.getResponseCode() == AuthorizationResponse.REJECT) + { msnProvider.getMessenger().blockFriend(contact.getEmail()); + } else if (authResponse.getResponseCode() == AuthorizationResponse.ACCEPT) { moveContact(contactImpl, rootGroup); -// addContact(contact.getEmail().getEmailAddress()); -// msnProvider.getMessenger().unblockFriend(contact.getEmail()); +// addContact(contact.getEmail().getEmailAddress()); +// msnProvider.getMessenger() +// .unblockFriend(contact.getEmail()); } // } // catch (OperationFailedException ex) @@ -937,7 +945,9 @@ public class ServerStoredContactListMsnImpl { } - public void contactAddCompleted(MsnMessenger messenger, MsnContact contact, MsnList list) + public void contactAddCompleted(MsnMessenger messenger, + MsnContact contact, + MsnList list) { String contactID = contact.getEmail().getEmailAddress(); @@ -964,7 +974,9 @@ public class ServerStoredContactListMsnImpl } } - public void contactRemoveCompleted(MsnMessenger messenger, MsnContact contact, MsnList list) + public void contactRemoveCompleted(MsnMessenger messenger, + MsnContact contact, + MsnList list) { ContactMsnImpl contactToRemove = findContactById(contact.getEmail().getEmailAddress()); @@ -975,15 +987,16 @@ public class ServerStoredContactListMsnImpl return; } - if(contactToRemove.getParentContactGroup() instanceof RootContactGroupMsnImpl) + if(contactToRemove.getParentContactGroup() + instanceof RootContactGroupMsnImpl) { rootGroup.removeContact(contactToRemove); fireContactRemoved(rootGroup, contactToRemove); } else { - ContactGroupMsnImpl parentGroup = - (ContactGroupMsnImpl)contactToRemove.getParentContactGroup(); + ContactGroupMsnImpl parentGroup = (ContactGroupMsnImpl) + contactToRemove.getParentContactGroup(); parentGroup.removeContact(contactToRemove); fireContactRemoved(parentGroup, contactToRemove); } @@ -1014,13 +1027,25 @@ public class ServerStoredContactListMsnImpl rootGroup.removeSubGroup(group); fireGroupEvent(group, ServerStoredGroupEvent.GROUP_REMOVED_EVENT); } - public void contactAddInGroupCompleted(MsnMessenger messenger, MsnContact c, MsnGroup g) + + /** + * Called when a contact has been added to a group. Note that this + * method would also be called after moving a contact. + * + * @param messenger a reference to the currently valid messenger + * @param c the contact that has been added + * @param g the group that the contact was added to + */ + public void contactAddInGroupCompleted( MsnMessenger messenger, + MsnContact c, + MsnGroup g) { ContactMsnImpl contactToAdd = findContactById(c.getEmail().getEmailAddress()); if(contactToAdd == null) { + //this is really a new contact contactToAdd = new ContactMsnImpl( c, @@ -1041,6 +1066,7 @@ public class ServerStoredContactListMsnImpl } else { + //the contact was added here. ContactGroup oldGroup = contactToAdd.getParentContactGroup(); @@ -1057,13 +1083,19 @@ public class ServerStoredContactListMsnImpl if(oldGroup instanceof RootContactGroupMsnImpl) - ((RootContactGroupMsnImpl)oldGroup).removeContact(contactToAdd); + { + ((RootContactGroupMsnImpl)oldGroup) + .removeContact(contactToAdd); + } else + { ((ContactGroupMsnImpl)oldGroup).removeContact(contactToAdd); + } fireContactMoved(oldGroup, group, contactToAdd); } } + public void contactRemoveFromGroupCompleted(MsnMessenger messenger, MsnContact c, MsnGroup g) { @@ -1091,8 +1123,14 @@ public class ServerStoredContactListMsnImpl return; } - dstGroup.removeContact(contactToRemove); - fireContactRemoved(dstGroup, contactToRemove); + //make sure that the contact was really in the group because when + //moving contacts with multiple parent groups we get multiple + //removal events. That's a problem because we don't support multiple + //parent groups and we only show a single parent so all remove + //events for the parent groups we are not displaying will cause + //exceptions + if(dstGroup.removeContact(contactToRemove)) + fireContactRemoved(dstGroup, contactToRemove); } public void ownerDisplayNameChanged(MsnMessenger arg0) @@ -1266,7 +1304,8 @@ public class ServerStoredContactListMsnImpl c[i].getBelongGroups().length); } - logger.info("Number of groups : " + messenger.getContactList().getGroups().length); + logger.info("Number of groups : " + + messenger.getContactList().getGroups().length); MsnGroup[] groups = messenger.getContactList().getGroups(); for(int j = 0; j < groups.length; j++) { @@ -1284,12 +1323,13 @@ public class ServerStoredContactListMsnImpl this.contact = contact; } - public void notifyMsnObjectRetrieval(MsnMessenger arg0messenger, - DisplayPictureRetrieveWorker worker, - MsnObject msnObject, - ResultStatus result, - byte[] resultBytes, - Object context) + public void notifyMsnObjectRetrieval( + MsnMessenger arg0messenger, + DisplayPictureRetrieveWorker worker, + MsnObject msnObject, + ResultStatus result, + byte[] resultBytes, + Object context) { if (result == ResultStatus.GOOD) { diff --git a/src/net/java/sip/communicator/impl/protocol/rss/ContactGroupRssImpl.java b/src/net/java/sip/communicator/impl/protocol/rss/ContactGroupRssImpl.java index 538c86e..ca4f668 100644 --- a/src/net/java/sip/communicator/impl/protocol/rss/ContactGroupRssImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/rss/ContactGroupRssImpl.java @@ -193,18 +193,6 @@ public class ContactGroupRssImpl subgroup.setParentGroup(null); } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (ContactRssImpl)contacts.get(index); - } - /** * Returns the group that is parent of the specified rssGroup or null * if no parent was found. @@ -454,7 +442,7 @@ public class ContactGroupRssImpl //return buff.append("]").toString(); return rssURLList; } - + /** * Specifies whether or not this contact group is being stored by the server. * Non persistent contact groups are common in the case of simple, diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ContactGroupSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/ContactGroupSipImpl.java index 45e2daf..f836981 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ContactGroupSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ContactGroupSipImpl.java @@ -194,18 +194,6 @@ public class ContactGroupSipImpl subgroup.setParentGroup(null); } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (ContactSipImpl)contacts.get(index); - } - /** * Returns the group that is parent of the specified sipGroup or null * if no parent was found. diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/ContactGroupSSHImpl.java b/src/net/java/sip/communicator/impl/protocol/ssh/ContactGroupSSHImpl.java index c4572a0..7552e01 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/ContactGroupSSHImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/ContactGroupSSHImpl.java @@ -19,7 +19,7 @@ import net.java.sip.communicator.service.protocol.*; * the SSH protocol is not a real one, we simply store all group details * in class fields. You should know that when implementing a real protocol, * the contact group implementation would rather encapsulate group objects from - * the protocol stack and group property values should be returned by + * the protocol stack and group property values should be returned by * consulting the encapsulated object. * * @author Shobhit Jindal @@ -159,7 +159,7 @@ public class ContactGroupSSHImpl /** * Adds the specified contact group to the contained by this group. - * @param subgroup the ContactGroupSSHImpl to add as a subgroup to this + * @param subgroup the ContactGroupSSHImpl to add as a subgroup to this * group. */ public void addSubgroup(ContactGroupSSHImpl subgroup) @@ -198,18 +198,6 @@ public class ContactGroupSSHImpl subgroup.setParentGroup(null); } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (ContactSSHImpl) contacts.get(index); - } - /** * Returns the group that is parent of the specified sshGroup or null * if no parent was found. @@ -430,15 +418,15 @@ public class ContactGroupSSHImpl } /** - * Specifies whether or not this contact group is being stored by the + * Specifies whether or not this contact group is being stored by the * server. * Non persistent contact groups are common in the case of simple, * non-persistent presence operation sets. They could however also be seen * in persistent presence operation sets when for example we have received * an event from someone not on our contact list and the contact that we * associated with that user is placed in a non persistent group. Non - * persistent contact groups are volatile even when coming from a - * persistent presence op. set. They would only exist until the + * persistent contact groups are volatile even when coming from a + * persistent presence op. set. They would only exist until the * application is closed and will not be there next time it is loaded. * * @param isPersistent true if the contact group is to be persistent and diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/ContactGroupYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/ContactGroupYahooImpl.java index 6cc6030..d43f65b 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/ContactGroupYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/ContactGroupYahooImpl.java @@ -43,7 +43,7 @@ public class ContactGroupYahooImpl * to extract empty iterators */ private List dummyGroupsList = new LinkedList(); - + private String tempId = null; private ServerStoredContactListYahooImpl ssclCallback = null; @@ -79,11 +79,11 @@ public class ContactGroupYahooImpl { addContact( new ContactYahooImpl( - (YahooUser)iter.next(), + (YahooUser)iter.next(), ssclCallback, true, true) ); } } - + ContactGroupYahooImpl( String id, ServerStoredContactListYahooImpl ssclCallback) @@ -183,17 +183,6 @@ public class ContactGroupYahooImpl } /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (ContactYahooImpl) buddies.get(index); - } - - /** * Returns the <tt>Contact</tt> with the specified address or * identifier. * @param id the addres or identifier of the <tt>Contact</tt> we are diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/RootContactGroupYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/RootContactGroupYahooImpl.java index 2ce9df8..33ae66f 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/RootContactGroupYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/RootContactGroupYahooImpl.java @@ -192,18 +192,6 @@ public class RootContactGroupYahooImpl } /** - * A dummy impl of the corresponding interface method - always returns null. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index, i.e. always - * null. - */ - public Contact getContact(int index) - { - return null; - } - - /** * Returns the <tt>Contact</tt> with the specified address or * identifier. * @param id the addres or identifier of the <tt>Contact</tt> we are diff --git a/src/net/java/sip/communicator/impl/protocol/zeroconf/ContactGroupZeroconfImpl.java b/src/net/java/sip/communicator/impl/protocol/zeroconf/ContactGroupZeroconfImpl.java index 350f295..976e2fd 100644 --- a/src/net/java/sip/communicator/impl/protocol/zeroconf/ContactGroupZeroconfImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/zeroconf/ContactGroupZeroconfImpl.java @@ -17,7 +17,7 @@ import net.java.sip.communicator.service.protocol.*; * the contact group implementation would rather encapsulate group objects from * the protocol stack and group property values should be returned by consulting * the encapsulated object. - * + * * @author Christian Vincenot * @author Maxime Catelin * @author Jonathan Martin @@ -157,7 +157,7 @@ public class ContactGroupZeroconfImpl /** * Adds the specified contact group to the contained by this group. - * @param subgroup the ContactGroupZeroconfImpl to add as a + * @param subgroup the ContactGroupZeroconfImpl to add as a * subgroup to this group. */ public void addSubgroup(ContactGroupZeroconfImpl subgroup) @@ -196,18 +196,6 @@ public class ContactGroupZeroconfImpl subgroup.setParentGroup(null); } - - /** - * Returns the <tt>Contact</tt> with the specified index. - * - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index) - { - return (ContactZeroconfImpl)contacts.get(index); - } - /** * Returns the group that is parent of the specified zeroconfGroup or null * if no parent was found. @@ -279,9 +267,9 @@ public class ContactGroupZeroconfImpl Iterator contactsIter = contacts(); while (contactsIter.hasNext()) { - ContactZeroconfImpl contact = + ContactZeroconfImpl contact = (ContactZeroconfImpl)contactsIter.next(); - + if (contact.getAddress().equals(id)) return contact; @@ -374,7 +362,7 @@ public class ContactGroupZeroconfImpl while(contactsIter.hasNext()) { - ContactZeroconfImpl mContact = + ContactZeroconfImpl mContact = (ContactZeroconfImpl)contactsIter.next(); if( mContact.getAddress().equals(id) ) @@ -386,7 +374,7 @@ public class ContactGroupZeroconfImpl while( groupsIter.hasNext() ) { - ContactGroupZeroconfImpl mGroup = + ContactGroupZeroconfImpl mGroup = (ContactGroupZeroconfImpl)groupsIter.next(); ContactZeroconfImpl mContact = mGroup.findContactByID(id); @@ -413,7 +401,7 @@ public class ContactGroupZeroconfImpl Iterator subGroups = subgroups(); while (subGroups.hasNext()) { - ContactGroupZeroconfImpl group = + ContactGroupZeroconfImpl group = (ContactGroupZeroconfImpl)subGroups.next(); buff.append(group.toString()); if (subGroups.hasNext()) @@ -550,7 +538,7 @@ public class ContactGroupZeroconfImpl ContactGroupZeroconfImpl zeroconfGroup = (ContactGroupZeroconfImpl)obj; - if(!zeroconfGroup.getGroupName().equals(getGroupName()) || + if(!zeroconfGroup.getGroupName().equals(getGroupName()) || !zeroconfGroup.getUID().equals(getUID()) || zeroconfGroup.countContacts() != countContacts() || zeroconfGroup.countSubgroups() != countSubgroups()) @@ -591,4 +579,4 @@ public class ContactGroupZeroconfImpl return true; } -}
\ No newline at end of file +} diff --git a/src/net/java/sip/communicator/service/protocol/ContactGroup.java b/src/net/java/sip/communicator/service/protocol/ContactGroup.java index f1c8b46..238a75c 100644 --- a/src/net/java/sip/communicator/service/protocol/ContactGroup.java +++ b/src/net/java/sip/communicator/service/protocol/ContactGroup.java @@ -69,13 +69,6 @@ public interface ContactGroup public int countContacts(); /** - * Returns the <tt>Contact</tt> with the specified index. - * @param index the index of the <tt>Contact</tt> to return. - * @return the <tt>Contact</tt> with the specified index. - */ - public Contact getContact(int index); - - /** * Returns the <tt>Contact</tt> with the specified address or * identifier. * @param id the addres or identifier of the <tt>Contact</tt> we are |