Use NormalizedNode streaming serialization in sal-remoterpc-connector
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / NodeIdentifierWithValueGenerator.java
index 2d434fffcfe8b9f538aa51f828a382498f21e9bd..6ecf9050c365ee54698cf7813aef8e09114467ce 100644 (file)
@@ -1,58 +1,55 @@
 /*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
- *  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
- *
+ * 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 java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+public class NodeIdentifierWithValueGenerator {
+    private static final Pattern PATTERN = Pattern.compile("(.*)\\Q[\\E(.*)\\Q]\\E");
 
-public class NodeIdentifierWithValueGenerator{
-        private final String id;
+    private final String id;
     private final DataSchemaNode schemaNode;
-    private static final Pattern pattern = Pattern.compile("(.*)\\Q[\\E(.*)\\Q]\\E");
-        private final Matcher matcher;
-        private final boolean doesMatch;
-
-        public NodeIdentifierWithValueGenerator(String id, DataSchemaNode schemaNode){
-            this.id = id;
-            this.schemaNode = schemaNode;
-            matcher = pattern.matcher(this.id);
-            doesMatch = matcher.matches();
-        }
+    private final Matcher matcher;
+    private final boolean doesMatch;
+
+    public NodeIdentifierWithValueGenerator(String id, DataSchemaNode schemaNode) {
+        this.id = id;
+        this.schemaNode = schemaNode;
+        matcher = PATTERN.matcher(this.id);
+        doesMatch = matcher.matches();
+    }
 
-        public boolean matches(){
-            return doesMatch;
-        }
+    public boolean matches() {
+        return doesMatch;
+    }
 
-        public YangInstanceIdentifier.PathArgument getPathArgument(){
-            final String name = matcher.group(1);
-            final String value = matcher.group(2);
+    public YangInstanceIdentifier.PathArgument getPathArgument() {
+        final String name = matcher.group(1);
+        final String value = matcher.group(2);
 
-            return new YangInstanceIdentifier.NodeWithValue(
-                QNameFactory.create(name), getValue(value));
-        }
+        return new YangInstanceIdentifier.NodeWithValue<>(QNameFactory.create(name), getValue(value));
+    }
 
-        private Object getValue(String value){
-            if(schemaNode != null){
-                if(schemaNode instanceof LeafListSchemaNode){
-                    return TypeDefinitionAwareCodec
-                        .from(LeafListSchemaNode.class.cast(schemaNode).getType()).deserialize(value);
+    private Object getValue(String value) {
+        if (schemaNode != null) {
+            if (schemaNode instanceof LeafListSchemaNode) {
+                return TypeDefinitionAwareCodec.from(LeafListSchemaNode.class.cast(schemaNode).getType())
+                        .deserialize(value);
 
-                }
             }
-        return value;
         }
-
+        return value;
     }
+
+}