From 23eecbf102623e63e875f7c7d660ac50b05185a2 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Wed, 3 Sep 2003 03:00:45 +0000 Subject: [PATCH] Added additional convenience methods (SMACK-82). git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2080 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/Roster.java | 49 +++++++++++++++++++ .../org/jivesoftware/smack/RosterGroup.java | 25 ++++++++++ 2 files changed, 74 insertions(+) diff --git a/source/org/jivesoftware/smack/Roster.java b/source/org/jivesoftware/smack/Roster.java index 95846af4f..bff3ab3f5 100644 --- a/source/org/jivesoftware/smack/Roster.java +++ b/source/org/jivesoftware/smack/Roster.java @@ -317,6 +317,55 @@ public class Roster { } } + /** + * Returns the roster entry associated with the given XMPP address or + * null if the user is not an entry in the roster. + * + * @param user the XMPP address of the user (eg "jsmith@example.com"). + * @return the roster entry or null if it does not exist. + */ + public RosterEntry getEntry(String user) { + if (user == null) { + return null; + } + // Roster entries never include a resource so remove the resource + // if it's a part of the XMPP address. + user = StringUtils.parseBareAddress(user); + synchronized (entries) { + for (Iterator i=entries.iterator(); i.hasNext(); ) { + RosterEntry entry = (RosterEntry)i.next(); + if (entry.getUser().equals(user)) { + return entry; + } + } + } + return null; + } + + /** + * Returns true if the specified XMPP address is an entry in the roster. + * + * @param user the XMPP address of the user (eg "jsmith@example.com"). + * @return true if the XMPP address is an entry in the roster. + */ + public boolean contains(String user) { + if (user == null) { + return false; + } + // Roster entries never include a resource so remove the resource + // if it's a part of the XMPP address. + user = StringUtils.parseBareAddress(user); + synchronized (entries) { + for (Iterator i=entries.iterator(); i.hasNext(); ) { + RosterEntry entry = (RosterEntry)i.next(); + if (entry.getUser().equals(user)) { + return true; + } + } + } + return false; + } + /** * Returns the roster group with the specified name, or null if the * group doesn't exist. diff --git a/source/org/jivesoftware/smack/RosterGroup.java b/source/org/jivesoftware/smack/RosterGroup.java index 630967b95..b9d734caa 100644 --- a/source/org/jivesoftware/smack/RosterGroup.java +++ b/source/org/jivesoftware/smack/RosterGroup.java @@ -131,6 +131,31 @@ public class RosterGroup { } } + /** + * Returns the roster entry associated with the given XMPP address or + * null if the user is not an entry in the group. + * + * @param user the XMPP address of the user (eg "jsmith@example.com"). + * @return the roster entry or null if it does not exist in the group. + */ + public RosterEntry getEntry(String user) { + if (user == null) { + return null; + } + // Roster entries never include a resource so remove the resource + // if it's a part of the XMPP address. + user = StringUtils.parseBareAddress(user); + synchronized (entries) { + for (Iterator i=entries.iterator(); i.hasNext(); ) { + RosterEntry entry = (RosterEntry)i.next(); + if (entry.getUser().equals(user)) { + return entry; + } + } + } + return null; + } + /** * Returns true if the specified entry is part of this group. *