summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/util/User.java
blob: 003f4850172af53a26f861e0e7edfcb9121c2da7 (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
package com.vaadin.tests.util;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class User implements Serializable {
    private String name = "";
    private Set<Role> roles = new HashSet<Role>();

    public User() {
    }

    public User(String name) {
        setName(name);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * Returns an unmodifiable set of roles. To modify the roles a user has,
     * replace the whole set using {@link #setRoles(Set)}.
     * 
     * @return set of roles (unmodifiable, not null)
     */
    public Set<Role> getRoles() {
        return Collections.unmodifiableSet(roles);
    }

    /**
     * Replaces the set of roles with another collection. User references in
     * roles are automatically updated when setting the roles of a user.
     * 
     * @param roles
     *            non-null set of roles
     */
    public void setRoles(Set<Role> roles) {
        for (Role role : this.roles) {
            role.getUsers().remove(this);
        }
        this.roles = roles;
        for (Role role : this.roles) {
            role.getUsers().add(this);
        }
    }

}