diff --git a/source/org/jivesoftware/smack/Roster.java b/source/org/jivesoftware/smack/Roster.java index 8b9f846f1..358a07951 100644 --- a/source/org/jivesoftware/smack/Roster.java +++ b/source/org/jivesoftware/smack/Roster.java @@ -244,6 +244,50 @@ public class Roster { connection.sendPacket(presencePacket); } + /** + * Returns a count of the entries in the roster. + * + * @return the number of entries in the roster. + */ + public int getEntryCount() { + HashMap entryMap = new HashMap(); + // Loop through all roster groups. + for (Iterator groups = getGroups(); groups.hasNext(); ) { + RosterGroup rosterGroup = (RosterGroup) groups.next(); + for (Iterator entries = rosterGroup.getEntries(); entries.hasNext(); ) { + entryMap.put(entries.next(), ""); + } + } + synchronized (unfiledEntries) { + return entryMap.size() + unfiledEntries.size(); + } + } + + /** + * Returns all entries in the roster, including entries that don't belong to + * any groups. + * + * @return all entries in the roster. + */ + public Iterator getEntries() { + ArrayList allEntries = new ArrayList(); + // Loop through all roster groups and add their entries to the new RosterExchange + for (Iterator groups = getGroups(); groups.hasNext(); ) { + RosterGroup rosterGroup = (RosterGroup) groups.next(); + for (Iterator entries = rosterGroup.getEntries(); entries.hasNext(); ) { + RosterEntry entry = (RosterEntry)entries.next(); + if (!allEntries.contains(entry)) { + allEntries.add(entry); + } + } + } + // Add the roster unfiled entries to the new RosterExchange + synchronized (unfiledEntries) { + allEntries.add(unfiledEntries); + } + return allEntries.iterator(); + } + /** * Returns an Iterator for the roster entries that haven't been assigned to any groups. * diff --git a/source/org/jivesoftware/smack/RosterEntry.java b/source/org/jivesoftware/smack/RosterEntry.java index c097c7db3..b591dcbbf 100644 --- a/source/org/jivesoftware/smack/RosterEntry.java +++ b/source/org/jivesoftware/smack/RosterEntry.java @@ -96,6 +96,24 @@ public class RosterEntry { return type; } + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append(user); + Iterator groups = getGroups(); + if (groups.hasNext()) { + buf.append(" ["); + RosterGroup group = (RosterGroup)groups.next(); + buf.append(group.getName()); + while (groups.hasNext()) { + buf.append(", "); + group = (RosterGroup)groups.next(); + buf.append(group.getName()); + } + buf.append("]"); + } + return buf.toString(); + } + public boolean equals(Object object) { if (this == object) { return true;