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.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
16 import org.opendaylight.yangtools.yang.common.Uint32;
17
18 public class DevicesGroupRegistry {
19     private final Map<NodeId, List<Uint32>> deviceGroupMapping = new ConcurrentHashMap<>();
20
21     public boolean isGroupPresent(NodeId nodeId, Uint32 groupId) {
22         return deviceGroupMapping.get(nodeId) != null ? deviceGroupMapping.get(nodeId).contains(groupId) : false;
23     }
24
25     public void storeGroup(NodeId nodeId, Uint32 groupId) {
26         deviceGroupMapping.computeIfAbsent(nodeId, groupIdList -> new ArrayList<>()).add(groupId);
27     }
28
29     public void removeGroup(NodeId nodeId, Uint32 groupId) {
30         deviceGroupMapping.computeIfPresent(nodeId, (node, groupIds) -> groupIds).remove(groupId);
31     }
32
33     public void clearNodeGroups(NodeId nodeId) {
34         deviceGroupMapping.remove(nodeId);
35     }
36
37 }