Remove NormalizedNodeStreamReader
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / AugmentationIdentifierGenerator.java
1 /*
2  * Copyright (c) 2014, 2015 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
9 package org.opendaylight.controller.cluster.datastore.node.utils;
10
11 import com.google.common.base.Splitter;
12 import java.util.HashSet;
13 import java.util.Set;
14 import java.util.regex.Matcher;
15 import java.util.regex.Pattern;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18
19 public class AugmentationIdentifierGenerator {
20     private static final Pattern PATTERN = Pattern.compile("AugmentationIdentifier\\Q{\\EchildNames=\\Q[\\E(.*)\\Q]}\\E");
21     private static final Splitter COMMA_SPLITTER = Splitter.on(',').trimResults();
22
23     private final String id;
24     private final Matcher matcher;
25     private final boolean doesMatch;
26
27     public AugmentationIdentifierGenerator(String id) {
28         this.id = id;
29         matcher = PATTERN.matcher(this.id);
30         doesMatch = matcher.matches();
31     }
32
33     public boolean matches() {
34         return doesMatch;
35     }
36
37     public YangInstanceIdentifier.AugmentationIdentifier getPathArgument() {
38         final String childQNames = matcher.group(1);
39
40         final Set<QName> childNames = new HashSet<>();
41         for (String name : COMMA_SPLITTER.split(childQNames)) {
42             childNames.add(QNameFactory.create(name));
43         }
44
45         return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
46     }
47
48 }