X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Frepository%2FPolicies.java;fp=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Frepository%2FPolicies.java;h=0000000000000000000000000000000000000000;hb=13c62d122c38b98cbdc76a4a775c6f6187e40e39;hp=4e2ebfa03bae9650787e2b19b900c6b6f5bfe619;hpb=6a39814272307d0207222c9229b0d765ac062bf0;p=nonrtric.git 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 deleted file mode 100644 index 4e2ebfa0..00000000 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Policies.java +++ /dev/null @@ -1,131 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * O-RAN-SC - * %% - * Copyright (C) 2019 Nordix Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ========================LICENSE_END=================================== - */ - -package org.oransc.policyagent.repository; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.Vector; - -import org.oransc.policyagent.exceptions.ServiceException; - -public class Policies { - private Map policiesId = new HashMap<>(); - private Map> policiesRic = new HashMap<>(); - private Map> policiesService = new HashMap<>(); - private Map> policiesType = new HashMap<>(); - - public synchronized void put(Policy policy) { - policiesId.put(policy.id(), policy); - multiMapPut(policiesRic, policy.ric().name(), policy); - multiMapPut(policiesService, policy.ownerServiceName(), policy); - multiMapPut(policiesType, policy.type().name(), policy); - } - - private void multiMapPut(Map> multiMap, String key, Policy value) { - multiMap.computeIfAbsent(key, k -> new HashMap<>()).put(value.id(), value); - } - - private void multiMapRemove(Map> multiMap, String key, Policy value) { - Map map = multiMap.get(key); - if (map != null) { - map.remove(value.id()); - if (map.isEmpty()) { - multiMap.remove(key); - } - } - } - - private Collection multiMapGet(Map> multiMap, String key) { - Map map = multiMap.get(key); - if (map == null) { - return Collections.emptyList(); - } - 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 { - Policy p = policiesId.get(id); - if (p == null) { - throw new ServiceException("Could not find policy: " + id); - } - return p; - } - - public synchronized Collection getAll() { - return new Vector<>(policiesId.values()); - } - - public synchronized Collection getForService(String service) { - return multiMapGet(policiesService, service); - } - - public synchronized Collection getForRic(String ric) { - return multiMapGet(policiesRic, ric); - } - - public synchronized Collection getForType(String type) { - return multiMapGet(policiesType, type); - } - - public synchronized Policy removeId(String id) { - Policy p = policiesId.get(id); - if (p != null) { - remove(p); - } - return p; - } - - public synchronized void remove(Policy policy) { - policiesId.remove(policy.id()); - multiMapRemove(policiesRic, policy.ric().name(), policy); - multiMapRemove(policiesService, policy.ownerServiceName(), policy); - multiMapRemove(policiesType, policy.type().name(), policy); - } - - public synchronized void removePoliciesForRic(String ricName) { - Collection policiesForRic = getForRic(ricName); - for (Policy policy : policiesForRic) { - remove(policy); - } - } - - public synchronized int size() { - return policiesId.size(); - } - - public synchronized void clear() { - while (policiesId.size() > 0) { - Set keys = policiesId.keySet(); - removeId(keys.iterator().next()); - } - } -}