Roster.java

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