1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package eu.ehri.project.acl;
21
22 import com.fasterxml.jackson.annotation.JsonCreator;
23 import com.fasterxml.jackson.annotation.JsonValue;
24 import com.google.common.collect.Sets;
25
26 import java.util.Set;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public final class ItemPermissionSet {
42
43 private final Set<PermissionType> set;
44
45 @JsonCreator
46 public static ItemPermissionSet from(Set<PermissionType> set) {
47 return new ItemPermissionSet(set);
48 }
49
50 private ItemPermissionSet(Set<PermissionType> permissionSet) {
51 set = Sets.immutableEnumSet(permissionSet);
52 }
53
54 public boolean has(PermissionType permissionType) {
55 return set.contains(permissionType);
56 }
57
58 @JsonValue
59 public Set<PermissionType> asSet() {
60 return set;
61 }
62
63 @Override
64 public boolean equals(Object o) {
65 if (this == o) return true;
66 if (o == null || getClass() != o.getClass()) return false;
67
68 ItemPermissionSet that = (ItemPermissionSet) o;
69
70 return set.equals(that.set);
71 }
72
73 @Override
74 public int hashCode() {
75 return set.hashCode();
76 }
77
78 @Override
79 public String toString() {
80 return "<ItemPermissions: " + set + ">";
81 }
82 }