aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/entities/Presences.java
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-03-06 19:42:55 +0100
committerlookshe <github@lookshe.org>2016-03-06 19:42:55 +0100
commit3c400703e082a1b180b35d891b8fb3460c7d5b87 (patch)
tree28738dd90fc41b4ab71897f38d324828778ad2e3 /src/main/java/de/thedevstack/conversationsplus/entities/Presences.java
parent72114d732427266024cdd6e27cd8d1aa60afae2f (diff)
parentf28d77dc42f6bac5a026e0b1c78562dee8de45ac (diff)
Merge branch 'trz/rebase' into trz/rename
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/entities/Presences.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/entities/Presences.java49
1 files changed, 8 insertions, 41 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/Presences.java b/src/main/java/de/thedevstack/conversationsplus/entities/Presences.java
index cb984648..d32e931c 100644
--- a/src/main/java/de/thedevstack/conversationsplus/entities/Presences.java
+++ b/src/main/java/de/thedevstack/conversationsplus/entities/Presences.java
@@ -1,29 +1,18 @@
package de.thedevstack.conversationsplus.entities;
+import java.util.Collections;
import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map.Entry;
-
-import de.thedevstack.conversationsplus.xml.Element;
public class Presences {
+ private final Hashtable<String, Presence> presences = new Hashtable<>();
- public static final int CHAT = -1;
- public static final int ONLINE = 0;
- public static final int AWAY = 1;
- public static final int XA = 2;
- public static final int DND = 3;
- public static final int OFFLINE = 4;
-
- private Hashtable<String, Integer> presences = new Hashtable<String, Integer>();
-
- public Hashtable<String, Integer> getPresences() {
+ public Hashtable<String, Presence> getPresences() {
return this.presences;
}
- public void updatePresence(String resource, int status) {
+ public void updatePresence(String resource, Presence presence) {
synchronized (this.presences) {
- this.presences.put(resource, status);
+ this.presences.put(resource, presence);
}
}
@@ -39,32 +28,10 @@ public class Presences {
}
}
- public int getMostAvailableStatus() {
- int status = OFFLINE;
+ public Presence getMostAvailablePresence() {
synchronized (this.presences) {
- Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
- while (it.hasNext()) {
- Entry<String, Integer> entry = it.next();
- if (entry.getValue() < status)
- status = entry.getValue();
- }
- }
- return status;
- }
-
- public static int parseShow(Element show) {
- if ((show == null) || (show.getContent() == null)) {
- return Presences.ONLINE;
- } else if (show.getContent().equals("away")) {
- return Presences.AWAY;
- } else if (show.getContent().equals("xa")) {
- return Presences.XA;
- } else if (show.getContent().equals("chat")) {
- return Presences.CHAT;
- } else if (show.getContent().equals("dnd")) {
- return Presences.DND;
- } else {
- return Presences.OFFLINE;
+ if (presences.size() < 1) { return null; }
+ return Collections.min(presences.values());
}
}