src/main/java/org/jivesoftware/smack/UserRoster.java
public Presence getPresence(String user) {
        String key = getPresenceMapKey(StringUtils.parseBareAddress(user));
        Map<String, Presence> userPresences = presenceMap.get(key);
        if (userPresences == null) {
            Presence presence = new Presence(Presence.Type.unavailable);
            presence.setFrom(user);
            return presence;
        } else {
            // Find the resource with the highest priority
            // Might be changed to use the resource with the highest
            // availability instead.
            Presence presence = null;

            for (String resource : userPresences.keySet()) {
                Presence p = userPresences.get(resource);
                if (!p.isAvailable()) {
                    continue;
                }
                // Chose presence with highest priority first.
                if (presence == null
                        || p.getPriority() > presence.getPriority()) {
                    presence = p;
                }
                // If equal priority, choose "most available" by the mode value.
                else if (p.getPriority() == presence.getPriority()) {
                    Presence.Show pMode = p.getShow();
                    // Default to presence mode of available.
                    if (pMode == null) {
                        pMode = Presence.Show.chat;
                    }
                    Presence.Show presenceMode = presence.getShow();
                    // Default to presence mode of available.
                    if (presenceMode == null) {
                        presenceMode = Presence.Show.chat;
                    }
                    if (pMode.compareTo(presenceMode) < 0) {
                        presence = p;
                    }
                }
            }
            if (presence == null) {
                presence = new Presence(Presence.Type.unavailable);
                presence.setFrom(user);
                return presence;
            } else {
                return presence;
            }
        }
    }
public Presence getPresence(String user) {
        String key = getPresenceMapKey(StringUtils.parseBareAddress(user));
        Map<String, Presence> userPresences = presenceMap.get(key);
        if (userPresences == null) {
            Presence presence = new Presence(Presence.Type.unavailable);
            presence.setFrom(user);
            return presence;
        } else {
            // Find the resource with the highest priority
            // Might be changed to use the resource with the highest
            // availability instead.
            Presence presence = null;

            for (String resource : userPresences.keySet()) {
                Presence p = userPresences.get(resource);
                if (!p.isAvailable()) {
                    continue;
                }
                // Chose presence with highest priority first.
                if (presence == null
                        || p.getPriority() > presence.getPriority()) {
                    presence = p;
                }
                // If equal priority, choose "most available" by the mode value.
                else if (p.getPriority() == presence.getPriority()) {
                    Presence.Show pMode = p.getShow();
                    // Default to presence mode of available.
                    if (pMode == null) {
                        pMode = Presence.Show.chat;
                    }
                    Presence.Show presenceMode = presence.getShow();
                    // Default to presence mode of available.
                    if (presenceMode == null) {
                        presenceMode = Presence.Show.chat;
                    }
                    if (pMode.compareTo(presenceMode) < 0) {
                        presence = p;
                    }
                }
            }
            if (presence == null) {
                presence = new Presence(Presence.Type.unavailable);
                presence.setFrom(user);
                return presence;
            } else {
                return presence;
            }
        }
    }
public Presence getPresence ( String user ) { String key = getPresenceMapKey ( StringUtils . parseBareAddress ( user ) ) ; Map < String , Presence > userPresences = presenceMap . get ( key ) ; if ( userPresences == null ) { Presence presence = new Presence ( Presence . Type . unavailable ) ; presence . setFrom ( user ) ; return presence ; } else { // Find the resource with the highest priority // Might be changed to use the resource with the highest // availability instead. Presence presence = null ; for ( String resource : userPresences . keySet ( ) ) { Presence p = userPresences . get ( resource ) ; if ( ! p . isAvailable ( ) ) { continue ; } // Chose presence with highest priority first. if ( presence == null || p . getPriority ( ) > presence . getPriority ( ) ) { presence = p ; } // If equal priority, choose "most available" by the mode value. else if ( p . getPriority ( ) == presence . getPriority ( ) ) { Presence . Show pMode = p . getShow ( ) ; // Default to presence mode of available. if ( pMode == null ) { pMode = Presence . Show . chat ; } Presence . Show presenceMode = presence . getShow ( ) ; // Default to presence mode of available. if ( presenceMode == null ) { presenceMode = Presence . Show . chat ; } if ( pMode . compareTo ( presenceMode ) < 0 ) { presence = p ; } } } if ( presence == null ) { presence = new Presence ( Presence . Type . unavailable ) ; presence . setFrom ( user ) ; return presence ; } else { return presence ; } } }
Returns the presence info for a particular user. If the user is offline,
or if no presence data is available (such as when you are not subscribed
to the user's presence updates), unavailable presence will be returned.
<p>
<p/>
If the user has several presences (one for each resource), then the
presence with highest priority will be returned. If multiple presences
have the same priority, the one with the "most available" presence mode
will be returned. In order, that's
{@link org.jivesoftware.smack.packet.Presence.Mode#chat free to chat},
{@link org.jivesoftware.smack.packet.Presence.Mode#available available},
{@link org.jivesoftware.smack.packet.Presence.Mode#away away},
{@link org.jivesoftware.smack.packet.Presence.Mode#xa extended away}, and
{@link org.jivesoftware.smack.packet.Presence.Mode#dnd do not disturb}.
<p>
<p/>
Note that presence information is received asynchronously. So, just after
logging in to the server, presence values for users in the roster may be
unavailable even if they are actually online. In other words, the value
returned by this method should only be treated as a snapshot in time, and
may not accurately reflect other user's presence instant by instant. If
you need to track presence over time, such as when showing a visual
representation of the roster, consider using a {@link RosterListener}.

@param user
an XMPP ID. The address could be in any valid format (e.g.
"domain/resource", "user@domain" or "user@domain/resource").
Any resource information that's part of the ID will be
discarded.
@return the user's current presence, or unavailable presence if the user
is offline or if no presence information is available..
Returns the presence info for a particular user . If the user is offline or if no presence data is available ( such as when you are not subscribed to the user s presence updates ) unavailable presence will be returned . <p > <p / > If the user has several presences ( one for each resource ) then the presence with highest priority will be returned . If multiple presences have the same priority the one with the most available presence mode will be returned . In order that s { @link org . jivesoftware . smack . packet . Presence . Mode#chat free to chat } { @link org . jivesoftware . smack . packet . Presence . Mode#available available } { @link org . jivesoftware . smack . packet . Presence . Mode#away away } { @link org . jivesoftware . smack . packet . Presence . Mode#xa extended away } and { @link org . jivesoftware . smack . packet . Presence . Mode#dnd do not disturb } . <p > <p / > Note that presence information is received asynchronously . So just after logging in to the server presence values for users in the roster may be unavailable even if they are actually online . In other words the value returned by this method should only be treated as a snapshot in time and may not accurately reflect other user s presence instant by instant . If you need to track presence over time such as when showing a visual representation of the roster consider using a { @link RosterListener } .