summaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2024-10-23 15:12:41 +0100
committerSourabh Sourabh <sourabh.sourabh@est.tech>2024-10-24 10:27:41 +0000
commite0c537f4463b6664e108e12962e1f4b34544776c (patch)
tree30477a8d6b505ee1731d8657e8a76650ff1d285c /cps-service
parentd612628bae7c468ef69dc04a1fed89d3ba4b8f34 (diff)
Refactor: Improve code quality and compliance with SonarQube standards
- Consolidated multiple `if` statements to enhance readability and maintainability. - Replaced traditional `instanceof` checks followed by casting with the new pattern matching syntax for improved type safety and clarity. - Removed unnecessary casts and streamlined code in `addYangLeafList` and `addDataNodeFromNormalizedNode` methods. Issue-ID: CPS-1957 Change-Id: I46696dc184b6b3c3d0fe3a6bd12267a4e0d76193 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java25
1 files changed, 12 insertions, 13 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
index 9859acdf0e..de57914527 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
@@ -204,18 +204,17 @@ public class DataNodeBuilder {
private static void addDataNodeFromNormalizedNode(final DataNode currentDataNode,
final NormalizedNode normalizedNode) {
- if (normalizedNode instanceof ChoiceNode) {
- addChoiceNode(currentDataNode, (ChoiceNode) normalizedNode);
- } else if (normalizedNode instanceof DataContainerNode) {
- addYangContainer(currentDataNode, (DataContainerNode) normalizedNode);
- } else if (normalizedNode instanceof MapNode) {
- addDataNodeForEachListElement(currentDataNode, (MapNode) normalizedNode);
- } else if (normalizedNode instanceof ValueNode) {
- final ValueNode<NormalizedNode> valuesNode = (ValueNode) normalizedNode;
- addYangLeaf(currentDataNode, valuesNode.getIdentifier().getNodeType().getLocalName(),
- (Serializable) valuesNode.body());
- } else if (normalizedNode instanceof LeafSetNode) {
- addYangLeafList(currentDataNode, (LeafSetNode<?>) normalizedNode);
+ if (normalizedNode instanceof ChoiceNode choiceNode) {
+ addChoiceNode(currentDataNode, choiceNode);
+ } else if (normalizedNode instanceof DataContainerNode dataContainerNode) {
+ addYangContainer(currentDataNode, dataContainerNode);
+ } else if (normalizedNode instanceof MapNode mapNode) {
+ addDataNodeForEachListElement(currentDataNode, mapNode);
+ } else if (normalizedNode instanceof ValueNode<?> valueNode) {
+ addYangLeaf(currentDataNode, valueNode.getIdentifier().getNodeType().getLocalName(),
+ (Serializable) valueNode.body());
+ } else if (normalizedNode instanceof LeafSetNode<?> leafSetNode) {
+ addYangLeafList(currentDataNode, leafSetNode);
} else {
log.warn("Unsupported NormalizedNode type detected: {}", normalizedNode.getClass());
}
@@ -243,7 +242,7 @@ public class DataNodeBuilder {
private static void addYangLeafList(final DataNode currentDataNode, final LeafSetNode<?> leafSetNode) {
final String leafListName = leafSetNode.getIdentifier().getNodeType().getLocalName();
- List<?> leafListValues = ((Collection<? extends NormalizedNode>) leafSetNode.body())
+ List<?> leafListValues = (leafSetNode.body())
.stream()
.map(NormalizedNode::body)
.collect(Collectors.toList());