Code Review
/
nonrtric.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Merge "Version Up & Removed unncessary properties"
[nonrtric.git]
/
policy-agent
/
src
/
main
/
java
/
org
/
oransc
/
policyagent
/
repository
/
Policies.java
diff --git
a/policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java
b/policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java
index
7b7b17c
..
4e2ebfa
100644
(file)
--- a/
policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java
+++ b/
policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java
@@
-21,8
+21,10
@@
package org.oransc.policyagent.repository;
import java.util.Collection;
package org.oransc.policyagent.repository;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
import java.util.Vector;
import org.oransc.policyagent.exceptions.ServiceException;
import java.util.Vector;
import org.oransc.policyagent.exceptions.ServiceException;
@@
-33,9
+35,6
@@
public class Policies {
private Map<String, Map<String, Policy>> policiesService = new HashMap<>();
private Map<String, Map<String, Policy>> policiesType = new HashMap<>();
private Map<String, Map<String, Policy>> policiesService = new HashMap<>();
private Map<String, Map<String, Policy>> policiesType = new HashMap<>();
- public Policies() {
- }
-
public synchronized void put(Policy policy) {
policiesId.put(policy.id(), policy);
multiMapPut(policiesRic, policy.ric().name(), policy);
public synchronized void put(Policy policy) {
policiesId.put(policy.id(), policy);
multiMapPut(policiesRic, policy.ric().name(), policy);
@@
-44,12
+43,7
@@
public class Policies {
}
private void multiMapPut(Map<String, Map<String, Policy>> multiMap, String key, Policy value) {
}
private void multiMapPut(Map<String, Map<String, Policy>> multiMap, String key, Policy value) {
- Map<String, Policy> map = multiMap.get(key);
- if (map == null) {
- map = new HashMap<>();
- multiMap.put(key, map);
- }
- map.put(value.id(), value);
+ multiMap.computeIfAbsent(key, k -> new HashMap<>()).put(value.id(), value);
}
private void multiMapRemove(Map<String, Map<String, Policy>> multiMap, String key, Policy value) {
}
private void multiMapRemove(Map<String, Map<String, Policy>> multiMap, String key, Policy value) {
@@
-65,9
+59,17
@@
public class Policies {
private Collection<Policy> multiMapGet(Map<String, Map<String, Policy>> multiMap, String key) {
Map<String, Policy> map = multiMap.get(key);
if (map == null) {
private Collection<Policy> multiMapGet(Map<String, Map<String, Policy>> multiMap, String key) {
Map<String, Policy> map = multiMap.get(key);
if (map == null) {
- return
new Vector<Policy>
();
+ return
Collections.emptyList
();
}
}
- return map.values();
+ return new Vector<>(map.values());
+ }
+
+ public synchronized boolean containsPolicy(String id) {
+ return policiesId.containsKey(id);
+ }
+
+ public synchronized Policy get(String id) {
+ return policiesId.get(id);
}
public synchronized Policy getPolicy(String id) throws ServiceException {
}
public synchronized Policy getPolicy(String id) throws ServiceException {
@@
-79,7
+81,7
@@
public class Policies {
}
public synchronized Collection<Policy> getAll() {
}
public synchronized Collection<Policy> getAll() {
- return
policiesId.values(
);
+ return
new Vector<>(policiesId.values()
);
}
public synchronized Collection<Policy> getForService(String service) {
}
public synchronized Collection<Policy> getForService(String service) {
@@
-109,14
+111,21
@@
public class Policies {
multiMapRemove(policiesType, policy.type().name(), policy);
}
multiMapRemove(policiesType, policy.type().name(), policy);
}
+ public synchronized void removePoliciesForRic(String ricName) {
+ Collection<Policy> policiesForRic = getForRic(ricName);
+ for (Policy policy : policiesForRic) {
+ remove(policy);
+ }
+ }
+
public synchronized int size() {
return policiesId.size();
}
public synchronized int size() {
return policiesId.size();
}
- public void clear() {
- for (String id : policiesId.keySet()) {
- removeId(id);
+ public synchronized void clear() {
+ while (policiesId.size() > 0) {
+ Set<String> keys = policiesId.keySet();
+ removeId(keys.iterator().next());
}
}
}
}
-
}
}