From 6812eea1e082be1c4d4b35fc1cb9b6fefee7d062 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Tue, 5 Aug 2003 02:33:11 +0000 Subject: [PATCH] Support for entry count and getting all entries. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2013 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/Roster.java | 44 +++++++++++++++++++ .../org/jivesoftware/smack/RosterEntry.java | 18 ++++++++ 2 files changed, 62 insertions(+) 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;