Merge "ISSUE Opendaylight controller to get node description from OF description...
[controller.git] / opendaylight / sal / yang-prototype / sal / sal-broker-impl / src / main / java / org / opendaylight / controller / sal / core / impl / Utils.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.controller.sal.core.impl;\r
9 \r
10 import java.util.ArrayList;\r
11 import java.util.List;\r
12 import java.util.Map;\r
13 \r
14 import org.opendaylight.controller.yang.common.QName;\r
15 \r
16 \r
17 public class Utils {\r
18 \r
19     public static <T> void addToMap(Map<QName, List<T>> map, QName key, T value) {\r
20         List<T> list = map.get(key);\r
21         if (list == null) {\r
22             list = new ArrayList<T>();\r
23             map.put(key, list);\r
24         }\r
25         list.add(value);\r
26     }\r
27 \r
28     public static <T> void removeFromMap(Map<QName, List<T>> map, QName key,\r
29             T value) {\r
30         List<T> list = map.get(key);\r
31         if (list == null) {\r
32             return;\r
33         }\r
34         list.remove(value);\r
35         if (list.isEmpty()) {\r
36             map.remove(key);\r
37         }\r
38     }\r
39 }\r
40