Take advantage of YangInstanceIdentifier methods
[controller.git] / 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);