Fix findbugs violations in restconf-nb-rfc8040
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / codecs / RestCodec.java
index 7c92625538268c9d35fc325499c57b8b220139ed..4d9ee346e26740674d53e37a25c6397fd1623dae 100644 (file)
@@ -11,10 +11,11 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
+import java.util.Map.Entry;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.restconf.common.util.IdentityValuesDTO;
 import org.opendaylight.restconf.common.util.IdentityValuesDTO.IdentityValue;
@@ -32,7 +33,7 @@ import org.opendaylight.yangtools.yang.data.api.codec.InstanceIdentifierCodec;
 import org.opendaylight.yangtools.yang.data.api.codec.LeafrefCodec;
 import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -49,14 +50,14 @@ import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class RestCodec {
+public final class RestCodec {
 
     private static final Logger LOG = LoggerFactory.getLogger(RestCodec.class);
 
     private RestCodec() {
     }
 
-    public static final Codec<Object, Object> from(final TypeDefinition<?> typeDefinition,
+    public static Codec<Object, Object> from(final TypeDefinition<?> typeDefinition,
             final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
         return new ObjectCodec(typeDefinition, mountPoint, schemaContext);
     }
@@ -325,8 +326,9 @@ public class RestCodec {
 
         private static List<Predicate> keyValuesToPredicateList(final Map<QName, Object> keyValues) {
             final List<Predicate> result = new ArrayList<>();
-            for (final QName qualifiedName : keyValues.keySet()) {
-                final Object value = keyValues.get(qualifiedName);
+            for (final Entry<QName, Object> entry : keyValues.entrySet()) {
+                final QName qualifiedName = entry.getKey();
+                final Object value = entry.getValue();
                 result.add(new Predicate(qNameToIdentityValue(qualifiedName), String.valueOf(value)));
             }
             return result;
@@ -345,9 +347,9 @@ public class RestCodec {
         final URI validNamespace = resolveValidNamespace(namespace, mountPoint, schemaContext);
         Module module = null;
         if (mountPoint != null) {
-            module = mountPoint.getSchemaContext().findModuleByNamespace(validNamespace).iterator().next();
+            module = mountPoint.getSchemaContext().findModules(validNamespace).iterator().next();
         } else {
-            module = schemaContext.findModuleByNamespace(validNamespace).iterator().next();
+            module = schemaContext.findModules(validNamespace).iterator().next();
         }
         if (module == null) {
             LOG.info("Module for namespace " + validNamespace + " wasn't found.");
@@ -356,10 +358,11 @@ public class RestCodec {
         return module;
     }
 
-    private static URI resolveValidNamespace(final String namespace, final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
+    private static URI resolveValidNamespace(final String namespace, final DOMMountPoint mountPoint,
+            final SchemaContext schemaContext) {
         URI validNamespace;
         if (mountPoint != null) {
-            validNamespace = findFirstModuleByName(schemaContext, namespace);
+            validNamespace = findFirstModuleByName(mountPoint.getSchemaContext(), namespace);
         } else {
             validNamespace = findFirstModuleByName(schemaContext, namespace);
         }
@@ -384,7 +387,7 @@ public class RestCodec {
         Preconditions.checkNotNull(namespace);
 
         final Iterable<DataSchemaNode> result = Iterables.filter(findInstanceDataChildrenByName(container, name),
-                node -> namespace.equals(node.getQName().getNamespace()));
+            node -> namespace.equals(node.getQName().getNamespace()));
         return Iterables.getFirst(result, null);
     }
 
@@ -414,15 +417,16 @@ public class RestCodec {
 
         final Iterable<ChoiceSchemaNode> choiceNodes =
                 Iterables.filter(container.getChildNodes(), ChoiceSchemaNode.class);
-        final Iterable<Set<ChoiceCaseNode>> map = Iterables.transform(choiceNodes, ChoiceSchemaNode::getCases);
-        for (final ChoiceCaseNode caze : Iterables.concat(map)) {
+        final Iterable<Collection<CaseSchemaNode>> map = Iterables.transform(choiceNodes,
+            choice -> choice.getCases().values());
+        for (final CaseSchemaNode caze : Iterables.concat(map)) {
             collectInstanceDataNodeContainers(potentialSchemaNodes, caze, name);
         }
     }
 
     private static boolean isInstantiatedDataSchema(final DataSchemaNode node) {
-        return (node instanceof LeafSchemaNode) || (node instanceof LeafListSchemaNode)
-                || (node instanceof ContainerSchemaNode) || (node instanceof ListSchemaNode)
-                || (node instanceof AnyXmlSchemaNode);
+        return node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode
+                || node instanceof ContainerSchemaNode || node instanceof ListSchemaNode
+                || node instanceof AnyXmlSchemaNode;
     }
 }