aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs
diff options
context:
space:
mode:
authorDaniel Gultsch <inputmice@siacs.eu>2015-01-04 00:14:40 +0100
committerDaniel Gultsch <inputmice@siacs.eu>2015-01-04 00:14:40 +0100
commitf338d897535ebc7737a6bc5edb169d9ae41627c1 (patch)
tree73173bf3c75df40cb2b43f9eb42d4b839d0562d6 /src/main/java/eu/siacs
parent4f4eff2353f4e359b5582c8e808a4e88631c3e74 (diff)
no longer use ConcurrentHashMap in favor of synchronize on a final HashMap
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Roster.java46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Roster.java b/src/main/java/eu/siacs/conversations/entities/Roster.java
index 1a81a419..ce058004 100644
--- a/src/main/java/eu/siacs/conversations/entities/Roster.java
+++ b/src/main/java/eu/siacs/conversations/entities/Roster.java
@@ -1,14 +1,14 @@
package eu.siacs.conversations.entities;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
import eu.siacs.conversations.xmpp.jid.Jid;
public class Roster {
final Account account;
- final ConcurrentHashMap<String, Contact> contacts = new ConcurrentHashMap<>();
+ final HashMap<String, Contact> contacts = new HashMap<>();
private String version = null;
public Roster(Account account) {
@@ -19,23 +19,27 @@ public class Roster {
if (jid == null) {
return null;
}
- final Contact contact = contacts.get(jid.toBareJid().toString());
- if (contact != null && contact.showInRoster()) {
- return contact;
- } else {
- return null;
+ synchronized (this.contacts) {
+ Contact contact = contacts.get(jid.toBareJid().toString());
+ if (contact != null && contact.showInRoster()) {
+ return contact;
+ } else {
+ return null;
+ }
}
}
public Contact getContact(final Jid jid) {
- final Jid bareJid = jid.toBareJid();
- if (contacts.containsKey(bareJid.toString())) {
- return contacts.get(bareJid.toString());
- } else {
- final Contact contact = new Contact(bareJid);
- contact.setAccount(account);
- contacts.put(bareJid.toString(), contact);
- return contact;
+ synchronized (this.contacts) {
+ final Jid bareJid = jid.toBareJid();
+ if (contacts.containsKey(bareJid.toString())) {
+ return contacts.get(bareJid.toString());
+ } else {
+ Contact contact = new Contact(bareJid);
+ contact.setAccount(account);
+ contacts.put(bareJid.toString(), contact);
+ return contact;
+ }
}
}
@@ -46,13 +50,13 @@ public class Roster {
}
public void markAllAsNotInRoster() {
- for (final Contact contact : getContacts()) {
+ for (Contact contact : getContacts()) {
contact.resetOption(Contact.Options.IN_ROSTER);
}
}
public void clearSystemAccounts() {
- for (final Contact contact : getContacts()) {
+ for (Contact contact : getContacts()) {
contact.setPhotoUri(null);
contact.setSystemName(null);
contact.setSystemAccount(null);
@@ -60,13 +64,17 @@ public class Roster {
}
public List<Contact> getContacts() {
- return new ArrayList<>(this.contacts.values());
+ synchronized (this.contacts) {
+ return new ArrayList<>(this.contacts.values());
+ }
}
public void initContact(final Contact contact) {
contact.setAccount(account);
contact.setOption(Contact.Options.IN_ROSTER);
- contacts.put(contact.getJid().toBareJid().toString(), contact);
+ synchronized (this.contacts) {
+ contacts.put(contact.getJid().toBareJid().toString(), contact);
+ }
}
public void setVersion(String version) {