Skip to content

Commit

Permalink
Use guava Strings.isNullOrEmpty instead of other StringUtils (apache#…
Browse files Browse the repository at this point in the history
…28276)

* Minor changes for code format

* Minor changes for code format

* Use guava Strings.isNullOrEmpty instead of other StringUtils
  • Loading branch information
terrymanu authored Aug 27, 2023
1 parent 075ad9b commit 31dfbbf
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.shardingsphere.driver.jdbc.core.driver.spi;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider;

import java.io.BufferedReader;
Expand All @@ -39,7 +39,7 @@ public final class AbsolutePathURLProvider implements ShardingSphereURLProvider

@Override
public boolean accept(final String url) {
return StringUtils.isNotBlank(url) && url.contains(PATH_TYPE);
return !Strings.isNullOrEmpty(url) && url.contains(PATH_TYPE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Strings;
import org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider;

import java.nio.charset.StandardCharsets;
Expand All @@ -35,7 +35,7 @@ public final class ApolloURLProvider implements ShardingSphereURLProvider {

@Override
public boolean accept(final String url) {
return StringUtils.isNotBlank(url) && url.contains(APOLLO_TYPE);
return !Strings.isNullOrEmpty(url) && url.contains(APOLLO_TYPE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.shardingsphere.driver.jdbc.core.driver.spi;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLProvider;

import java.io.BufferedReader;
Expand All @@ -37,7 +37,7 @@ public final class ClasspathURLProvider implements ShardingSphereURLProvider {

@Override
public boolean accept(final String url) {
return StringUtils.isNotBlank(url) && url.contains(CLASSPATH_TYPE);
return !Strings.isNullOrEmpty(url) && url.contains(CLASSPATH_TYPE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

package org.apache.shardingsphere.data.pipeline.common.metadata.generator;

import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.data.pipeline.spi.ddlgenerator.CreateTableSQLGenerator;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterTableStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.ddl.CommentStatementContext;
Expand All @@ -29,6 +28,7 @@
import org.apache.shardingsphere.infra.binder.context.type.ConstraintAvailable;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.util.IndexMetaDataUtils;
Expand Down Expand Up @@ -87,7 +87,7 @@ public String generateLogicDDL(final DatabaseType databaseType, final DataSource

private Optional<String> decorate(final DatabaseType databaseType, final DataSource dataSource, final String schemaName, final String targetTableName,
final SQLParserEngine parserEngine, final String sql) throws SQLException {
if (StringUtils.isBlank(sql)) {
if (Strings.isNullOrEmpty(sql)) {
return Optional.empty();
}
String databaseName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -97,7 +96,7 @@ private void initServiceMetaData() {
serviceController = new ServiceController();
for (ServiceMetaData each : serviceController.getAllServices()) {
Integer port = client.getAllInstances(each.getServiceName(), false).stream()
.filter(instance -> StringUtils.equals(instance.getIp(), ip)).map(Instance::getPort).max(Comparator.naturalOrder()).orElse(Integer.MIN_VALUE);
.filter(instance -> ip.equals(instance.getIp())).map(Instance::getPort).max(Comparator.naturalOrder()).orElse(Integer.MIN_VALUE);
each.setIp(ip);
each.setPort(new AtomicInteger(port));
}
Expand Down Expand Up @@ -292,7 +291,7 @@ public void delete(final String key) {
Collection<Instance> instances = findExistedInstance(each.isEphemeral()).stream()
.filter(instance -> {
String fullPath = NacosMetaDataUtils.getKey(instance);
return fullPath.startsWith(key + PATH_SEPARATOR) || StringUtils.equals(fullPath, key);
return fullPath.startsWith(key + PATH_SEPARATOR) || key.equals(fullPath);
})
.sorted(Comparator.comparing(NacosMetaDataUtils::getKey).reversed()).collect(Collectors.toList());
Collection<KeyValue> keyValues = new LinkedList<>();
Expand Down Expand Up @@ -339,7 +338,7 @@ private boolean isAvailable(final Collection<KeyValue> keyValues) throws NacosEx
keyValues.removeIf(keyValue -> {
Collection<Instance> instances = instanceMap.get(keyValue.getKey());
String value = keyValue.getValue();
return CollectionUtils.isNotEmpty(instances) ? instances.stream().anyMatch(instance -> StringUtils.equals(NacosMetaDataUtils.getValue(instance), value)) : null == value;
return CollectionUtils.isNotEmpty(instances) ? instances.stream().anyMatch(instance -> Objects.equals(NacosMetaDataUtils.getValue(instance), value)) : null == value;
});
}
return keyValues.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.listener.NamingEvent;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.common.utils.StringUtils;
import com.google.common.util.concurrent.SettableFuture;
import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterPersistRepositoryException;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterPersistRepositoryException;
import org.apache.shardingsphere.mode.repository.cluster.nacos.entity.ServiceController;
import org.apache.shardingsphere.mode.repository.cluster.nacos.entity.ServiceMetaData;
import org.apache.shardingsphere.mode.repository.cluster.nacos.props.NacosProperties;
Expand All @@ -50,6 +49,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -361,7 +361,7 @@ private VoidAnswer2<String, EventListener> getListenerAnswer(final Instance preI
private VoidAnswer2<String, Instance> getRegisterInstanceAnswer() {
return (serviceName, instance) -> {
List<Instance> instances = client.getAllInstances(serviceName, false);
instances.removeIf(each -> StringUtils.equals(each.getIp(), instance.getIp()) && each.getPort() == instance.getPort());
instances.removeIf(each -> Objects.equals(each.getIp(), instance.getIp()) && each.getPort() == instance.getPort());
instances.add(instance);
when(client.getAllInstances(serviceName, false)).thenReturn(instances);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static JDBCRepositorySQL load(final String type) {
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
result = JAR_URL_PROTOCOLS.contains(resource.getProtocol()) ? loadFromJar(resource, type) : loadFromDirectory(resource, type);
if (null != result && Objects.equals(result.isDefault(), false)) {
if (null != result && !result.isDefault()) {
break;
}
}
Expand All @@ -85,8 +85,7 @@ private static JDBCRepositorySQL loadFromDirectory(final URL url, final String t
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attributes) throws IOException {
if (file.toString().endsWith(FILE_EXTENSION)) {
JDBCRepositorySQL provider = (JDBCRepositorySQL) JAXBContext.newInstance(JDBCRepositorySQL.class).createUnmarshaller()
.unmarshal(Files.newInputStream(file.toFile().toPath()));
JDBCRepositorySQL provider = (JDBCRepositorySQL) JAXBContext.newInstance(JDBCRepositorySQL.class).createUnmarshaller().unmarshal(Files.newInputStream(file.toFile().toPath()));
if (provider.isDefault()) {
result[0] = provider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

package org.apache.shardingsphere.test.e2e.env.container.atomic.util;

import com.google.common.base.Strings;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;

/**
* Database version parser.
Expand All @@ -34,6 +34,6 @@ public final class DatabaseVersionParser {
* @return major version
*/
public static String parseMajorVersion(final String storageContainerImage) {
return StringUtils.isBlank(storageContainerImage) ? "" : storageContainerImage.substring(storageContainerImage.indexOf(':') + 1, storageContainerImage.indexOf('.'));
return Strings.isNullOrEmpty(storageContainerImage) ? "" : storageContainerImage.substring(storageContainerImage.indexOf(':') + 1, storageContainerImage.indexOf('.'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.apache.shardingsphere.test.loader.strategy.impl;

import com.google.common.base.Strings;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.test.loader.strategy.TestParameterLoadStrategy;
import org.apache.shardingsphere.test.loader.summary.FileSummary;

Expand Down Expand Up @@ -82,7 +82,7 @@ private URI getGitHubApiUri(final URI sqlCaseURI) {
private String loadContent(final URI casesURI) {
try {
URLConnection urlConnection = casesURI.toURL().openConnection();
if (StringUtils.isNotBlank(GitHubEnvironment.getInstance().getGithubToken())) {
if (!Strings.isNullOrEmpty(GitHubEnvironment.getInstance().getGithubToken())) {
urlConnection.setRequestProperty("Authorization", "Bearer " + GitHubEnvironment.getInstance().getGithubToken());
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()))) {
Expand Down

0 comments on commit 31dfbbf

Please sign in to comment.