Merge changes I8c23739a,Ia0e70828
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / util / MapUtils.xtend
1 /*
2  * Copyright (c) 2014 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.util
9
10 import java.util.Map.Entry
11 import org.opendaylight.yangtools.concepts.Path
12 import java.util.Map
13 import java.util.Set
14 import java.util.Collection
15 import java.util.HashSet
16 import com.google.common.collect.Multimap
17
18 class MapUtils {
19
20     public static def <P extends Path<P>, V> Collection<Entry<? extends P, ? extends V>> getAllChildren(
21         Multimap<? extends P, ? extends V> map, P path) {
22         val ret = new HashSet();
23         val entries = map.entries;
24
25         for (entry : entries) {
26             val currentPath = entry.key;
27             // If the registered reader processes nested elements
28             if (path.contains(currentPath)) {
29                 ret.add(entry);
30             } else if(currentPath.contains(path)) {
31                 // If the registered reader is parent of entry
32                 ret.add(entry);
33             }
34         }
35
36         return ret;
37     }
38 }