You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/05/17 05:55:34 UTC
[shardingsphere] branch master updated: Remove usage of Maps.filterKeys (#17722)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 f074968957b Remove usage of Maps.filterKeys (#17722)
f074968957b is described below
commit f074968957b16b3f364bf4a6caa499a60f719bfd
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue May 17 13:55:23 2022 +0800
Remove usage of Maps.filterKeys (#17722)
---
...ractShardingSphereDataSourceForEncryptTest.java | 22 +++++++++++-----------
...gSphereDataSourceForReadwriteSplittingTest.java | 19 ++++++++++---------
...tractShardingSphereDataSourceForShadowTest.java | 19 ++++++++++---------
...actShardingSphereDataSourceForShardingTest.java | 16 ++++++++--------
.../mode/manager/ContextManager.java | 4 ++--
5 files changed, 41 insertions(+), 39 deletions(-)
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForEncryptTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForEncryptTest.java
index e40f6c73d93..361483e54ba 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForEncryptTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForEncryptTest.java
@@ -17,8 +17,6 @@
package org.apache.shardingsphere.driver.jdbc.base;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
@@ -36,7 +34,9 @@ import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
+import java.util.stream.Collectors;
public abstract class AbstractShardingSphereDataSourceForEncryptTest extends AbstractSQLTest {
@@ -46,27 +46,27 @@ public abstract class AbstractShardingSphereDataSourceForEncryptTest extends Abs
private static final List<String> ACTUAL_DATA_SOURCE_NAMES = Collections.singletonList("encrypt");
- private static final String ENCRYPT_CONFIG_QUERY_WITH_PLAIN_FILE = "config/config-encrypt-query-with-plain.yaml";
+ private static final String CONFIG_FILE_WITH_QUERY_WITH_PLAIN = "config/config-encrypt-query-with-plain.yaml";
- private static final String ENCRYPT_CONFIG_QUERY_WITH_CIPHER_FILE = "config/config-encrypt-query-with-cipher.yaml";
+ private static final String CONFIG_FILE_WITH_QUERY_WITH_CIPHER = "config/config-encrypt-query-with-cipher.yaml";
@BeforeClass
public static void initEncryptDataSource() throws SQLException, IOException {
if (null != queryWithPlainDataSource && null != queryWithCipherDataSource) {
return;
}
- DataSource dataSource = getDataSources().values().iterator().next();
- queryWithPlainDataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(dataSource, getFile(ENCRYPT_CONFIG_QUERY_WITH_CIPHER_FILE));
- queryWithCipherDataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(dataSource, getFile(ENCRYPT_CONFIG_QUERY_WITH_PLAIN_FILE));
+ DataSource dataSource = getDataSourceMap().values().iterator().next();
+ queryWithPlainDataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(dataSource, getFile(CONFIG_FILE_WITH_QUERY_WITH_CIPHER));
+ queryWithCipherDataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(dataSource, getFile(CONFIG_FILE_WITH_QUERY_WITH_PLAIN));
}
private static File getFile(final String fileName) {
- return new File(Preconditions.checkNotNull(
- AbstractShardingSphereDataSourceForEncryptTest.class.getClassLoader().getResource(fileName), "file resource `%s` must not be null.", fileName).getFile());
+ return new File(Objects.requireNonNull(
+ AbstractShardingSphereDataSourceForEncryptTest.class.getClassLoader().getResource(fileName), String.format("File `%s` is not existed.", fileName)).getFile());
}
- private static Map<String, DataSource> getDataSources() {
- return Maps.filterKeys(getActualDataSources(), ACTUAL_DATA_SOURCE_NAMES::contains);
+ private static Map<String, DataSource> getDataSourceMap() {
+ return getActualDataSources().entrySet().stream().filter(entry -> ACTUAL_DATA_SOURCE_NAMES.contains(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
@Before
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForReadwriteSplittingTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForReadwriteSplittingTest.java
index 452f7b45e6e..50c6f7db1e4 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForReadwriteSplittingTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForReadwriteSplittingTest.java
@@ -17,8 +17,6 @@
package org.apache.shardingsphere.driver.jdbc.base;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.junit.AfterClass;
@@ -31,12 +29,15 @@ import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.stream.Collectors;
public abstract class AbstractShardingSphereDataSourceForReadwriteSplittingTest extends AbstractSQLTest {
private static ShardingSphereDataSource dataSource;
- private static final String CONFIG = "config/config-readwrite-splitting.yaml";
+ private static final String CONFIG_FILE = "config/config-readwrite-splitting.yaml";
private static final List<String> ACTUAL_DATA_SOURCE_NAMES = Arrays.asList("test_write_ds", "test_read_ds");
@@ -45,16 +46,16 @@ public abstract class AbstractShardingSphereDataSourceForReadwriteSplittingTest
if (null != dataSource) {
return;
}
- dataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(getDataSources(), getFile(CONFIG));
+ dataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(getDataSourceMap(), getFile());
}
- private static Map<String, DataSource> getDataSources() {
- return Maps.filterKeys(getActualDataSources(), ACTUAL_DATA_SOURCE_NAMES::contains);
+ private static Map<String, DataSource> getDataSourceMap() {
+ return getActualDataSources().entrySet().stream().filter(entry -> ACTUAL_DATA_SOURCE_NAMES.contains(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
- private static File getFile(final String fileName) {
- return new File(Preconditions.checkNotNull(
- AbstractShardingSphereDataSourceForReadwriteSplittingTest.class.getClassLoader().getResource(fileName), "file resource `%s` must not be null.", fileName).getFile());
+ private static File getFile() {
+ return new File(Objects.requireNonNull(
+ AbstractShardingSphereDataSourceForReadwriteSplittingTest.class.getClassLoader().getResource(CONFIG_FILE), String.format("File `%s` is not existed.", CONFIG_FILE)).getFile());
}
protected final ShardingSphereDataSource getReadwriteSplittingDataSource() {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShadowTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShadowTest.java
index de0b2303f7e..e0078c78aa6 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShadowTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShadowTest.java
@@ -17,8 +17,6 @@
package org.apache.shardingsphere.driver.jdbc.base;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.junit.AfterClass;
@@ -31,12 +29,15 @@ import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.stream.Collectors;
public abstract class AbstractShardingSphereDataSourceForShadowTest extends AbstractSQLTest {
private static ShardingSphereDataSource dataSource;
- private static final String CONFIG_SHADOW = "config/config-shadow.yaml";
+ private static final String CONFIG_FILE = "config/config-shadow.yaml";
private static final List<String> ACTUAL_DATA_SOURCE_NAMES = Arrays.asList("shadow_jdbc_0", "shadow_jdbc_1");
@@ -45,16 +46,16 @@ public abstract class AbstractShardingSphereDataSourceForShadowTest extends Abst
if (null != dataSource) {
return;
}
- dataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(getDataSources(), getFile(CONFIG_SHADOW));
+ dataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(getDataSourceMap(), getFile());
}
- private static Map<String, DataSource> getDataSources() {
- return Maps.filterKeys(getActualDataSources(), ACTUAL_DATA_SOURCE_NAMES::contains);
+ private static Map<String, DataSource> getDataSourceMap() {
+ return getActualDataSources().entrySet().stream().filter(entry -> ACTUAL_DATA_SOURCE_NAMES.contains(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
- private static File getFile(final String fileName) {
- return new File(Preconditions.checkNotNull(
- AbstractShardingSphereDataSourceForShadowTest.class.getClassLoader().getResource(fileName), "file resource `%s` must not be null.", fileName).getFile());
+ private static File getFile() {
+ return new File(Objects.requireNonNull(
+ AbstractShardingSphereDataSourceForShadowTest.class.getClassLoader().getResource(CONFIG_FILE), String.format("File `%s` is not existed.", CONFIG_FILE)).getFile());
}
protected final ShardingSphereDataSource getShadowDataSource() {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShardingTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShardingTest.java
index 2ab45fd76e8..eeac945d679 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShardingTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShardingTest.java
@@ -17,8 +17,6 @@
package org.apache.shardingsphere.driver.jdbc.base;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.h2.tools.RunScript;
@@ -35,7 +33,9 @@ import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
+import java.util.stream.Collectors;
public abstract class AbstractShardingSphereDataSourceForShardingTest extends AbstractSQLTest {
@@ -43,23 +43,23 @@ public abstract class AbstractShardingSphereDataSourceForShardingTest extends Ab
private static final List<String> ACTUAL_DATA_SOURCE_NAMES = Arrays.asList("jdbc_0", "jdbc_1");
- private static final String CONFIG_SHARDING = "config/config-sharding.yaml";
+ private static final String CONFIG_FILE = "config/config-sharding.yaml";
@BeforeClass
public static void initShardingSphereDataSource() throws SQLException, IOException {
if (null != dataSource) {
return;
}
- dataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(getDataSourceMap(), getFile(CONFIG_SHARDING));
+ dataSource = (ShardingSphereDataSource) YamlShardingSphereDataSourceFactory.createDataSource(getDataSourceMap(), getFile());
}
private static Map<String, DataSource> getDataSourceMap() {
- return Maps.filterKeys(getActualDataSources(), ACTUAL_DATA_SOURCE_NAMES::contains);
+ return getActualDataSources().entrySet().stream().filter(entry -> ACTUAL_DATA_SOURCE_NAMES.contains(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
- private static File getFile(final String fileName) {
- return new File(Preconditions.checkNotNull(
- AbstractShardingSphereDataSourceForShardingTest.class.getClassLoader().getResource(fileName), "file resource `%s` must not be null.", fileName).getFile());
+ private static File getFile() {
+ return new File(Objects.requireNonNull(
+ AbstractShardingSphereDataSourceForShardingTest.class.getClassLoader().getResource(CONFIG_FILE), String.format("File `%s` is not existed.", CONFIG_FILE)).getFile());
}
@Before
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
index 7002f55c91e..30912239258 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.mode.manager;
-import com.google.common.collect.Maps;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -594,7 +593,8 @@ public final class ContextManager implements AutoCloseable {
}
private Map<String, DataSource> getAddedDataSources(final ShardingSphereMetaData originalMetaData, final Map<String, DataSourceProperties> newDataSourcePropsMap) {
- return DataSourcePoolCreator.create(Maps.filterKeys(newDataSourcePropsMap, each -> !originalMetaData.getResource().getDataSources().containsKey(each)));
+ return DataSourcePoolCreator.create(newDataSourcePropsMap.entrySet().stream()
+ .filter(entry -> !originalMetaData.getResource().getDataSources().containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
}
private Map<String, DataSource> buildChangedDataSources(final ShardingSphereMetaData originalMetaData, final Map<String, DataSourceProperties> newDataSourcePropsMap) {