Pace2Car commented on code in PR #25041:
URL: https://github.com/apache/shardingsphere/pull/25041#discussion_r1186981948


##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsChecker.java:
##########
@@ -55,30 +55,47 @@ public static void checkSingleCharConfig(final Properties 
props, final String si
      * @throws MaskAlgorithmInitializationException mask algorithm 
initialization exception
      */
     public static void checkAtLeastOneCharConfig(final Properties props, final 
String atLeastOneCharConfigKey, final String maskType) {
-        if (!props.containsKey(atLeastOneCharConfigKey)) {
-            throw new MaskAlgorithmInitializationException(maskType, 
String.format("%s can not be null", atLeastOneCharConfigKey));
-        }
-        if (0 == props.getProperty(atLeastOneCharConfigKey).length()) {
-            throw new MaskAlgorithmInitializationException(maskType, 
String.format("%s's length must be at least one", atLeastOneCharConfigKey));
-        }
+        
ShardingSpherePreconditions.checkState(props.containsKey(atLeastOneCharConfigKey),
+                () -> new MaskAlgorithmInitializationException(maskType, 
String.format("%s can not be null", atLeastOneCharConfigKey)));
+        
ShardingSpherePreconditions.checkState(props.getProperty(atLeastOneCharConfigKey).length()
 > 0,
+                () -> new MaskAlgorithmInitializationException(maskType, 
String.format("%s's length must be at least one", atLeastOneCharConfigKey)));
     }
     
     /**
-     * Check integer type config.
+     * Check required property config.
      *
      * @param props props
-     * @param integerTypeConfigKey integer type config key
+     * @param requiredPropertyConfigKey required property config key
      * @param maskType mask type
      * @throws MaskAlgorithmInitializationException mask algorithm 
initialization exception
      */
-    public static void checkIntegerTypeConfig(final Properties props, final 
String integerTypeConfigKey, final String maskType) {
-        if (!props.containsKey(integerTypeConfigKey)) {
-            throw new MaskAlgorithmInitializationException(maskType, 
String.format("%s can not be null", integerTypeConfigKey));
-        }
+    public static void checkRequiredPropertyConfig(final Properties props, 
final String requiredPropertyConfigKey, final String maskType) {
+        
ShardingSpherePreconditions.checkState(props.containsKey(requiredPropertyConfigKey),
+                () -> new MaskAlgorithmInitializationException(maskType, 
String.format("%s is required", requiredPropertyConfigKey)));
+    }
+    
+    /**
+     * Check required property config.
+     *
+     * @param props props
+     * @param positiveIntegerTypeConfigKey positive integer type config key
+     * @param maskType mask type
+     * @throws MaskAlgorithmInitializationException mask algorithm 
initialization exception
+     */
+    public static void checkPositiveIntegerConfig(final Properties props, 
final String positiveIntegerTypeConfigKey, final String maskType) {
+        
ShardingSpherePreconditions.checkState(props.containsKey(positiveIntegerTypeConfigKey),
+                () -> new MaskAlgorithmInitializationException(maskType, 
String.format("%s can not be null", positiveIntegerTypeConfigKey)));
+        

Review Comment:
   Please remove unnecessary blank lines.



##########
features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsChecker.java:
##########
@@ -55,30 +55,47 @@ public static void checkSingleCharConfig(final Properties 
props, final String si
      * @throws MaskAlgorithmInitializationException mask algorithm 
initialization exception
      */
     public static void checkAtLeastOneCharConfig(final Properties props, final 
String atLeastOneCharConfigKey, final String maskType) {
-        if (!props.containsKey(atLeastOneCharConfigKey)) {
-            throw new MaskAlgorithmInitializationException(maskType, 
String.format("%s can not be null", atLeastOneCharConfigKey));
-        }
-        if (0 == props.getProperty(atLeastOneCharConfigKey).length()) {
-            throw new MaskAlgorithmInitializationException(maskType, 
String.format("%s's length must be at least one", atLeastOneCharConfigKey));
-        }
+        
ShardingSpherePreconditions.checkState(props.containsKey(atLeastOneCharConfigKey),
+                () -> new MaskAlgorithmInitializationException(maskType, 
String.format("%s can not be null", atLeastOneCharConfigKey)));
+        
ShardingSpherePreconditions.checkState(props.getProperty(atLeastOneCharConfigKey).length()
 > 0,
+                () -> new MaskAlgorithmInitializationException(maskType, 
String.format("%s's length must be at least one", atLeastOneCharConfigKey)));
     }
     
     /**
-     * Check integer type config.
+     * Check required property config.
      *
      * @param props props
-     * @param integerTypeConfigKey integer type config key
+     * @param requiredPropertyConfigKey required property config key
      * @param maskType mask type
      * @throws MaskAlgorithmInitializationException mask algorithm 
initialization exception
      */
-    public static void checkIntegerTypeConfig(final Properties props, final 
String integerTypeConfigKey, final String maskType) {
-        if (!props.containsKey(integerTypeConfigKey)) {
-            throw new MaskAlgorithmInitializationException(maskType, 
String.format("%s can not be null", integerTypeConfigKey));
-        }
+    public static void checkRequiredPropertyConfig(final Properties props, 
final String requiredPropertyConfigKey, final String maskType) {
+        
ShardingSpherePreconditions.checkState(props.containsKey(requiredPropertyConfigKey),
+                () -> new MaskAlgorithmInitializationException(maskType, 
String.format("%s is required", requiredPropertyConfigKey)));
+    }
+    
+    /**
+     * Check required property config.
+     *
+     * @param props props
+     * @param positiveIntegerTypeConfigKey positive integer type config key
+     * @param maskType mask type
+     * @throws MaskAlgorithmInitializationException mask algorithm 
initialization exception
+     */
+    public static void checkPositiveIntegerConfig(final Properties props, 
final String positiveIntegerTypeConfigKey, final String maskType) {
+        
ShardingSpherePreconditions.checkState(props.containsKey(positiveIntegerTypeConfigKey),
+                () -> new MaskAlgorithmInitializationException(maskType, 
String.format("%s can not be null", positiveIntegerTypeConfigKey)));
+        
         try {
-            Integer.parseInt(props.getProperty(integerTypeConfigKey));
-        } catch (final NumberFormatException ignored) {
-            throw new MaskAlgorithmInitializationException(maskType, 
String.format("%s must be a valid integer number", integerTypeConfigKey));
+            Integer.parseInt(props.getProperty(positiveIntegerTypeConfigKey));
+        } catch (final NumberFormatException ex) {
+            throw new MaskAlgorithmInitializationException(maskType, 
String.format("%s must be a valid integer number", 
positiveIntegerTypeConfigKey));
+        }
+        

Review Comment:
   as same.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to