code: public List<Presence> getPresences(BareJid jid) {
          List<Presence> res;
          Map<Resourcepart, Presence> userPresences = getPresencesInternal(jid);
          if (userPresences == null) {
              Presence presence = new Presence(Presence.Type.unavailable);
              presence.setFrom(jid);
              res = Arrays.asList(presence);
          }
          else {
              List<Presence> answer = new ArrayList<>();
              // Used in case no available presence is found
              Presence unavailable = null;
              for (Presence presence : userPresences.values()) {
                  if (presence.isAvailable()) {
                      answer.add(presence.clone());
                  }
                  else {
                      unavailable = presence;
                  }
              }
              if (!answer.isEmpty()) {
                  res = answer;
              }
              else if (unavailable != null) {
                  res = Arrays.asList(unavailable.clone());
              }
              else {
                  Presence presence = new Presence(Presence.Type.unavailable);
                  presence.setFrom(jid);
                  res = Arrays.asList(presence);
              }
          }
          return res;
      }
docs: Returns a List of Presence objects for all of a user's current presences
  or an unavailable presence if the user is unavailable (offline) or if no presence
  information is available, such as when you are not subscribed to the user's presence
  updates.
  
  @param jid an XMPP ID, e.g. jdoe@example.com.
  @return a List of Presence objects for all the user's current presences,
  or an unavailable presence if the user is offline or if no presence information
  is available.