1package eu.siacs.conversations.entities;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Locale;
6import java.util.concurrent.ConcurrentHashMap;
7
8public class Roster {
9 Account account;
10 ConcurrentHashMap<String, Contact> contacts = new ConcurrentHashMap<String, Contact>();
11 private String version = null;
12
13 public Roster(Account account) {
14 this.account = account;
15 }
16
17 public boolean hasContact(String jid) {
18 String cleanJid = jid.split("/",2)[0];
19 return contacts.containsKey(cleanJid);
20 }
21
22 public Contact getContact(String jid) {
23 String cleanJid = jid.split("/",2)[0].toLowerCase(Locale.getDefault());
24 if (contacts.containsKey(cleanJid)) {
25 return contacts.get(cleanJid);
26 } else {
27 Contact contact = new Contact(cleanJid);
28 contact.setAccount(account);
29 contacts.put(cleanJid, contact);
30 return contact;
31 }
32 }
33
34 public void clearPresences() {
35 for (Contact contact : getContacts()) {
36 contact.clearPresences();
37 }
38 }
39
40 public void markAllAsNotInRoster() {
41 for (Contact contact : getContacts()) {
42 contact.resetOption(Contact.Options.IN_ROSTER);
43 }
44 }
45
46 public void clearSystemAccounts() {
47 for (Contact contact : getContacts()) {
48 contact.setPhotoUri(null);
49 contact.setSystemName(null);
50 contact.setSystemAccount(null);
51 }
52 }
53
54 public List<Contact> getContacts() {
55 return new ArrayList<Contact>(this.contacts.values());
56 }
57
58 public void initContact(Contact contact) {
59 contact.setAccount(account);
60 contact.setOption(Contact.Options.IN_ROSTER);
61 contacts.put(contact.getJid(), contact);
62 }
63
64 public void setVersion(String version) {
65 this.version = version;
66 }
67
68 public String getVersion() {
69 return this.version;
70 }
71
72 public Account getAccount() {
73 return this.account;
74 }
75}