mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 22:12:05 +01:00
Code cleanup.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2409 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
fdb4b017ff
commit
e1f47c181f
1 changed files with 23 additions and 14 deletions
|
@ -484,7 +484,7 @@ public class Roster {
|
||||||
public Presence getPresenceResource(String userResource) {
|
public Presence getPresenceResource(String userResource) {
|
||||||
String key = getPresenceMapKey(userResource);
|
String key = getPresenceMapKey(userResource);
|
||||||
String resource = StringUtils.parseResource(userResource);
|
String resource = StringUtils.parseResource(userResource);
|
||||||
Map userPresences = (Map) presenceMap.get(key);
|
Map userPresences = (Map)presenceMap.get(key);
|
||||||
if (userPresences == null) {
|
if (userPresences == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -494,22 +494,25 @@ public class Roster {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an iterator for all the user's current presences or <tt>null</tt> if the user
|
* Returns an iterator (of Presence objects) for all the user's current presences
|
||||||
* is unavailable (offline) or if no presence information is available, such as
|
* or <tt>null</tt> if the user is unavailable (offline) or if no presence information
|
||||||
* when you are not subscribed to the user's presence updates.
|
* is available, such as when you are not subscribed to the user's presence updates.
|
||||||
*
|
*
|
||||||
* @param user a fully qualified xmpp ID, e.g. jdoe@example.com
|
* @param user a fully qualified xmpp ID, e.g. jdoe@example.com
|
||||||
* @return an iterator for all the user's current presences, or <tt>null</tt> if the user is
|
* @return an iterator (of Presence objects) for all the user's current presences,
|
||||||
* unavailable or if no presence information is available.
|
* or <tt>null</tt> if the user is unavailable or if no presence information
|
||||||
|
* is available.
|
||||||
*/
|
*/
|
||||||
public Iterator getPresences(String user) {
|
public Iterator getPresences(String user) {
|
||||||
String key = getPresenceMapKey(user);
|
String key = getPresenceMapKey(user);
|
||||||
Map userPresences = (Map) presenceMap.get(key);
|
Map userPresences = (Map)presenceMap.get(key);
|
||||||
if (userPresences == null) {
|
if (userPresences == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return userPresences.values().iterator();
|
synchronized (userPresences) {
|
||||||
|
return new HashMap(userPresences).values().iterator();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -577,11 +580,14 @@ public class Roster {
|
||||||
if (presenceMap.get(key) == null) {
|
if (presenceMap.get(key) == null) {
|
||||||
userPresences = new HashMap();
|
userPresences = new HashMap();
|
||||||
presenceMap.put(key, userPresences);
|
presenceMap.put(key, userPresences);
|
||||||
} else {
|
|
||||||
userPresences = (Map) presenceMap.get(key);
|
|
||||||
}
|
}
|
||||||
// Add the new presence taking in consideration the presence´s resource
|
else {
|
||||||
|
userPresences = (Map)presenceMap.get(key);
|
||||||
|
}
|
||||||
|
// Add the new presence, using the resources as a key.
|
||||||
|
synchronized (userPresences) {
|
||||||
userPresences.put(StringUtils.parseResource(from), presence);
|
userPresences.put(StringUtils.parseResource(from), presence);
|
||||||
|
}
|
||||||
// If the user is in the roster, fire an event.
|
// If the user is in the roster, fire an event.
|
||||||
synchronized (entries) {
|
synchronized (entries) {
|
||||||
for (Iterator i = entries.iterator(); i.hasNext();) {
|
for (Iterator i = entries.iterator(); i.hasNext();) {
|
||||||
|
@ -596,7 +602,9 @@ public class Roster {
|
||||||
else if (presence.getType() == Presence.Type.UNAVAILABLE) {
|
else if (presence.getType() == Presence.Type.UNAVAILABLE) {
|
||||||
if (presenceMap.get(key) != null) {
|
if (presenceMap.get(key) != null) {
|
||||||
Map userPresences = (Map) presenceMap.get(key);
|
Map userPresences = (Map) presenceMap.get(key);
|
||||||
|
synchronized (userPresences) {
|
||||||
userPresences.remove(StringUtils.parseResource(from));
|
userPresences.remove(StringUtils.parseResource(from));
|
||||||
|
}
|
||||||
if (userPresences.isEmpty()) {
|
if (userPresences.isEmpty()) {
|
||||||
presenceMap.remove(key);
|
presenceMap.remove(key);
|
||||||
}
|
}
|
||||||
|
@ -663,7 +671,8 @@ public class Roster {
|
||||||
// Make sure the entry is in the entry list.
|
// Make sure the entry is in the entry list.
|
||||||
if (!entries.contains(entry)) {
|
if (!entries.contains(entry)) {
|
||||||
entries.add(entry);
|
entries.add(entry);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// If the entry was in then list then update its state with the new values
|
// If the entry was in then list then update its state with the new values
|
||||||
RosterEntry existingEntry =
|
RosterEntry existingEntry =
|
||||||
(RosterEntry) entries.get(entries.indexOf(entry));
|
(RosterEntry) entries.get(entries.indexOf(entry));
|
||||||
|
|
Loading…
Reference in a new issue