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

yx9o 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 d4ae0fcf15d Refactor TypedSPILoader (#26862)
d4ae0fcf15d is described below

commit d4ae0fcf15d8d8d0c34c001550d19eeef07fa028
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 9 23:40:24 2023 +0800

    Refactor TypedSPILoader (#26862)
    
    * Revise UniqueRuleItemNodePathTest
    
    * Refactor TypedSPILoader
---
 .../metadata/nodepath/item/UniqueRuleItemNodePathTest.java     |  2 +-
 .../shardingsphere/infra/util/spi/type/typed/TypedSPI.java     |  2 +-
 .../infra/util/spi/type/typed/TypedSPILoader.java              | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/nodepath/item/UniqueRuleItemNodePathTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/nodepath/item/UniqueRuleItemNodePathTest.java
index 5804753c599..7599ee31aea 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/nodepath/item/UniqueRuleItemNodePathTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/nodepath/item/UniqueRuleItemNodePathTest.java
@@ -25,7 +25,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 
-public class UniqueRuleItemNodePathTest {
+class UniqueRuleItemNodePathTest {
     
     @Test
     void assertPathWithNullParentNode() {
diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
index fd9d56d7d6c..fc41a922ff6 100644
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
+++ 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
@@ -40,7 +40,7 @@ public interface TypedSPI {
      * @return type
      */
     default String getType() {
-        return "";
+        return null;
     }
     
     /**
diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
index 1f00bfa91fc..629bec0bdf1 100644
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
+++ 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
@@ -89,10 +89,6 @@ public final class TypedSPILoader {
         return Optional.empty();
     }
     
-    private static boolean matchesType(final String type, final TypedSPI 
instance) {
-        return instance.getType().equalsIgnoreCase(type) || 
instance.getTypeAliases().contains(type);
-    }
-    
     private static Properties convertToStringTypedProperties(final Properties 
props) {
         if (props.isEmpty()) {
             return props;
@@ -134,7 +130,7 @@ public final class TypedSPILoader {
      * @param type type
      * @param props properties
      * @param <T> SPI class type
-     * @return check result
+     * @return is valid service or not
      * @throws ServiceProviderNotFoundServerException service provider not 
found server exception
      */
     public static <T extends TypedSPI> boolean checkService(final Class<T> 
spiClass, final String type, final Properties props) {
@@ -147,4 +143,8 @@ public final class TypedSPILoader {
         }
         throw new ServiceProviderNotFoundServerException(spiClass, type);
     }
+    
+    private static boolean matchesType(final String type, final TypedSPI 
instance) {
+        return null != instance.getType() && 
(instance.getType().equalsIgnoreCase(type) || 
instance.getTypeAliases().contains(type));
+    }
 }

Reply via email to