/** * Returns an unmodifiable collection of the roster groups that this entry belongs to. * * @return an iterator for the groups this entry belongs to. */ public Collection<RosterGroup> getGroups() { List<RosterGroup> results = new ArrayList<RosterGroup>(); // Loop through all roster groups and find the ones that contain this // entry. This algorithm should be fine for (RosterGroup group : roster.getGroups()) { if (group.contains(this)) { results.add(group); } } return Collections.unmodifiableCollection(results); }
/** * @see net.sf.kraken.session.TransportSession#updateContact(net.sf.kraken.roster.TransportBuddy) */ @Override public void updateContact(XMPPBuddy contact) { RosterEntry user2Update; String mail = getTransport().convertJIDToID(contact.getJID()); user2Update = conn.getRoster().getEntry(mail); user2Update.setName(contact.getNickname()); Collection<String> newgroups = contact.getGroups(); if (newgroups == null) { newgroups = new ArrayList<String>(); } for (RosterGroup group : conn.getRoster().getGroups()) { if (newgroups.contains(group.getName())) { if (!group.contains(user2Update)) { try { group.addEntry(user2Update); } catch (XMPPException e) { Log.debug("XMPP: Unable to add roster item to group."); } } newgroups.remove(group.getName()); } else { if (group.contains(user2Update)) { try { group.removeEntry(user2Update); } catch (XMPPException e) { Log.debug("XMPP: Unable to delete roster item from group."); } } } } for (String group : newgroups) { RosterGroup newgroup = conn.getRoster().createGroup(group); try { newgroup.addEntry(user2Update); } catch (XMPPException e) { Log.debug("XMPP: Unable to add roster item to new group."); } } }