BUG-1092: adjust to YangInstanceIdentifier
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / NodeIdentifierWithValueGenerator.java
1 package org.opendaylight.controller.cluster.datastore.node.utils;
2
3 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
4
5 import java.util.regex.Matcher;
6 import java.util.regex.Pattern;
7
8 public class NodeIdentifierWithValueGenerator{
9         private final String id;
10         private static final Pattern pattern = Pattern.compile("(.*)\\Q[\\E(.*)\\Q]\\E");
11         private final Matcher matcher;
12         private final boolean doesMatch;
13
14         public NodeIdentifierWithValueGenerator(String id){
15             this.id = id;
16             matcher = pattern.matcher(this.id);
17             doesMatch = matcher.matches();
18         }
19
20         public boolean matches(){
21             return doesMatch;
22         }
23
24         public YangInstanceIdentifier.PathArgument getPathArgument(){
25             final String name = matcher.group(1);
26             final String value = matcher.group(2);
27
28             return new YangInstanceIdentifier.NodeWithValue(
29                 QNameFactory.create(name), value);
30         }
31     }