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