Merge "Code refractor and logging improvements"
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / frm / impl / DevicesGroupRegistry.java
1 /*
2  * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.applications.frm.impl;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.concurrent.ConcurrentHashMap;
15 import org.opendaylight.yangtools.yang.common.Uint32;
16
17 public class DevicesGroupRegistry {
18     private final Map<String, List<Uint32>> deviceGroupMapping = new ConcurrentHashMap<>();
19
20     public boolean isGroupPresent(String nodeId, Uint32 groupId) {
21         return deviceGroupMapping.get(nodeId) != null ? deviceGroupMapping.get(nodeId).contains(groupId) : false;
22     }
23
24     public void storeGroup(String nodeId, Uint32 groupId) {
25         deviceGroupMapping.computeIfAbsent(nodeId, groupIdList -> new ArrayList<>()).add(groupId);
26     }
27
28     public void removeGroup(String nodeId, Uint32 groupId) {
29         deviceGroupMapping.computeIfPresent(nodeId, (node, groupIds) -> groupIds).remove(groupId);
30     }
31
32     public void clearNodeGroups(String nodeId) {
33         deviceGroupMapping.remove(nodeId);
34     }
35 }