aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/entities/Roster.java
blob: 7c18d80aac3b5ff627628395522b1437eae32076 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package eu.siacs.conversations.entities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Roster {
	Account account;
	HashMap<String, Contact> contacts = new HashMap<String, Contact>();
	private String version = null;
	
	public Roster(Account account) {
		this.account = account;
	}
	
	public boolean hasContact(String jid) {
		String cleanJid = jid.split("/")[0];
		return contacts.containsKey(cleanJid);
	}
	
	public Contact getContact(String jid) {
		String cleanJid = jid.split("/")[0];
		if (contacts.containsKey(cleanJid)) {
			return contacts.get(cleanJid);
		} else {
			Contact contact = new Contact(cleanJid);
			contact.setAccount(account);
			contacts.put(cleanJid, contact);
			return contact;
		}
	}

	public void clearPresences() {
		// TODO Auto-generated method stub
		
	}
	
	public void markAllAsNotInRoster() {
		
	}

	public List<Contact> getContacts() {
		return new ArrayList<Contact>(this.contacts.values());
	}

	public void initContact(Contact contact) {
		contact.setAccount(account);
		contact.setOption(Contact.Options.IN_ROSTER);
		contacts.put(contact.getJid(),contact);
	}

	public void setVersion(String version) {
		this.version = version;
	}
	
	public String getVersion() {
		return this.version;
	}

	public Account getAccount() {
		return this.account;
	}
}