/*
 *
 *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 *  This program and the accompanying materials are made available under the
 *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
 *  and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 */

package org.opendaylight.controller.cluster.datastore.node.utils;

import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AugmentationIdentifierGenerator {
    private final String id;
    private static final Pattern pattern = Pattern.compile("AugmentationIdentifier\\Q{\\EchildNames=\\Q[\\E(.*)\\Q]}\\E");
    private final Matcher matcher;
    private final boolean doesMatch;

    public AugmentationIdentifierGenerator(String id){
        this.id = id;
        matcher = pattern.matcher(this.id);
        doesMatch = matcher.matches();
    }

    public boolean matches(){
        return doesMatch;
    }

    public YangInstanceIdentifier.AugmentationIdentifier getPathArgument(){
        Set<QName> childNames = new HashSet<QName>();
        final String childQNames = matcher.group(1);

        final String[] splitChildQNames = childQNames.split(",");

        for(String name : splitChildQNames){
            childNames.add(
                org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory
                    .create(name.trim()));
        }

        return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
    }

}

@@ -390,127 +390,41 @@
 ort 
-org.opendaylight.yangtools.yang.common.QName;%0Aimport org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifi
+com.google.common.base.Splitt
 er;%0A
-%0A
 impo
@@ -530,16 +530,141 @@
 Pattern;
+%0Aimport org.opendaylight.yangtools.yang.common.QName;%0Aimport org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 %0A%0Apublic
@@ -708,37 +708,8 @@
 r %7B%0A
-    private final String id;%0A
     
@@ -737,23 +737,23 @@
 Pattern 
-pattern
+PATTERN
  = Patte
@@ -827,16 +827,129 @@
 %7D%5C%5CE%22);%0A
+    private static final Splitter COMMA_SPLITTER = Splitter.on(',').trimResults();%0A%0A    private final String id;%0A
     priv
@@ -1066,16 +1066,17 @@
 ring id)
+ 
 %7B%0A      
@@ -1113,15 +1113,15 @@
 r = 
-pattern
+PATTERN
 .mat
@@ -1209,16 +1209,17 @@
 atches()
+ 
 %7B%0A      
@@ -1323,63 +1323,10 @@
 nt()
+ 
 %7B
-%0A        Set%3CQName%3E childNames = new HashSet%3CQName%3E();
 %0A   
@@ -1395,60 +1395,48 @@
 al S
-tring%5B%5D splitChild
+et%3C
 QName
-s =
+%3E
  child
-Q
 Names
-.split(%22,%22
+ = new HashSet%3C%3E(
 );%0A
-%0A
     
@@ -1442,16 +1442,17 @@
      for
+ 
 (String 
@@ -1462,14 +1462,30 @@
 e : 
+COMMA_SPLITTER.
 split
-C
+(c
 hild
@@ -1491,16 +1491,18 @@
 dQNames)
+) 
 %7B%0A      
@@ -1526,115 +1526,20 @@
 add(
-%0A                org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory%0A                    
+QNameFactory
 .cre
@@ -1550,15 +1550,8 @@
 name
-.trim()
 ));%0A

Optimize AugmentationIdentifierGenerator.getPathArguments()