e174559c88c2a269121e52827ce3bd21e41fab26
[controller.git] / opendaylight / sal / yang-prototype / sal / sal-binding-broker-impl / src / main / java / org / opendaylight / controller / sal / binding / impl / BrokerUtils.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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.controller.sal.binding.impl;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.Map;
13
14 public class BrokerUtils {
15     private BrokerUtils() {
16         
17     }
18     
19     
20     public static <K,V> void addToMap(Map<Class<? extends K>, List<V>> map, Class<? extends K> key, V value) {
21         List<V> list = map.get(key);
22         if (list == null) {
23             list = new ArrayList<V>();
24             map.put(key, list);
25         }
26         list.add(value);
27     }
28
29     public static <K,V> void removeFromMap(Map<Class<? extends K>, List<V>> map, Class<? extends K> key,
30             V value) {
31         List<V> list = map.get(key);
32         if (list == null) {
33             return;
34         }
35         list.remove(value);
36         if (list.isEmpty()) {
37             map.remove(key);
38         }
39     }
40 }