2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.entities;
|
|
|
|
|
2016-01-17 21:28:38 +00:00
|
|
|
import java.util.Collections;
|
2014-10-22 16:38:44 +00:00
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.xml.Element;
|
|
|
|
|
|
|
|
public class Presences {
|
2016-01-17 21:28:38 +00:00
|
|
|
private final Hashtable<String, Presence> presences = new Hashtable<>();
|
2014-10-22 16:38:44 +00:00
|
|
|
|
2016-01-17 21:28:38 +00:00
|
|
|
public Hashtable<String, Presence> getPresences() {
|
2014-10-22 16:38:44 +00:00
|
|
|
return this.presences;
|
|
|
|
}
|
|
|
|
|
2016-01-17 21:28:38 +00:00
|
|
|
public void updatePresence(String resource, Presence presence) {
|
2014-11-13 13:44:19 +00:00
|
|
|
synchronized (this.presences) {
|
2016-01-17 21:28:38 +00:00
|
|
|
this.presences.put(resource, presence);
|
2014-11-13 13:44:19 +00:00
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removePresence(String resource) {
|
2014-11-13 13:44:19 +00:00
|
|
|
synchronized (this.presences) {
|
|
|
|
this.presences.remove(resource);
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clearPresences() {
|
2014-11-13 13:44:19 +00:00
|
|
|
synchronized (this.presences) {
|
|
|
|
this.presences.clear();
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 21:28:38 +00:00
|
|
|
public Presence getMostAvailablePresence() {
|
2014-11-13 13:44:19 +00:00
|
|
|
synchronized (this.presences) {
|
2016-01-17 21:28:38 +00:00
|
|
|
if (presences.size() < 1) { return null; }
|
|
|
|
return Collections.min(presences.values());
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int size() {
|
2014-11-13 13:44:19 +00:00
|
|
|
synchronized (this.presences) {
|
|
|
|
return presences.size();
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String[] asStringArray() {
|
2014-11-13 13:44:19 +00:00
|
|
|
synchronized (this.presences) {
|
|
|
|
final String[] presencesArray = new String[presences.size()];
|
|
|
|
presences.keySet().toArray(presencesArray);
|
|
|
|
return presencesArray;
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean has(String presence) {
|
2014-11-13 13:44:19 +00:00
|
|
|
synchronized (this.presences) {
|
|
|
|
return presences.containsKey(presence);
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|