You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/06/29 13:20:49 UTC

[shardingsphere] branch master updated: Fix sonar issues of Replace this "switch" statement by "if" statements to increase readability. (#26698)

This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new ca9a17cafaf Fix sonar issues of Replace this "switch" statement by "if" statements to increase readability. (#26698)
ca9a17cafaf is described below

commit ca9a17cafafa75630794d6e9372bced0d79f1585
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Jun 29 21:20:40 2023 +0800

    Fix sonar issues of Replace this "switch" statement by "if" statements to increase readability. (#26698)
---
 .../broadcast/event/BroadcastRuleChangedEventCreator.java        | 9 +++------
 .../shadow/event/ShadowRuleChangedEventCreator.java              | 9 +++------
 .../single/event/SingleRuleChangedEventCreator.java              | 9 +++------
 3 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/BroadcastRuleChangedEventCreator.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/BroadcastRuleChangedEventCreator.java
index a9a48a48958..e5016ae2b14 100644
--- a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/BroadcastRuleChangedEventCreator.java
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/BroadcastRuleChangedEventCreator.java
@@ -34,14 +34,11 @@ public final class BroadcastRuleChangedEventCreator implements RuleChangedEventC
         return getUniqueRuleItemChangedEventCreator(itemType).create(databaseName, event);
     }
     
-    @SuppressWarnings("SwitchStatementWithTooFewBranches")
     private UniqueRuleItemChangedEventCreator getUniqueRuleItemChangedEventCreator(final String itemType) {
-        switch (itemType) {
-            case BroadcastRuleNodePathProvider.TABLES:
-                return new BroadcastTableEventCreator();
-            default:
-                throw new UnsupportedOperationException(itemType);
+        if (itemType.equals(BroadcastRuleNodePathProvider.TABLES)) {
+            return new BroadcastTableEventCreator();
         }
+        throw new UnsupportedOperationException(itemType);
     }
     
     @Override
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/ShadowRuleChangedEventCreator.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/ShadowRuleChangedEventCreator.java
index 094c0bacaf8..f78991b326b 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/ShadowRuleChangedEventCreator.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/event/ShadowRuleChangedEventCreator.java
@@ -56,14 +56,11 @@ public final class ShadowRuleChangedEventCreator implements RuleChangedEventCrea
         }
     }
     
-    @SuppressWarnings("SwitchStatementWithTooFewBranches")
     private UniqueRuleItemChangedEventCreator getUniqueRuleItemChangedEventCreator(final String itemType) {
-        switch (itemType) {
-            case ShadowRuleNodePathProvider.DATA_SOURCES:
-                return new DefaultShadowAlgorithmEventCreator();
-            default:
-                throw new UnsupportedOperationException(itemType);
+        if (itemType.equals(ShadowRuleNodePathProvider.DATA_SOURCES)) {
+            return new DefaultShadowAlgorithmEventCreator();
         }
+        throw new UnsupportedOperationException(itemType);
     }
     
     @Override
diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/event/SingleRuleChangedEventCreator.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/event/SingleRuleChangedEventCreator.java
index f2e4d5e59df..ebd8c620bf7 100644
--- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/event/SingleRuleChangedEventCreator.java
+++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/event/SingleRuleChangedEventCreator.java
@@ -34,14 +34,11 @@ public final class SingleRuleChangedEventCreator implements RuleChangedEventCrea
         return getUniqueRuleItemChangedEventCreator(itemType).create(databaseName, event);
     }
     
-    @SuppressWarnings("SwitchStatementWithTooFewBranches")
     private UniqueRuleItemChangedEventCreator getUniqueRuleItemChangedEventCreator(final String itemType) {
-        switch (itemType) {
-            case SingleRuleNodePathProvider.TABLES:
-                return new SingleTableEventCreator();
-            default:
-                throw new UnsupportedOperationException(itemType);
+        if (itemType.equals(SingleRuleNodePathProvider.TABLES)) {
+            return new SingleTableEventCreator();
         }
+        throw new UnsupportedOperationException(itemType);
     }
     
     @Override