This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 3503ce1f582 Add ShardingSpherePreconditions.checkContains() (#30981)
3503ce1f582 is described below
commit 3503ce1f5825956c74b59a47c54f9f03c12353ee
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Apr 20 15:47:05 2024 +0800
Add ShardingSpherePreconditions.checkContains() (#30981)
---
.../checker/EncryptRuleConfigurationChecker.java | 6 +--
.../rewrite/condition/EncryptConditionEngine.java | 2 +-
.../algorithm/MaskAlgorithmPropertiesChecker.java | 2 +-
.../mask/checker/MaskRuleConfigurationChecker.java | 2 +-
...riteSplittingStaticDataSourceRuleAttribute.java | 2 +-
.../ReadwriteSplittingRuleStatementChecker.java | 2 +-
...eadwriteSplittingStorageUnitStatusExecutor.java | 6 +--
.../checker/ShadowRuleConfigurationChecker.java | 8 +--
.../update/DropShadowAlgorithmExecutor.java | 2 +-
.../datetime/AutoIntervalShardingAlgorithm.java | 2 +-
.../datetime/IntervalShardingAlgorithm.java | 6 +--
.../sharding/mod/HashModShardingAlgorithm.java | 2 +-
.../sharding/mod/ModShardingAlgorithm.java | 2 +-
.../range/BoundaryBasedRangeShardingAlgorithm.java | 2 +-
.../range/VolumeBasedRangeShardingAlgorithm.java | 6 +--
.../checker/ShardingRuleConfigurationChecker.java | 4 +-
.../weight/WeightLoadBalanceAlgorithm.java | 2 +-
.../segment/from/impl/JoinTableSegmentBinder.java | 2 +-
.../impl/ShorthandProjectionSegmentBinder.java | 2 +-
.../core/ShardingSpherePreconditions.java | 47 ++++++++++++++++-
.../core/ShardingSpherePreconditionsTest.java | 59 +++++++++++++++++-----
.../interval/IntervalInlineExpressionParser.java | 15 ++----
.../result/impl/memory/MemoryMergedResult.java | 2 +-
.../api/ConsistencyCheckJobAPI.java | 4 +-
.../scenario/migration/api/MigrationJobAPI.java | 2 +-
.../SingleRuleConfigurationDecorator.java | 9 ++--
.../handler/update/LoadSingleTableExecutor.java | 4 +-
.../SetDefaultSingleTableStorageUnitExecutor.java | 2 +-
.../handler/update/UnloadSingleTableExecutor.java | 4 +-
.../resultset/SQLFederationResultSet.java | 2 +-
.../traffic/segment/SQLMatchTrafficAlgorithm.java | 2 +-
.../traffic/segment/SQLRegexTrafficAlgorithm.java | 2 +-
.../updatable/RefreshTableMetaDataExecutor.java | 3 +-
.../proxy/backend/hbase/context/HBaseContext.java | 2 +-
34 files changed, 144 insertions(+), 77 deletions(-)
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
index 2cb1266427e..a31571339e3 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
@@ -73,7 +73,7 @@ public final class EncryptRuleConfigurationChecker implements
RuleConfigurationC
() -> new MissingRequiredEncryptColumnException("Cipher", new
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
ShardingSpherePreconditions.checkNotEmpty(cipherColumnConfig.getEncryptorName(),
() -> new EmptyAlgorithmException("Standard encrypt", new
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
-
ShardingSpherePreconditions.checkState(encryptors.containsKey(cipherColumnConfig.getEncryptorName()),
+ ShardingSpherePreconditions.checkContainsKey(encryptors,
cipherColumnConfig.getEncryptorName(),
() -> new UnregisteredAlgorithmException("Standard encrypt",
cipherColumnConfig.getEncryptorName(), new SQLExceptionIdentifier(databaseName,
tableName, logicColumnName)));
}
@@ -83,7 +83,7 @@ public final class EncryptRuleConfigurationChecker implements
RuleConfigurationC
() -> new MissingRequiredEncryptColumnException("Assisted
query", new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
ShardingSpherePreconditions.checkNotEmpty(assistedQueryColumnConfig.getEncryptorName(),
() -> new EmptyAlgorithmException("Assist query encrypt", new
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
-
ShardingSpherePreconditions.checkState(encryptors.containsKey(assistedQueryColumnConfig.getEncryptorName()),
+ ShardingSpherePreconditions.checkContainsKey(encryptors,
assistedQueryColumnConfig.getEncryptorName(),
() -> new UnregisteredAlgorithmException("Assist query
encrypt", assistedQueryColumnConfig.getEncryptorName(), new
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
}
@@ -93,7 +93,7 @@ public final class EncryptRuleConfigurationChecker implements
RuleConfigurationC
() -> new MissingRequiredEncryptColumnException("Like", new
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
ShardingSpherePreconditions.checkNotEmpty(likeQueryColumnConfig.getEncryptorName(),
() -> new EmptyAlgorithmException("Like query", new
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
-
ShardingSpherePreconditions.checkState(encryptors.containsKey(likeQueryColumnConfig.getEncryptorName()),
+ ShardingSpherePreconditions.checkContainsKey(encryptors,
likeQueryColumnConfig.getEncryptorName(),
() -> new UnregisteredAlgorithmException("Like query encrypt",
likeQueryColumnConfig.getEncryptorName(), new
SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
index 91c5210550a..4f4e5067710 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
@@ -162,7 +162,7 @@ public final class EncryptConditionEngine {
if (LOGICAL_OPERATOR.contains(operator)) {
return Optional.empty();
}
-
ShardingSpherePreconditions.checkState(SUPPORTED_COMPARE_OPERATOR.contains(operator),
() -> new UnsupportedEncryptSQLException(operator));
+ ShardingSpherePreconditions.checkContains(SUPPORTED_COMPARE_OPERATOR,
operator, () -> new UnsupportedEncryptSQLException(operator));
return createCompareEncryptCondition(tableName, expression,
expression.getRight());
}
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
index 75c066d6c5c..d747cd0d473 100644
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
+++
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
@@ -74,6 +74,6 @@ public final class MaskAlgorithmPropertiesChecker {
}
private static void checkRequired(final Properties props, final String
requiredPropKey, final MaskAlgorithm<?, ?> algorithm) {
-
ShardingSpherePreconditions.checkState(props.containsKey(requiredPropKey), ()
-> new AlgorithmInitializationException(algorithm, "%s is required",
requiredPropKey));
+ ShardingSpherePreconditions.checkContainsKey(props, requiredPropKey,
() -> new AlgorithmInitializationException(algorithm, "%s is required",
requiredPropKey));
}
}
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
index 494aa0862ec..661f736609e 100644
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
+++
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
@@ -59,7 +59,7 @@ public final class MaskRuleConfigurationChecker implements
RuleConfigurationChec
}
private void checkColumn(final String databaseName, final String
tableName, final MaskColumnRuleConfiguration columnRuleConfig, final
Map<String, AlgorithmConfiguration> maskAlgorithms) {
-
ShardingSpherePreconditions.checkState(maskAlgorithms.containsKey(columnRuleConfig.getMaskAlgorithm()),
+ ShardingSpherePreconditions.checkContainsKey(maskAlgorithms,
columnRuleConfig.getMaskAlgorithm(),
() -> new UnregisteredAlgorithmException("Mask",
columnRuleConfig.getMaskAlgorithm(), new SQLExceptionIdentifier(databaseName,
tableName, columnRuleConfig.getLogicColumn())));
}
diff --git
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java
index fe08d57fcc3..8acad8f35c2 100644
---
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java
@@ -70,7 +70,7 @@ public final class
ReadwriteSplittingStaticDataSourceRuleAttribute implements St
@Override
public void cleanStorageNodeDataSource(final String groupName) {
-
ShardingSpherePreconditions.checkState(dataSourceRules.containsKey(groupName),
() -> new ReadwriteSplittingDataSourceRuleNotFoundException(groupName,
databaseName));
+ ShardingSpherePreconditions.checkContainsKey(dataSourceRules,
groupName, () -> new
ReadwriteSplittingDataSourceRuleNotFoundException(groupName, databaseName));
deleteStorageNodeDataSources(dataSourceRules.get(groupName));
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
index 93db4765d07..eba0117df4e 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
@@ -211,7 +211,7 @@ public final class ReadwriteSplittingRuleStatementChecker {
Collection<String> validStrategyNames =
Arrays.stream(TransactionalReadQueryStrategy.values()).map(Enum::name).collect(Collectors.toSet());
for (ReadwriteSplittingRuleSegment each : segments) {
if (null != each.getTransactionalReadQueryStrategy()) {
-
ShardingSpherePreconditions.checkState(validStrategyNames.contains(each.getTransactionalReadQueryStrategy().toUpperCase()),
+ ShardingSpherePreconditions.checkContains(validStrategyNames,
each.getTransactionalReadQueryStrategy().toUpperCase(),
() -> new
MissingRequiredStrategyException("Transactional read query",
Collections.singleton(each.getTransactionalReadQueryStrategy())));
}
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
index 90e26186b7c..47a8806e45e 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
@@ -62,14 +62,14 @@ public final class
AlterReadwriteSplittingStorageUnitStatusExecutor
private void checkBeforeUpdate(final
AlterReadwriteSplittingStorageUnitStatusStatement sqlStatement) {
Optional<ReadwriteSplittingDataSourceRule> dataSourceRule =
rule.getDataSourceRules().values().stream().filter(each ->
each.getName().equalsIgnoreCase(sqlStatement.getRuleName())).findAny();
ShardingSpherePreconditions.checkState(dataSourceRule.isPresent(), ()
-> new MissingRequiredRuleException("Readwrite-splitting", database.getName(),
sqlStatement.getRuleName()));
-
ShardingSpherePreconditions.checkState(dataSourceRule.get().getReadwriteSplittingGroup().getReadDataSources().contains(sqlStatement.getStorageUnitName()),
+
ShardingSpherePreconditions.checkContains(dataSourceRule.get().getReadwriteSplittingGroup().getReadDataSources(),
sqlStatement.getStorageUnitName(),
() -> new ReadwriteSplittingActualDataSourceNotFoundException(
ReadwriteSplittingDataSourceType.READ,
sqlStatement.getStorageUnitName(), new
ReadwriteSplittingRuleExceptionIdentifier(database.getName(),
dataSourceRule.get().getName())));
if (sqlStatement.isEnable()) {
-
ShardingSpherePreconditions.checkState(dataSourceRule.get().getDisabledDataSourceNames().contains(sqlStatement.getStorageUnitName()),
+
ShardingSpherePreconditions.checkContains(dataSourceRule.get().getDisabledDataSourceNames(),
sqlStatement.getStorageUnitName(),
() -> new InvalidStorageUnitStatusException("storage unit
is not disabled"));
} else {
-
ShardingSpherePreconditions.checkState(!dataSourceRule.get().getDisabledDataSourceNames().contains(sqlStatement.getStorageUnitName()),
+
ShardingSpherePreconditions.checkNotContains(dataSourceRule.get().getDisabledDataSourceNames(),
sqlStatement.getStorageUnitName(),
() -> new InvalidStorageUnitStatusException("storage unit
is already disabled"));
}
}
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
index 4909310645e..429ae997afa 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
@@ -60,8 +60,8 @@ public final class ShadowRuleConfigurationChecker implements
RuleConfigurationCh
private void checkDataSources(final
Collection<ShadowDataSourceConfiguration> shadowDataSources, final Map<String,
DataSource> dataSourceMap, final String databaseName) {
for (ShadowDataSourceConfiguration each : shadowDataSources) {
-
ShardingSpherePreconditions.checkState(dataSourceMap.containsKey(each.getProductionDataSourceName()),
() -> new MissingRequiredProductionDataSourceException(databaseName));
-
ShardingSpherePreconditions.checkState(dataSourceMap.containsKey(each.getShadowDataSourceName()),
() -> new MissingRequiredShadowDataSourceException(databaseName));
+ ShardingSpherePreconditions.checkContainsKey(dataSourceMap,
each.getProductionDataSourceName(), () -> new
MissingRequiredProductionDataSourceException(databaseName));
+ ShardingSpherePreconditions.checkContainsKey(dataSourceMap,
each.getShadowDataSourceName(), () -> new
MissingRequiredShadowDataSourceException(databaseName));
}
}
@@ -69,7 +69,7 @@ public final class ShadowRuleConfigurationChecker implements
RuleConfigurationCh
Collection<String> dataSourceNames =
shadowDataSources.stream().map(ShadowDataSourceConfiguration::getName).collect(Collectors.toSet());
shadowTables.forEach((key, value) -> {
for (String each : value.getDataSourceNames()) {
-
ShardingSpherePreconditions.checkState(dataSourceNames.contains(each), () ->
new ShadowDataSourceMappingNotFoundException(key));
+ ShardingSpherePreconditions.checkContains(dataSourceNames,
each, () -> new ShadowDataSourceMappingNotFoundException(key));
}
});
}
@@ -84,7 +84,7 @@ public final class ShadowRuleConfigurationChecker implements
RuleConfigurationCh
private void checkShadowTableAlgorithmsReferences(final Map<String,
ShadowTableConfiguration> shadowTables, final Map<String,
AlgorithmConfiguration> shadowAlgorithms, final String databaseName) {
for (ShadowTableConfiguration each : shadowTables.values()) {
ShardingSpherePreconditions.checkNotEmpty(each.getShadowAlgorithmNames(), () ->
new EmptyAlgorithmException("Shadow", new
SQLExceptionIdentifier(databaseName)));
- each.getShadowAlgorithmNames().forEach(shadowAlgorithmName ->
ShardingSpherePreconditions.checkState(shadowAlgorithms.containsKey(shadowAlgorithmName),
+ each.getShadowAlgorithmNames().forEach(shadowAlgorithmName ->
ShardingSpherePreconditions.checkContainsKey(shadowAlgorithms,
shadowAlgorithmName,
() -> new EmptyAlgorithmException("Shadow", new
SQLExceptionIdentifier(databaseName))));
}
}
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
index 0f9b3bdc7f0..7b4370ee2d2 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
@@ -65,7 +65,7 @@ public final class DropShadowAlgorithmExecutor implements
DatabaseRuleDropExecut
notExistedAlgorithms -> new
UnregisteredAlgorithmException("Shadow", notExistedAlgorithms, new
SQLExceptionIdentifier(database.getName())));
}
checkAlgorithmInUsed(requiredAlgorithms, getAlgorithmInUse(),
identical -> new InUsedAlgorithmException("Shadow", database.getName(),
identical));
-
ShardingSpherePreconditions.checkState(!requiredAlgorithms.contains(defaultShadowAlgorithmName),
+ ShardingSpherePreconditions.checkNotContains(requiredAlgorithms,
defaultShadowAlgorithmName,
() -> new InUsedAlgorithmException("Shadow",
database.getName(), Collections.singleton(defaultShadowAlgorithmName)));
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithm.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithm.java
index e53909424ad..bbe238f5f05 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithm.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithm.java
@@ -75,7 +75,7 @@ public final class AutoIntervalShardingAlgorithm implements
StandardShardingAlgo
}
private long getShardingSeconds(final Properties props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_SECONDS_KEY),
() -> new AlgorithmInitializationException(this, String.format("%s cannot be
null.", SHARDING_SECONDS_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props,
SHARDING_SECONDS_KEY, () -> new AlgorithmInitializationException(this,
String.format("%s cannot be null.", SHARDING_SECONDS_KEY)));
return Long.parseLong(props.getProperty(SHARDING_SECONDS_KEY));
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
index c92ba0d0530..ed829da38a3 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
@@ -94,14 +94,12 @@ public final class IntervalShardingAlgorithm implements
StandardShardingAlgorith
}
private String getDateTimePattern(final Properties props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(DATE_TIME_PATTERN_KEY),
- () -> new AlgorithmInitializationException(this,
String.format("%s can not be null", DATE_TIME_PATTERN_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props,
DATE_TIME_PATTERN_KEY, () -> new AlgorithmInitializationException(this,
String.format("%s can not be null", DATE_TIME_PATTERN_KEY)));
return props.getProperty(DATE_TIME_PATTERN_KEY);
}
private TemporalAccessor getDateTimeLower(final Properties props, final
String dateTimePattern) {
-
ShardingSpherePreconditions.checkState(props.containsKey(DATE_TIME_LOWER_KEY),
- () -> new AlgorithmInitializationException(this,
String.format("%s can not be null.", DATE_TIME_LOWER_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props,
DATE_TIME_LOWER_KEY, () -> new AlgorithmInitializationException(this,
String.format("%s can not be null.", DATE_TIME_LOWER_KEY)));
return getDateTime(DATE_TIME_LOWER_KEY,
props.getProperty(DATE_TIME_LOWER_KEY), dateTimePattern);
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithm.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithm.java
index c71344d9d8c..b1fb965367b 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithm.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithm.java
@@ -44,7 +44,7 @@ public final class HashModShardingAlgorithm implements
StandardShardingAlgorithm
}
private int getShardingCount(final Properties props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_COUNT_KEY),
() -> new AlgorithmInitializationException(this, "Sharding count cannot be
null."));
+ ShardingSpherePreconditions.checkContainsKey(props,
SHARDING_COUNT_KEY, () -> new AlgorithmInitializationException(this, "Sharding
count cannot be null."));
int result =
Integer.parseInt(String.valueOf(props.getProperty(SHARDING_COUNT_KEY)));
ShardingSpherePreconditions.checkState(result > 0, () -> new
AlgorithmInitializationException(this, "Sharding count must be a positive
integer."));
return result;
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithm.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithm.java
index ab18d88ca80..08c69a9dda9 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithm.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithm.java
@@ -65,7 +65,7 @@ public final class ModShardingAlgorithm implements
StandardShardingAlgorithm<Com
}
private int getShardingCount(final Properties props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_COUNT_KEY),
() -> new AlgorithmInitializationException(this, "Sharding count can not be
null."));
+ ShardingSpherePreconditions.checkContainsKey(props,
SHARDING_COUNT_KEY, () -> new AlgorithmInitializationException(this, "Sharding
count can not be null."));
int result =
Integer.parseInt(String.valueOf(props.getProperty(SHARDING_COUNT_KEY)));
ShardingSpherePreconditions.checkState(result > 0, () -> new
AlgorithmInitializationException(this, "Sharding count must be a positive
integer."));
return result;
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithm.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithm.java
index 9adcdacb994..01686e4b333 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithm.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithm.java
@@ -38,7 +38,7 @@ public final class BoundaryBasedRangeShardingAlgorithm
extends AbstractRangeShar
@Override
public Map<Integer, Range<Comparable<?>>> calculatePartitionRange(final
Properties props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_RANGES_KEY),
() -> new AlgorithmInitializationException(this, "Sharding ranges cannot be
null."));
+ ShardingSpherePreconditions.checkContainsKey(props,
SHARDING_RANGES_KEY, () -> new AlgorithmInitializationException(this, "Sharding
ranges cannot be null."));
List<Long> partitionRanges =
Splitter.on(",").trimResults().splitToList(props.getProperty(SHARDING_RANGES_KEY)).stream()
.map(this::parseLong).filter(Objects::nonNull).sorted().collect(Collectors.toList());
ShardingSpherePreconditions.checkNotEmpty(partitionRanges, () -> new
AlgorithmInitializationException(this, "Sharding ranges can not be empty."));
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithm.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithm.java
index 7dc35710de5..ff0f2fbd1c9 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithm.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithm.java
@@ -40,9 +40,9 @@ public final class VolumeBasedRangeShardingAlgorithm extends
AbstractRangeShardi
@Override
public Map<Integer, Range<Comparable<?>>> calculatePartitionRange(final
Properties props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(RANGE_LOWER_KEY), ()
-> new AlgorithmInitializationException(this, "Lower range cannot be null."));
-
ShardingSpherePreconditions.checkState(props.containsKey(RANGE_UPPER_KEY), ()
-> new AlgorithmInitializationException(this, "Upper range cannot be null."));
-
ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_VOLUME_KEY),
() -> new AlgorithmInitializationException(this, "Sharding volume cannot be
null."));
+ ShardingSpherePreconditions.checkContainsKey(props, RANGE_LOWER_KEY,
() -> new AlgorithmInitializationException(this, "Lower range cannot be
null."));
+ ShardingSpherePreconditions.checkContainsKey(props, RANGE_UPPER_KEY,
() -> new AlgorithmInitializationException(this, "Upper range cannot be
null."));
+ ShardingSpherePreconditions.checkContainsKey(props,
SHARDING_VOLUME_KEY, () -> new AlgorithmInitializationException(this, "Sharding
volume cannot be null."));
long lower = Long.parseLong(props.getProperty(RANGE_LOWER_KEY));
long upper = Long.parseLong(props.getProperty(RANGE_UPPER_KEY));
long volume = Long.parseLong(props.getProperty(SHARDING_VOLUME_KEY));
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
index 21675c0d4e0..f34d91141da 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
@@ -101,7 +101,7 @@ public final class ShardingRuleConfigurationChecker
implements RuleConfiguration
return;
}
ShardingSpherePreconditions.checkNotEmpty(keyGenerateStrategy.getColumn(), ()
-> new MissingRequiredShardingConfigurationException("Key generate column",
databaseName));
-
ShardingSpherePreconditions.checkState(keyGenerators.contains(keyGenerateStrategy.getKeyGeneratorName()),
+ ShardingSpherePreconditions.checkContains(keyGenerators,
keyGenerateStrategy.getKeyGeneratorName(),
() -> new UnregisteredAlgorithmException("Key generate",
keyGenerateStrategy.getKeyGeneratorName(), new
SQLExceptionIdentifier(databaseName)));
}
@@ -122,7 +122,7 @@ public final class ShardingRuleConfigurationChecker
implements RuleConfiguration
() -> new
MissingRequiredShardingConfigurationException("Complex sharding columns",
databaseName));
}
ShardingSpherePreconditions.checkNotNull(shardingStrategy.getShardingAlgorithmName(),
() -> new MissingRequiredShardingConfigurationException("Sharding algorithm
name", databaseName));
-
ShardingSpherePreconditions.checkState(shardingAlgorithms.contains(shardingStrategy.getShardingAlgorithmName()),
+ ShardingSpherePreconditions.checkContains(shardingAlgorithms,
shardingStrategy.getShardingAlgorithmName(),
() -> new UnregisteredAlgorithmException("Key generate",
shardingStrategy.getShardingAlgorithmName(), new
SQLExceptionIdentifier(databaseName)));
}
diff --git
a/infra/algorithm/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
b/infra/algorithm/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
index df0097f8141..c017743a3a5 100644
---
a/infra/algorithm/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
+++
b/infra/algorithm/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
@@ -60,7 +60,7 @@ public final class WeightLoadBalanceAlgorithm implements
LoadBalanceAlgorithm {
@Override
public void check(final String databaseName, final Collection<String>
configuredTargetNames) {
- weightConfigMap.keySet().forEach(each ->
ShardingSpherePreconditions.checkState(configuredTargetNames.contains(each),
+ weightConfigMap.keySet().forEach(each ->
ShardingSpherePreconditions.checkContains(configuredTargetNames, each,
() -> new AlgorithmInitializationException(this, "Target `%s`
is required in database `%s`.", each, databaseName)));
}
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinder.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinder.java
index d8fe4caedc0..1d0649d61f1 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinder.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinder.java
@@ -148,7 +148,7 @@ public final class JoinTableSegmentBinder {
}
private static Collection<ProjectionSegment>
getProjectionSegmentsByTableAliasOrName(final Map<String,
TableSegmentBinderContext> tableBinderContexts, final String tableAliasOrName) {
-
ShardingSpherePreconditions.checkState(tableBinderContexts.containsKey(tableAliasOrName.toLowerCase()),
+ ShardingSpherePreconditions.checkContainsKey(tableBinderContexts,
tableAliasOrName.toLowerCase(),
() -> new IllegalStateException(String.format("Can not find
table binder context by table alias or name %s.", tableAliasOrName)));
return
tableBinderContexts.get(tableAliasOrName.toLowerCase()).getProjectionSegments();
}
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
index a6c56c0f477..f21f5e53b63 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
@@ -59,7 +59,7 @@ public final class ShorthandProjectionSegmentBinder {
}
private static Collection<ProjectionSegment>
getProjectionSegmentsByTableAliasOrName(final Map<String,
TableSegmentBinderContext> tableBinderContexts, final String tableAliasOrName) {
-
ShardingSpherePreconditions.checkState(tableBinderContexts.containsKey(tableAliasOrName.toLowerCase()),
+ ShardingSpherePreconditions.checkContainsKey(tableBinderContexts,
tableAliasOrName.toLowerCase(),
() -> new IllegalStateException(String.format("Can not find
table binder context by table alias or name %s.", tableAliasOrName)));
return
tableBinderContexts.get(tableAliasOrName.toLowerCase()).getProjectionSegments();
}
diff --git
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
index aa463358aa1..bdec1cd19d1 100644
---
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
+++
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
@@ -116,7 +116,7 @@ public final class ShardingSpherePreconditions {
}
/**
- * Ensures that a collection passed as a parameter to the calling method
must empty.
+ * Ensures that a map passed as a parameter to the calling method must
empty.
*
* @param <T> type of exception
* @param map map to be checked
@@ -128,4 +128,49 @@ public final class ShardingSpherePreconditions {
throw exceptionSupplierIfUnexpected.get();
}
}
+
+ /**
+ * Ensures that a collection passed as a parameter to the calling method
must contain element.
+ *
+ * @param <T> type of exception
+ * @param values values to be checked
+ * @param element element to be checked
+ * @param exceptionSupplierIfUnexpected exception from this supplier will
be thrown if expression is unexpected
+ * @throws T exception to be thrown
+ */
+ public static <T extends Throwable> void checkContains(final Collection<?>
values, final Object element, final Supplier<T> exceptionSupplierIfUnexpected)
throws T {
+ if (!values.contains(element)) {
+ throw exceptionSupplierIfUnexpected.get();
+ }
+ }
+
+ /**
+ * Ensures that a collection passed as a parameter to the calling method
must not contain element.
+ *
+ * @param <T> type of exception
+ * @param values values to be checked
+ * @param element element to be checked
+ * @param exceptionSupplierIfUnexpected exception from this supplier will
be thrown if expression is unexpected
+ * @throws T exception to be thrown
+ */
+ public static <T extends Throwable> void checkNotContains(final
Collection<?> values, final Object element, final Supplier<T>
exceptionSupplierIfUnexpected) throws T {
+ if (values.contains(element)) {
+ throw exceptionSupplierIfUnexpected.get();
+ }
+ }
+
+ /**
+ * Ensures that a map passed as a parameter to the calling method must
contain key.
+ *
+ * @param <T> type of exception
+ * @param map map to be checked
+ * @param key key to be checked
+ * @param exceptionSupplierIfUnexpected exception from this supplier will
be thrown if expression is unexpected
+ * @throws T exception to be thrown
+ */
+ public static <T extends Throwable> void checkContainsKey(final Map<?, ?>
map, final Object key, final Supplier<T> exceptionSupplierIfUnexpected) throws
T {
+ if (!map.containsKey(key)) {
+ throw exceptionSupplierIfUnexpected.get();
+ }
+ }
}
diff --git
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
index 4841749990c..173ea3e4fae 100644
---
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
+++
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
@@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test;
import java.sql.SQLException;
import java.util.Collections;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
class ShardingSpherePreconditionsTest {
@@ -32,8 +33,8 @@ class ShardingSpherePreconditionsTest {
}
@Test
- void assertCheckStateToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkState(true, SQLException::new);
+ void assertCheckStateToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkState(true,
SQLException::new));
}
@Test
@@ -42,8 +43,8 @@ class ShardingSpherePreconditionsTest {
}
@Test
- void assertCheckNotNullToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkNotNull(new Object(),
SQLException::new);
+ void assertCheckNotNullToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkNotNull(new
Object(), SQLException::new));
}
@Test
@@ -53,8 +54,8 @@ class ShardingSpherePreconditionsTest {
}
@Test
- void assertCheckNotEmptyWithStringToNotThrowException() throws
SQLException {
- ShardingSpherePreconditions.checkNotEmpty("foo", SQLException::new);
+ void assertCheckNotEmptyWithStringToNotThrowException() {
+ assertDoesNotThrow(() ->
ShardingSpherePreconditions.checkNotEmpty("foo", SQLException::new));
}
@Test
@@ -63,8 +64,8 @@ class ShardingSpherePreconditionsTest {
}
@Test
- void assertCheckNotEmptyWithCollectionToNotThrowException() throws
SQLException {
-
ShardingSpherePreconditions.checkNotEmpty(Collections.singleton("foo"),
SQLException::new);
+ void assertCheckNotEmptyWithCollectionToNotThrowException() {
+ assertDoesNotThrow(() ->
ShardingSpherePreconditions.checkNotEmpty(Collections.singleton("foo"),
SQLException::new));
}
@Test
@@ -73,8 +74,8 @@ class ShardingSpherePreconditionsTest {
}
@Test
- void assertCheckNotEmptyWithMapToNotThrowException() throws SQLException {
-
ShardingSpherePreconditions.checkNotEmpty(Collections.singletonMap("key",
"value"), SQLException::new);
+ void assertCheckNotEmptyWithMapToNotThrowException() {
+ assertDoesNotThrow(() ->
ShardingSpherePreconditions.checkNotEmpty(Collections.singletonMap("key",
"value"), SQLException::new));
}
@Test
@@ -83,8 +84,8 @@ class ShardingSpherePreconditionsTest {
}
@Test
- void assertCheckMustEmptyWithCollectionToNotThrowException() throws
SQLException {
- ShardingSpherePreconditions.checkMustEmpty(Collections.emptyList(),
SQLException::new);
+ void assertCheckMustEmptyWithCollectionToNotThrowException() {
+ assertDoesNotThrow(() ->
ShardingSpherePreconditions.checkMustEmpty(Collections.emptyList(),
SQLException::new));
}
@Test
@@ -93,7 +94,37 @@ class ShardingSpherePreconditionsTest {
}
@Test
- void assertCheckMustEmptyWithMapToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkMustEmpty(Collections.emptyMap(),
SQLException::new);
+ void assertCheckMustEmptyWithMapToNotThrowException() {
+ assertDoesNotThrow(() ->
ShardingSpherePreconditions.checkMustEmpty(Collections.emptyMap(),
SQLException::new));
+ }
+
+ @Test
+ void assertCheckContainsToNotThrowException() {
+ assertDoesNotThrow(() ->
ShardingSpherePreconditions.checkContains(Collections.singleton("foo"), "foo",
SQLException::new));
+ }
+
+ @Test
+ void assertCheckContainsToThrowsException() {
+ assertThrows(SQLException.class, () ->
ShardingSpherePreconditions.checkContains(Collections.singleton("foo"), "bar",
SQLException::new));
+ }
+
+ @Test
+ void assertCheckNotContainsToNotThrowException() {
+ assertDoesNotThrow(() ->
ShardingSpherePreconditions.checkNotContains(Collections.singleton("foo"),
"bar", SQLException::new));
+ }
+
+ @Test
+ void assertCheckNotContainsToThrowsException() {
+ assertThrows(SQLException.class, () ->
ShardingSpherePreconditions.checkNotContains(Collections.singleton("foo"),
"foo", SQLException::new));
+ }
+
+ @Test
+ void assertCheckContainsKeyToNotThrowException() {
+ assertDoesNotThrow(() ->
ShardingSpherePreconditions.checkContainsKey(Collections.singletonMap("foo",
"value"), "foo", SQLException::new));
+ }
+
+ @Test
+ void assertCheckContainsKeyToThrowsException() {
+ assertThrows(SQLException.class, () ->
ShardingSpherePreconditions.checkContainsKey(Collections.singletonMap("foo",
"value"), "bar", SQLException::new));
}
}
diff --git
a/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
b/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
index 976612ce9dc..6edfed06a84 100644
---
a/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
+++
b/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
@@ -115,20 +115,17 @@ public class IntervalInlineExpressionParser implements
InlineExpressionParser {
}
private String getPrefix(final Map<String, String> props) {
- ShardingSpherePreconditions.checkState(props.containsKey(PREFIX_KEY),
- () -> new RuntimeException(String.format("%s can not be
null.", PREFIX_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, PREFIX_KEY, () ->
new RuntimeException(String.format("%s can not be null.", PREFIX_KEY)));
return props.get(PREFIX_KEY);
}
private TemporalAccessor getDateTimeLower(final Map<String, String> props)
{
-
ShardingSpherePreconditions.checkState(props.containsKey(DATE_TIME_LOWER_KEY),
- () -> new RuntimeException(String.format("%s can not be
null.", DATE_TIME_LOWER_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props,
DATE_TIME_LOWER_KEY, () -> new RuntimeException(String.format("%s can not be
null.", DATE_TIME_LOWER_KEY)));
return getDateTime(props.get(DATE_TIME_LOWER_KEY));
}
private TemporalAccessor getDateTimeUpper(final Map<String, String> props)
{
-
ShardingSpherePreconditions.checkState(props.containsKey(DATE_TIME_UPPER_KEY),
- () -> new RuntimeException(String.format("%s can not be
null.", DATE_TIME_UPPER_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props,
DATE_TIME_UPPER_KEY, () -> new RuntimeException(String.format("%s can not be
null.", DATE_TIME_UPPER_KEY)));
return getDateTime(props.get(DATE_TIME_UPPER_KEY));
}
@@ -144,14 +141,12 @@ public class IntervalInlineExpressionParser implements
InlineExpressionParser {
}
private int getStepAmount(final Map<String, String> props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(INTERVAL_AMOUNT_KEY),
- () -> new RuntimeException(String.format("%s can not be
null.", INTERVAL_AMOUNT_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props,
INTERVAL_AMOUNT_KEY, () -> new RuntimeException(String.format("%s can not be
null.", INTERVAL_AMOUNT_KEY)));
return Integer.parseInt(props.get(INTERVAL_AMOUNT_KEY));
}
private ChronoUnit getStepUnit(final Map<String, String> props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(INTERVAL_UNIT_KEY),
- () -> new RuntimeException(String.format("%s can not be
null.", INTERVAL_UNIT_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, INTERVAL_UNIT_KEY,
() -> new RuntimeException(String.format("%s can not be null.",
INTERVAL_UNIT_KEY)));
String stepUnit = props.get(INTERVAL_UNIT_KEY);
return Arrays.stream(ChronoUnit.values())
.filter(chronoUnit -> chronoUnit.toString().equals(stepUnit))
diff --git
a/infra/merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
b/infra/merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
index 5ecdff7e2a1..b4310c5a231 100644
---
a/infra/merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
+++
b/infra/merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
@@ -74,7 +74,7 @@ public abstract class MemoryMergedResult<T extends
ShardingSphereRule> implement
@Override
public final Object getValue(final int columnIndex, final Class<?> type)
throws SQLException {
-
ShardingSpherePreconditions.checkState(!INVALID_MEMORY_TYPES.contains(type), ()
-> new SQLFeatureNotSupportedException(String.format("Get value from `%s`",
type.getName())));
+ ShardingSpherePreconditions.checkNotContains(INVALID_MEMORY_TYPES,
type, () -> new SQLFeatureNotSupportedException(String.format("Get value from
`%s`", type.getName())));
Object result = currentResultSetRow.getCell(columnIndex);
wasNull = null == result;
return result;
diff --git
a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java
b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java
index e62fc84ce41..c22d89843c2 100644
---
a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java
+++
b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java
@@ -110,8 +110,8 @@ public final class ConsistencyCheckJobAPI {
try (TableDataConsistencyChecker checker =
TableDataConsistencyCheckerFactory.newInstance(param.getAlgorithmTypeName(),
param.getAlgorithmProps())) {
supportedDatabaseTypes = checker.getSupportedDatabaseTypes();
}
-
ShardingSpherePreconditions.checkState(supportedDatabaseTypes.contains(param.getSourceDatabaseType()),
() -> new
UnsupportedPipelineDatabaseTypeException(param.getSourceDatabaseType()));
-
ShardingSpherePreconditions.checkState(supportedDatabaseTypes.contains(param.getTargetDatabaseType()),
() -> new
UnsupportedPipelineDatabaseTypeException(param.getTargetDatabaseType()));
+ ShardingSpherePreconditions.checkContains(supportedDatabaseTypes,
param.getSourceDatabaseType(), () -> new
UnsupportedPipelineDatabaseTypeException(param.getSourceDatabaseType()));
+ ShardingSpherePreconditions.checkContains(supportedDatabaseTypes,
param.getTargetDatabaseType(), () -> new
UnsupportedPipelineDatabaseTypeException(param.getTargetDatabaseType()));
}
private YamlConsistencyCheckJobConfiguration getYamlConfiguration(final
String jobId, final String parentJobId, final
CreateConsistencyCheckJobParameter param) {
diff --git
a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java
b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java
index 8b8d6244684..5e2ff9914d0 100644
---
a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java
+++
b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java
@@ -134,7 +134,7 @@ public final class MigrationJobAPI implements
TransmissionJobAPI {
if (configSources.containsKey(dataSourceName)) {
continue;
}
-
ShardingSpherePreconditions.checkState(metaDataDataSource.containsKey(dataSourceName),
+ ShardingSpherePreconditions.checkContainsKey(metaDataDataSource,
dataSourceName,
() -> new PipelineInvalidParameterException(dataSourceName
+ " doesn't exist. Run `SHOW MIGRATION SOURCE STORAGE UNITS;` to verify it."));
Map<String, Object> sourceDataSourcePoolProps =
dataSourceConfigSwapper.swapToMap(metaDataDataSource.get(dataSourceName));
StandardPipelineDataSourceConfiguration sourceDataSourceConfig =
new StandardPipelineDataSourceConfiguration(sourceDataSourcePoolProps);
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
index 21b50762a7b..34182d0f86b 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
@@ -127,7 +127,7 @@ public final class SingleRuleConfigurationDecorator
implements RuleConfiguration
final
Collection<DataNode> configuredDataNodes) {
Collection<String> result = new LinkedHashSet<>();
for (DataNode each : configuredDataNodes) {
-
ShardingSpherePreconditions.checkState(actualDataNodes.containsKey(each.getTableName()),
() -> new
SingleTableNotFoundException(getTableNodeString(isSchemaSupportedDatabaseType,
each)));
+ ShardingSpherePreconditions.checkContainsKey(actualDataNodes,
each.getTableName(), () -> new
SingleTableNotFoundException(getTableNodeString(isSchemaSupportedDatabaseType,
each)));
DataNode actualDataNode =
actualDataNodes.get(each.getTableName()).iterator().next();
String tableNodeStr =
getTableNodeString(isSchemaSupportedDatabaseType, actualDataNode);
ShardingSpherePreconditions.checkState(actualDataNode.equals(each),
@@ -155,12 +155,11 @@ public final class SingleRuleConfigurationDecorator
implements RuleConfiguration
private void checkRuleConfiguration(final String databaseName, final
Map<String, DataSource> dataSources, final Collection<String> excludedTables,
final Collection<DataNode> dataNodes) {
for (DataNode each : dataNodes) {
if
(!SingleTableConstants.ASTERISK.equals(each.getDataSourceName())) {
-
ShardingSpherePreconditions.checkState(dataSources.containsKey(each.getDataSourceName()),
+ ShardingSpherePreconditions.checkContainsKey(dataSources,
each.getDataSourceName(),
() -> new
InvalidSingleRuleConfigurationException(String.format("Data source `%s` does
not exist in database `%s`", each.getDataSourceName(), databaseName)));
}
-
ShardingSpherePreconditions.checkState(!excludedTables.contains(each.getTableName()),
- () -> new
InvalidSingleRuleConfigurationException(String.format("Table `%s` existed and
is not a single table in database `%s`",
- each.getTableName(), databaseName)));
+ ShardingSpherePreconditions.checkNotContains(excludedTables,
each.getTableName(),
+ () -> new
InvalidSingleRuleConfigurationException(String.format("Table `%s` existed and
is not a single table in database `%s`", each.getTableName(), databaseName)));
}
}
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
index a10465d5e6e..5e9263ba320 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
@@ -95,7 +95,7 @@ public final class LoadSingleTableExecutor implements
DatabaseRuleCreateExecutor
}
private void checkStorageUnits(final LoadSingleTableStatement
sqlStatement) {
-
ShardingSpherePreconditions.checkState(!database.getResourceMetaData().getStorageUnits().isEmpty(),
() -> new EmptyStorageUnitException(database.getName()));
+
ShardingSpherePreconditions.checkNotEmpty(database.getResourceMetaData().getStorageUnits(),
() -> new EmptyStorageUnitException(database.getName()));
Collection<String> requiredDataSources =
getRequiredDataSources(sqlStatement);
if (requiredDataSources.isEmpty()) {
return;
@@ -104,7 +104,7 @@ public final class LoadSingleTableExecutor implements
DatabaseRuleCreateExecutor
Collection<String> logicDataSources =
database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class).stream()
.flatMap(each ->
each.getDataSourceMapper().keySet().stream()).collect(Collectors.toSet());
notExistedDataSources.removeIf(logicDataSources::contains);
-
ShardingSpherePreconditions.checkState(notExistedDataSources.isEmpty(), () ->
new MissingRequiredStorageUnitsException(database.getName(),
notExistedDataSources));
+ ShardingSpherePreconditions.checkMustEmpty(notExistedDataSources, ()
-> new MissingRequiredStorageUnitsException(database.getName(),
notExistedDataSources));
}
private void checkActualTableExist(final LoadSingleTableStatement
sqlStatement, final String defaultSchemaName) {
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutor.java
index 505bfffcca0..8c3d4e0ec43 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutor.java
@@ -48,7 +48,7 @@ public final class SetDefaultSingleTableStorageUnitExecutor
implements DatabaseR
private void checkStorageUnitExist(final
SetDefaultSingleTableStorageUnitStatement sqlStatement) {
if (!Strings.isNullOrEmpty(sqlStatement.getDefaultStorageUnit())) {
Collection<String> storageUnitNames =
database.getResourceMetaData().getStorageUnits().keySet();
-
ShardingSpherePreconditions.checkState(storageUnitNames.contains(sqlStatement.getDefaultStorageUnit()),
+ ShardingSpherePreconditions.checkContains(storageUnitNames,
sqlStatement.getDefaultStorageUnit(),
() -> new
MissingRequiredStorageUnitsException(database.getName(),
Collections.singleton(sqlStatement.getDefaultStorageUnit())));
}
}
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
index 98f5c6c03e0..31692895502 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
@@ -80,14 +80,14 @@ public final class UnloadSingleTableExecutor implements
DatabaseRuleAlterExecuto
}
private void checkIsSingleTable(final Collection<String> singleTables,
final String tableName) {
-
ShardingSpherePreconditions.checkState(singleTables.contains(tableName), () ->
new SingleTableNotFoundException(tableName));
+ ShardingSpherePreconditions.checkContains(singleTables, tableName, ()
-> new SingleTableNotFoundException(tableName));
}
private void checkTableRuleExist(final String databaseName, final
DatabaseType databaseType,
final Collection<DataNode> dataNodes,
final String tableName) {
ShardingSpherePreconditions.checkNotEmpty(dataNodes, () -> new
MissingRequiredRuleException("Single", databaseName, tableName));
DataNode dataNode = dataNodes.iterator().next();
-
ShardingSpherePreconditions.checkState(rule.getConfiguration().getTables().contains(dataNode.format(databaseType)),
() -> new MissingRequiredRuleException("Single", databaseName, tableName));
+
ShardingSpherePreconditions.checkContains(rule.getConfiguration().getTables(),
dataNode.format(databaseType), () -> new MissingRequiredRuleException("Single",
databaseName, tableName));
}
@Override
diff --git
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
index df26d570723..2c846c79f3d 100644
---
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
+++
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
@@ -466,7 +466,7 @@ public final class SQLFederationResultSet extends
AbstractUnsupportedOperationRe
}
private Object getValue(final int columnIndex, final Class<?> type) throws
SQLException {
-
ShardingSpherePreconditions.checkState(!INVALID_FEDERATION_TYPES.contains(type),
() -> new SQLFeatureNotSupportedException(String.format("Get value from `%s`",
type.getName())));
+ ShardingSpherePreconditions.checkNotContains(INVALID_FEDERATION_TYPES,
type, () -> new SQLFeatureNotSupportedException(String.format("Get value from
`%s`", type.getName())));
Object result = currentRows[columnIndex - 1];
wasNull = null == result;
return columnTypeConverter.convertColumnValue(result);
diff --git
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
index 5c7bc31229f..6fbd23187cb 100644
---
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
+++
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
@@ -42,7 +42,7 @@ public final class SQLMatchTrafficAlgorithm implements
SegmentTrafficAlgorithm {
@Override
public void init(final Properties props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(SQL_PROPS_KEY), () ->
new AlgorithmInitializationException(this, "%s cannot be null", SQL_PROPS_KEY));
+ ShardingSpherePreconditions.checkContainsKey(props, SQL_PROPS_KEY, ()
-> new AlgorithmInitializationException(this, "%s cannot be null",
SQL_PROPS_KEY));
sql = getExactlySQL(props.getProperty(SQL_PROPS_KEY));
ShardingSpherePreconditions.checkNotEmpty(String.valueOf(sql), () ->
new AlgorithmInitializationException(this, "SQL must be not empty"));
}
diff --git
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
index 2a4631e1081..dd3a6d16195 100644
---
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
+++
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
@@ -36,7 +36,7 @@ public final class SQLRegexTrafficAlgorithm implements
SegmentTrafficAlgorithm {
@Override
public void init(final Properties props) {
-
ShardingSpherePreconditions.checkState(props.containsKey(REGEX_PROPS_KEY), ()
-> new AlgorithmInitializationException(this, "%s cannot be null",
REGEX_PROPS_KEY));
+ ShardingSpherePreconditions.checkContainsKey(props, REGEX_PROPS_KEY,
() -> new AlgorithmInitializationException(this, "%s cannot be null",
REGEX_PROPS_KEY));
regex = Pattern.compile(props.getProperty(REGEX_PROPS_KEY));
ShardingSpherePreconditions.checkNotEmpty(String.valueOf(regex), () ->
new AlgorithmInitializationException(this, "Regex must be not empty"));
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataExecutor.java
index f590ce5b2dd..ca4ef5f0a20 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataExecutor.java
@@ -64,8 +64,7 @@ public final class RefreshTableMetaDataExecutor implements
DistSQLUpdateExecutor
ShardingSpherePreconditions.checkNotEmpty(storageUnits, () -> new
EmptyStorageUnitException(database.getName()));
if (sqlStatement.getStorageUnitName().isPresent()) {
String storageUnitName = sqlStatement.getStorageUnitName().get();
- ShardingSpherePreconditions.checkState(
- storageUnits.containsKey(storageUnitName), () -> new
MissingRequiredStorageUnitsException(database.getName(),
Collections.singleton(storageUnitName)));
+ ShardingSpherePreconditions.checkContainsKey(storageUnits,
storageUnitName, () -> new
MissingRequiredStorageUnitsException(database.getName(),
Collections.singleton(storageUnitName)));
}
}
diff --git
a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java
b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java
index 61f677dc3ca..cc992b41aac 100644
---
a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java
+++
b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java
@@ -138,7 +138,7 @@ public final class HBaseContext implements AutoCloseable {
* @return HBase connection
*/
public Connection getConnection(final String tableName) {
-
ShardingSpherePreconditions.checkState(tableConnectionMap.containsKey(tableName),
() -> new TableNotFoundException(tableName));
+ ShardingSpherePreconditions.checkContainsKey(tableConnectionMap,
tableName, () -> new TableNotFoundException(tableName));
return tableConnectionMap.get(tableName).getConnection();
}