This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 4444314ac9c Fix code style (#25869)
4444314ac9c is described below
commit 4444314ac9c78642af56f40f3c0fb904df14ac8e
Author: ChenJiaHao <[email protected]>
AuthorDate: Wed May 24 16:03:49 2023 +0800
Fix code style (#25869)
* Fix code style
* Refactor code
---
.../mask/algorithm/MaskAlgorithmPropsChecker.java | 36 +++++++---------------
.../replace/LandlineNumberRandomAlgorithmTest.java | 1 -
2 files changed, 11 insertions(+), 26 deletions(-)
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsChecker.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsChecker.java
index 5717890d374..8b106c868a3 100644
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsChecker.java
+++
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropsChecker.java
@@ -32,59 +32,40 @@ public final class MaskAlgorithmPropsChecker {
/**
* Check single char config.
- *
+ *
* @param props props
* @param singleCharConfigKey single char config key
* @param maskType mask type
- * @throws MaskAlgorithmInitializationException mask algorithm
initialization exception
*/
public static void checkSingleCharConfig(final Properties props, final
String singleCharConfigKey, final String maskType) {
-
ShardingSpherePreconditions.checkState(props.containsKey(singleCharConfigKey),
- () -> new MaskAlgorithmInitializationException(maskType,
String.format("%s can not be null", singleCharConfigKey)));
+ checkRequiredPropertyConfig(props, singleCharConfigKey, maskType);
ShardingSpherePreconditions.checkState(1 ==
props.getProperty(singleCharConfigKey).length(),
() -> new MaskAlgorithmInitializationException(maskType,
String.format("%s's length must be one", singleCharConfigKey)));
}
/**
* Check at least one char config.
- *
+ *
* @param props props
* @param atLeastOneCharConfigKey at least one char config key
* @param maskType mask type
- * @throws MaskAlgorithmInitializationException mask algorithm
initialization exception
*/
public static void checkAtLeastOneCharConfig(final Properties props, final
String atLeastOneCharConfigKey, final String maskType) {
-
ShardingSpherePreconditions.checkState(props.containsKey(atLeastOneCharConfigKey),
- () -> new MaskAlgorithmInitializationException(maskType,
String.format("%s can not be null", atLeastOneCharConfigKey)));
+ checkRequiredPropertyConfig(props, atLeastOneCharConfigKey, maskType);
ShardingSpherePreconditions.checkState(props.getProperty(atLeastOneCharConfigKey).length()
> 0,
() -> new MaskAlgorithmInitializationException(maskType,
String.format("%s's length must be at least one", atLeastOneCharConfigKey)));
}
/**
* Check required property config.
- *
- * @param props props
- * @param requiredPropertyConfigKey required property config key
- * @param maskType mask type
- * @throws MaskAlgorithmInitializationException mask algorithm
initialization exception
- */
- public static void checkRequiredPropertyConfig(final Properties props,
final String requiredPropertyConfigKey, final String maskType) {
- if (!props.containsKey(requiredPropertyConfigKey)) {
- throw 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)));
+ checkRequiredPropertyConfig(props, positiveIntegerTypeConfigKey,
maskType);
try {
int integerValue =
Integer.parseInt(props.getProperty(positiveIntegerTypeConfigKey));
ShardingSpherePreconditions.checkState(integerValue > 0,
@@ -93,4 +74,9 @@ public final class MaskAlgorithmPropsChecker {
throw new MaskAlgorithmInitializationException(maskType,
String.format("%s must be a valid integer number",
positiveIntegerTypeConfigKey));
}
}
+
+ private 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)));
+ }
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithmTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithmTest.java
index 35ade1c8975..4cbeee97576 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithmTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/algorithm/replace/LandlineNumberRandomAlgorithmTest.java
@@ -55,5 +55,4 @@ class LandlineNumberRandomAlgorithmTest {
assertThrows(MaskAlgorithmInitializationException.class,
() -> maskAlgorithm.init(PropertiesBuilder.build(new
Property("landline-numbers", ""))));
}
-
}