Merge "Fix the build errors due to the class change of InstanceIdentifier to YangInst...
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / InstanceIdentifierUtils.java
1 package org.opendaylight.controller.cluster.datastore.utils;
2
3 import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
4 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
5
6 import java.util.ArrayList;
7 import java.util.List;
8
9 /**
10  * @author: syedbahm
11  */
12 public class InstanceIdentifierUtils {
13   public static String getParentPath(String currentElementPath) {
14     String parentPath = "";
15
16     if (currentElementPath != null) {
17       String[] parentPaths = currentElementPath.split("/");
18       if (parentPaths.length > 2) {
19         for (int i = 0; i < parentPaths.length - 1; i++) {
20           if (parentPaths[i].length() > 0) {
21             parentPath += "/" + parentPaths[i];
22           }
23         }
24       }
25     }
26     return parentPath;
27   }
28
29   public static InstanceIdentifier from(String path) {
30     String[] ids = path.split("/");
31
32     List<InstanceIdentifier.PathArgument> pathArguments = new ArrayList<>();
33     for (String nodeId : ids) {
34       if (!"".equals(nodeId)) {
35         pathArguments.add(NodeIdentifierFactory.getArgument(nodeId));
36       }
37     }
38     final InstanceIdentifier instanceIdentifier =
39         new InstanceIdentifier(pathArguments);
40     return instanceIdentifier;
41   }
42 }