Merge "Cleanup utility classes"
[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 com.google.common.collect.Multimap
11 import java.util.Collection
12 import java.util.HashSet
13 import java.util.Map.Entry
14 import org.opendaylight.yangtools.concepts.Path
15
16 class MapUtils {
17
18     public static def <P extends Path<P>, V> Collection<Entry<? extends P, ? extends V>> getAllChildren(
19         Multimap<? extends P, ? extends V> map, P path) {
20         val ret = new HashSet();
21         val entries = map.entries;
22
23         for (entry : entries) {
24             val currentPath = entry.key;
25             // If the registered reader processes nested elements
26             if (path.contains(currentPath)) {
27                 ret.add(entry);
28             } else if(currentPath.contains(path)) {
29                 // If the registered reader is parent of entry
30                 ret.add(entry);
31             }
32         }
33
34         return ret;
35     }
36 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.