Take advantage of YangInstanceIdentifier methods
authorRobert Varga <rovarga@cisco.com>
Fri, 22 May 2015 16:14:47 +0000 (18:14 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 8 Jun 2015 09:00:50 +0000 (09:00 +0000)
YangInstanceIdentifier provides new, fast methods to acquire parent,
check if it empty and size of path arguments. Take advantage of them.

Change-Id: I527ff8cefb2799cb188ffe294c69e3b81a0d6909
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit ad7a6537b709a72e763835cae683b8cc12401ce1)

opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java

index 08ba91fe8553970542440d36710112774bd659f9..f07dda0cec44333afc3219701e1dd6b6c7263d53 100644 (file)
@@ -30,7 +30,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -541,7 +540,7 @@ public class RestconfImpl implements RestconfService {
 
         final YangInstanceIdentifier pathIdentifier = ((YangInstanceIdentifier) pathValue);
         String streamName = null;
-        if (!Iterables.isEmpty(pathIdentifier.getPathArguments())) {
+        if (!pathIdentifier.isEmpty()) {
             final String fullRestconfIdentifier = controllerContext.toFullRestconfIdentifier(pathIdentifier, null);
 
             LogicalDatastoreType datastore = parseEnumTypeParameter(value, LogicalDatastoreType.class,
@@ -785,19 +784,18 @@ public class RestconfImpl implements RestconfService {
             final YangInstanceIdentifier identifier) {
 
         final String payloadName = node.getData().getNodeType().getLocalName();
-        final Iterator<PathArgument> pathArguments = identifier.getReversePathArguments().iterator();
 
         //no arguments
-        if ( ! pathArguments.hasNext()) {
+        if (identifier.isEmpty()) {
             //no "data" payload
-            if ( ! node.getData().getNodeType().equals(NETCONF_BASE_QNAME)) {
+            if (!node.getData().getNodeType().equals(NETCONF_BASE_QNAME)) {
                 throw new RestconfDocumentedException("Instance identifier has to contain at least one path argument",
                         ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
             }
         //any arguments
         } else {
-            final String identifierName = pathArguments.next().getNodeType().getLocalName();
-            if ( ! payloadName.equals(identifierName)) {
+            final String identifierName = identifier.getLastPathArgument().getNodeType().getLocalName();
+            if (!payloadName.equals(identifierName)) {
                 throw new RestconfDocumentedException("Payload name (" + payloadName
                         + ") is different from identifier name (" + identifierName + ")", ErrorType.PROTOCOL,
                         ErrorTag.MALFORMED_MESSAGE);