aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/entities/Room.java
blob: d41cbe2f23ff0f913fdf712b14444665db8bbea1 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package de.pixart.messenger.entities;

import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.ComparisonChain;

import de.pixart.messenger.services.AvatarService;
import de.pixart.messenger.utils.LanguageUtils;
import de.pixart.messenger.utils.UIHelper;
import rocks.xmpp.addr.Jid;

public class Room implements AvatarService.Avatarable, Comparable<Room> {

    public String address;
    public String name;
    public String description;
    public String language;
    public int nusers;

    public Room(String address, String name, String description, String language, int nusers) {
        this.address = address;
        this.name = name;
        this.description = description;
        this.language = language;
        this.nusers = nusers;
    }

    public Room() {

    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public Jid getRoom() {
        try {
            return Jid.of(address);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    public String getLanguage() {
        return LanguageUtils.convert(language);
    }

    @Override
    public int getAvatarBackgroundColor() {
        Jid room = getRoom();
        return UIHelper.getColorForName(room != null ? room.asBareJid().toEscapedString() : name);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Room room = (Room) o;
        return Objects.equal(address, room.address) &&
                Objects.equal(name, room.name) &&
                Objects.equal(description, room.description);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(address, name, description);
    }


    public boolean contains(String needle) {
        return Strings.nullToEmpty(name).contains(needle)
                || Strings.nullToEmpty(description).contains(needle)
                || Strings.nullToEmpty(address).contains(needle);
    }

    @Override
    public int compareTo(Room o) {
        return ComparisonChain.start()
                .compare(o.nusers, nusers)
                .compare(Strings.nullToEmpty(name), Strings.nullToEmpty(o.name))
                .compare(Strings.nullToEmpty(address), Strings.nullToEmpty(o.address))
                .result();
    }
}