Convert ListenerRegistrationHelper into a component
[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 package org.opendaylight.openflowplugin.applications.frm.impl;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.concurrent.ConcurrentHashMap;
14 import org.opendaylight.yangtools.yang.common.Uint32;
15
16 public class DevicesGroupRegistry {
17     private final Map<String, List<Uint32>> deviceGroupMapping = new ConcurrentHashMap<>();
18
19     public boolean isGroupPresent(final String nodeId, final Uint32 groupId) {
20         final List<Uint32> groups = deviceGroupMapping.get(nodeId);
21         return groups != null && groups.contains(groupId);
22     }
23
24     public void storeGroup(final String nodeId, final Uint32 groupId) {
25         deviceGroupMapping.computeIfAbsent(nodeId, groupIdList -> new ArrayList<>()).add(groupId);
26     }
27
28     public void removeGroup(final String nodeId, final Uint32 groupId) {
29         deviceGroupMapping.computeIfPresent(nodeId, (node, groupIds) -> groupIds).remove(groupId);
30     }
31
32     public void clearNodeGroups(final String nodeId) {
33         deviceGroupMapping.remove(nodeId);
34     }
35 }