1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.common.lib.types;
20
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.HashSet;
24 import java.util.Set;
25
26 public final class EntitlementsHolder {
27
28 private static final Object MONITOR = new Object();
29
30 private static EntitlementsHolder INSTANCE;
31
32 public static EntitlementsHolder getInstance() {
33 synchronized (MONITOR) {
34 if (INSTANCE == null) {
35 INSTANCE = new EntitlementsHolder();
36 }
37 }
38 return INSTANCE;
39 }
40
41 private final Set<String> values = Collections.synchronizedSet(new HashSet<>());
42
43 private EntitlementsHolder() {
44
45 }
46
47 public void addAll(final Collection<String> values) {
48 this.values.addAll(values);
49 }
50
51 public Set<String> addFor(final String anyType) {
52 Set<String> added = new HashSet<>();
53
54 for (AnyEntitlement operation : AnyEntitlement.values()) {
55 this.values.add(operation.getFor(anyType));
56 added.add(operation.getFor(anyType));
57 }
58
59 return added;
60 }
61
62 public Set<String> removeFor(final String anyType) {
63 Set<String> removed = new HashSet<>();
64
65 for (AnyEntitlement operation : AnyEntitlement.values()) {
66 this.values.remove(operation.getFor(anyType));
67 removed.add(operation.getFor(anyType));
68 }
69
70 return removed;
71 }
72
73 public Set<String> getValues() {
74 return Collections.unmodifiableSet(values);
75 }
76 }