Reduce casts a bit 52/107152/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 31 Jul 2023 16:01:19 +0000 (18:01 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Tue, 1 Aug 2023 07:04:32 +0000 (07:04 +0000)
Use instanceof patterns to reduce explicit casts.

Change-Id: I2d06c9702c6d3f9cdadb84c5bce0506ffe98566d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/BaseYangOpenApiGenerator.java

index e498fe4c9da06313a85d2e53f6c20e010de68748..bde578914369b2a1a12cdc84c0eb1746f7f3c62a 100644 (file)
@@ -304,14 +304,13 @@ public abstract class BaseYangOpenApiGenerator {
         final List<Parameter> pathParams = new ArrayList<>(parentPathParams);
         Iterable<? extends DataSchemaNode> childSchemaNodes = Collections.emptySet();
         if (node instanceof ListSchemaNode || node instanceof ContainerSchemaNode) {
-            final DataNodeContainer dataNodeContainer = (DataNodeContainer) node;
-            childSchemaNodes = dataNodeContainer.getChildNodes();
+            childSchemaNodes = ((DataNodeContainer) node).getChildNodes();
         }
         paths.put(dataPath, operations(node, moduleName, deviceName, pathParams, isConfig, parentName,
                 definitionNames));
 
-        if (node instanceof ActionNodeContainer) {
-            ((ActionNodeContainer) node).getActions().forEach(actionDef -> {
+        if (node instanceof ActionNodeContainer actionContainer) {
+            actionContainer.getActions().forEach(actionDef -> {
                 final String operationsPath = getResourcePath("operations", context)
                     + "/" + resourcePathPart
                     + "/" + resolvePathArgumentsName(actionDef.getQName(), node.getQName(), schemaContext);
@@ -383,10 +382,10 @@ public abstract class BaseYangOpenApiGenerator {
             .map(Parameter::name)
             .collect(Collectors.toSet());
 
-        if (schemaNode instanceof ListSchemaNode) {
+        if (schemaNode instanceof ListSchemaNode listSchemaNode) {
             String prefix = "=";
             int discriminator = 1;
-            for (final QName listKey : ((ListSchemaNode) schemaNode).getKeyDefinition()) {
+            for (final QName listKey : listSchemaNode.getKeyDefinition()) {
                 final String keyName = listKey.getLocalName();
                 String paramName = keyName;
                 while (!parameters.add(paramName)) {
@@ -398,7 +397,7 @@ public abstract class BaseYangOpenApiGenerator {
                 prefix = ",";
                 path.append(pathParamIdentifier);
 
-                final String description = ((DataNodeContainer) schemaNode).findDataChildByName(listKey)
+                final String description = listSchemaNode.findDataChildByName(listKey)
                     .flatMap(DataSchemaNode::getDescription).orElse(null);
                 final Parameter.Builder pathParamBuilder = new Parameter.Builder()
                     .name(paramName)