Eliminate casting in processTypeDef method 46/107246/5
authorlubos-cicut <lubos.cicut@pantheon.tech>
Fri, 4 Aug 2023 06:41:57 +0000 (08:41 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Fri, 4 Aug 2023 13:18:30 +0000 (13:18 +0000)
Eliminate casting in DefinitionGenerator#processTypeDef method by using
instanceof pattern.

JIRA: NETCONF-1112
Change-Id: I621b0080db35d3db1a9abc0a52a598efaf154047
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/DefinitionGenerator.java

index cf361fa679b0bc80b72e458d5617206a66cdaf5c..7869f36091b47043a151532b638bb2b0960a3f3f 100644 (file)
@@ -612,33 +612,27 @@ public class DefinitionGenerator {
         final String jsonType;
         if (leafTypeDef instanceof BinaryTypeDefinition) {
             jsonType = processBinaryType(property);
-
-        } else if (leafTypeDef instanceof BitsTypeDefinition) {
-            jsonType = processBitsType((BitsTypeDefinition) leafTypeDef, property);
-
-        } else if (leafTypeDef instanceof EnumTypeDefinition) {
-            jsonType = processEnumType((EnumTypeDefinition) leafTypeDef, property);
-
-        } else if (leafTypeDef instanceof IdentityrefTypeDefinition) {
-            jsonType = processIdentityRefType((IdentityrefTypeDefinition) leafTypeDef, property, definitions,
+        } else if (leafTypeDef instanceof BitsTypeDefinition bitsType) {
+            jsonType = processBitsType(bitsType, property);
+        } else if (leafTypeDef instanceof EnumTypeDefinition enumType) {
+            jsonType = processEnumType(enumType, property);
+        } else if (leafTypeDef instanceof IdentityrefTypeDefinition identityrefType) {
+            jsonType = processIdentityRefType(identityrefType, property, definitions,
                     definitionNames, stack.getEffectiveModelContext());
-
-        } else if (leafTypeDef instanceof StringTypeDefinition) {
-            jsonType = processStringType(leafTypeDef, property, node.getQName().getLocalName());
-
-        } else if (leafTypeDef instanceof UnionTypeDefinition) {
-            jsonType = processUnionType((UnionTypeDefinition) leafTypeDef);
-
+        } else if (leafTypeDef instanceof StringTypeDefinition stringType) {
+            jsonType = processStringType(stringType, property, node.getQName().getLocalName());
+        } else if (leafTypeDef instanceof UnionTypeDefinition unionType) {
+            jsonType = processUnionType(unionType);
         } else if (leafTypeDef instanceof EmptyTypeDefinition) {
             jsonType = OBJECT_TYPE;
-        } else if (leafTypeDef instanceof LeafrefTypeDefinition) {
-            return processTypeDef(stack.resolveLeafref((LeafrefTypeDefinition) leafTypeDef), node, property,
+        } else if (leafTypeDef instanceof LeafrefTypeDefinition leafrefType) {
+            return processTypeDef(stack.resolveLeafref(leafrefType), node, property,
                 stack, definitions, definitionNames);
         } else if (leafTypeDef instanceof BooleanTypeDefinition) {
             jsonType = BOOLEAN_TYPE;
             setExampleValue(property, true);
-        } else if (leafTypeDef instanceof RangeRestrictedTypeDefinition) {
-            jsonType = processNumberType((RangeRestrictedTypeDefinition<?, ?>) leafTypeDef, property);
+        } else if (leafTypeDef instanceof RangeRestrictedTypeDefinition<?, ?> rangeRestrictedType) {
+            jsonType = processNumberType(rangeRestrictedType, property);
         } else if (leafTypeDef instanceof InstanceIdentifierTypeDefinition) {
             jsonType = processInstanceIdentifierType(node, property, stack.getEffectiveModelContext());
         } else {
@@ -656,9 +650,9 @@ public class DefinitionGenerator {
                     } else if (leafTypeDef instanceof DecimalTypeDefinition
                             || leafTypeDef instanceof Uint64TypeDefinition) {
                         setDefaultValue(property, new BigDecimal(stringDefaultValue));
-                    } else if (leafTypeDef instanceof RangeRestrictedTypeDefinition) {
+                    } else if (leafTypeDef instanceof RangeRestrictedTypeDefinition<?, ?> rangeRestrictedType) {
                         //uint8,16,32 int8,16,32,64
-                        if (isHexadecimalOrOctal((RangeRestrictedTypeDefinition<?, ?>)leafTypeDef)) {
+                        if (isHexadecimalOrOctal(rangeRestrictedType)) {
                             setDefaultValue(property, stringDefaultValue);
                         } else {
                             setDefaultValue(property, Long.valueOf(stringDefaultValue));