1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-23 04:57:58 +01:00

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
This commit is contained in:
Matt Tucker 2003-08-05 02:33:11 +00:00 committed by mtucker
parent c05820b2ae
commit 6812eea1e0
2 changed files with 62 additions and 0 deletions

View file

@ -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.
*

View file

@ -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;