From dd4c10ac9d7b29f59bed87e13acb6eaef8b635ec Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Sun, 23 Mar 2003 23:03:19 +0000 Subject: [PATCH] Improvements in entry creation and management. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1854 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/Roster.java | 22 +++++++++++++++++ .../org/jivesoftware/smack/RosterGroup.java | 24 +++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/source/org/jivesoftware/smack/Roster.java b/source/org/jivesoftware/smack/Roster.java index 2e3149c06..93cc4ecf7 100644 --- a/source/org/jivesoftware/smack/Roster.java +++ b/source/org/jivesoftware/smack/Roster.java @@ -104,6 +104,17 @@ public class Roster { } } + /** + * Cretaes a new roster entry. + * + * @param user + * @param name + * @return + */ + public RosterEntry createEntry(String user, String name) { + return new RosterEntry(user, name, connection); + } + /** * Returns the roster group with the specified name, or null if the * group doesn't exist. @@ -117,6 +128,17 @@ public class Roster { } } + /** + * Returns the number of the groups in the roster. + * + * @return the number of groups in the roster. + */ + public int getGroupCount() { + synchronized (groups) { + return groups.size(); + } + } + /** * Returns an iterator the for all the roster groups. * diff --git a/source/org/jivesoftware/smack/RosterGroup.java b/source/org/jivesoftware/smack/RosterGroup.java index f2990fa94..4be53f0ac 100644 --- a/source/org/jivesoftware/smack/RosterGroup.java +++ b/source/org/jivesoftware/smack/RosterGroup.java @@ -108,18 +108,38 @@ public class RosterGroup { } } + /** + * Returns the number of entries in the group. + * + * @return the number of entries in the group. + */ public int getEntryCount() { synchronized (entries) { return entries.size(); } } + /** + * Returns an iterator for the entries in the group. + * + * @return an iterator for the entries in the group. + */ public Iterator getEntries() { - return Collections.unmodifiableList(entries).iterator(); + synchronized (entries) { + return Collections.unmodifiableList(new ArrayList(entries)).iterator(); + } } + /** + * Returns true if an entry is part of the group. + * + * @param entry + * @return + */ public boolean contains(RosterEntry entry) { - return entries.contains(entry); + synchronized (entries) { + return entries.contains(entry); + } } public void addEntry(RosterEntry entry) {