Skip to content

Commit 939f890

Browse files
authored
Code style-Optimize some code structures to improve readability (#5293)
1 parent 52df66e commit 939f890

File tree

25 files changed

+65
-20
lines changed

25 files changed

+65
-20
lines changed

apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiJpaImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void appendDataInfluence(String entityName, String entityId, String field
9595
@Override
9696
public void appendDataInfluences(List<Object> entities, Class<?> beanDefinition) {
9797
String tableName = ApolloAuditUtil.getApolloAuditLogTableName(beanDefinition);
98-
if (Objects.isNull(tableName) || tableName.equals("")) {
98+
if (Objects.isNull(tableName) || Objects.equals(tableName, "")) {
9999
return;
100100
}
101101
List<Field> dataInfluenceFields = ApolloAuditUtil.getAnnotatedFields(

apollo-audit/apollo-audit-impl/src/main/java/com/ctrip/framework/apollo/audit/component/ApolloAuditLogApiNoOpImpl.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.ctrip.framework.apollo.audit.dto.ApolloAuditLogDataInfluenceDTO;
2222
import com.ctrip.framework.apollo.audit.dto.ApolloAuditLogDetailsDTO;
2323
import com.ctrip.framework.apollo.audit.dto.ApolloAuditLogDTO;
24+
import java.util.Collections;
2425
import java.util.Date;
2526
import java.util.List;
2627

@@ -50,28 +51,28 @@ public void appendDataInfluences(List<Object> entities, Class<?> beanDefinition)
5051

5152
@Override
5253
public List<ApolloAuditLogDTO> queryLogs(int page, int size) {
53-
return null;
54+
return Collections.emptyList();
5455
}
5556

5657
@Override
5758
public List<ApolloAuditLogDTO> queryLogsByOpName(String opName, Date startDate,
5859
Date endDate, int page, int size) {
59-
return null;
60+
return Collections.emptyList();
6061
}
6162

6263
@Override
6364
public List<ApolloAuditLogDetailsDTO> queryTraceDetails(String traceId) {
64-
return null;
65+
return Collections.emptyList();
6566
}
6667

6768
@Override
6869
public List<ApolloAuditLogDataInfluenceDTO> queryDataInfluencesByField(String entityName,
6970
String entityId, String fieldName, int page, int size) {
70-
return null;
71+
return Collections.emptyList();
7172
}
7273

7374
@Override
7475
public List<ApolloAuditLogDTO> searchLogByNameOrTypeOrOperator(String query, int page, int size) {
75-
return null;
76+
return Collections.emptyList();
7677
}
7778
}

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Audit.java

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public void setOpName(String opName) {
7979
this.opName = opName;
8080
}
8181

82+
@Override
8283
public String toString() {
8384
return toStringHelper().add("entityName", entityName).add("entityId", entityId)
8485
.add("opName", opName).add("comment", comment).toString();

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Cluster.java

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public void setComment(String comment) {
7878
this.comment = comment;
7979
}
8080

81+
@Override
8182
public String toString() {
8283
return toStringHelper().add("name", name).add("appId", appId)
8384
.add("parentClusterId", parentClusterId).add("comment", comment).toString();

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Item.java

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public void setType(int type) {
9999
this.type = type;
100100
}
101101

102+
@Override
102103
public String toString() {
103104
return toStringHelper().add("namespaceId", namespaceId).add("key", key)
104105
.add("type", type).add("value", value)

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Namespace.java

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public void setNamespaceName(String namespaceName) {
7474
this.namespaceName = namespaceName;
7575
}
7676

77+
@Override
7778
public String toString() {
7879
return toStringHelper().add("appId", appId).add("clusterName", clusterName)
7980
.add("namespaceName", namespaceName).toString();

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Privilege.java

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void setPrivilType(String privilType) {
6464
this.privilType = privilType;
6565
}
6666

67+
@Override
6768
public String toString() {
6869
return toStringHelper().add("namespaceId", namespaceId).add("privilType", privilType)
6970
.add("name", name).toString();

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Release.java

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public void setAbandoned(boolean abandoned) {
123123
isAbandoned = abandoned;
124124
}
125125

126+
@Override
126127
public String toString() {
127128
return toStringHelper().add("name", name).add("appId", appId).add("clusterName", clusterName)
128129
.add("namespaceName", namespaceName).add("configurations", configurations)

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ReleaseHistory.java

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public void setOperationContext(String operationContext) {
121121
this.operationContext = operationContext;
122122
}
123123

124+
@Override
124125
public String toString() {
125126
return toStringHelper().add("appId", appId).add("clusterName", clusterName)
126127
.add("namespaceName", namespaceName).add("branchName", branchName)

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/ServerConfig.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public void setCluster(String cluster) {
7777
this.cluster = cluster;
7878
}
7979

80+
@Override
8081
public String toString() {
81-
return toStringHelper().add("key", key).add("value", value).add("comment", comment).toString();
82+
return toStringHelper().add("key", key).add("value", value).add("cluster", cluster).add("comment", comment).toString();
8283
}
8384
}

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/registry/DatabaseServiceRegistryImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ static ServiceRegistry convert(ServiceInstance instance) {
3737
return serviceRegistry;
3838
}
3939

40+
@Override
4041
public void register(ServiceInstance instance) {
4142
ServiceRegistry serviceRegistry = convert(instance);
4243
this.serviceRegistryService.saveIfNotExistByServiceNameAndUri(serviceRegistry);
4344
}
4445

46+
@Override
4547
public void deregister(ServiceInstance instance) {
4648
ServiceRegistry serviceRegistry = convert(instance);
4749
this.serviceRegistryService.delete(serviceRegistry);

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/registry/configuration/support/ApolloServiceRegistryProperties.java

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public void setEnabled(boolean enabled) {
9797
this.enabled = enabled;
9898
}
9999

100+
@Override
100101
public String getServiceName() {
101102
return serviceName;
102103
}

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ReleaseMessageKeyGenerator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.ctrip.framework.apollo.core.ConfigConsts;
2323
import com.google.common.base.Splitter;
24+
import java.util.Collections;
2425
import java.util.List;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
@@ -42,7 +43,7 @@ public static List<String> messageToList(String message) {
4243
//message should be appId+cluster+namespace
4344
if (keys.size() != 3) {
4445
logger.error("message format invalid - {}", message);
45-
return null;
46+
return Collections.emptyList();
4647
}
4748
return keys;
4849
}

apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/utils/ReleaseKeyGeneratorTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
import java.util.List;
2525
import org.junit.Test;
26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
2826

2927
import java.util.Set;
3028
import java.util.concurrent.CountDownLatch;
@@ -33,7 +31,6 @@
3331
import java.util.concurrent.TimeUnit;
3432

3533
import static org.junit.Assert.assertEquals;
36-
import static org.junit.Assert.assertNull;
3734

3835
/**
3936
* @author Jason Song([email protected])
@@ -80,7 +77,8 @@ public void testMessageToList() {
8077

8178
message = "appId+cluster";
8279
keys = ReleaseMessageKeyGenerator.messageToList(message);
83-
assertNull(keys);
80+
assert keys != null;
81+
assertEquals(0, keys.size());
8482
}
8583

8684
private Runnable generateReleaseKeysTask(Namespace namespace, Set<String> releaseKeys,

apollo-common/src/main/java/com/ctrip/framework/apollo/common/datasource/ApolloDataSourceScriptDatabaseInitializerFactory.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.security.CodeSource;
2121
import java.util.ArrayList;
2222
import java.util.Collection;
23+
import java.util.Collections;
2324
import java.util.List;
2425
import javax.sql.DataSource;
2526
import org.springframework.boot.jdbc.DataSourceBuilder;
@@ -101,7 +102,7 @@ private static List<String> resolveLocations(Collection<String> locations,
101102
private static Collection<String> convertRepositoryLocations(Collection<String> locations,
102103
DataSource dataSource) {
103104
if (CollectionUtils.isEmpty(locations)) {
104-
return null;
105+
return Collections.emptyList();
105106
}
106107
String repositoryDir = findRepositoryDirectory();
107108
String suffix = findSuffix(dataSource);

apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/App.java

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public void setOwnerName(String ownerName) {
111111
this.ownerName = ownerName;
112112
}
113113

114+
@Override
114115
public String toString() {
115116
return toStringHelper().add("name", name).add("appId", appId)
116117
.add("orgId", orgId)

apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/AppNamespace.java

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public void setFormat(String format) {
107107
this.format = format;
108108
}
109109

110+
@Override
110111
public String toString() {
111112
return toStringHelper().add("name", name).add("appId", appId).add("comment", comment)
112113
.add("format", format).add("isPublic", isPublic).toString();

apollo-common/src/main/java/com/ctrip/framework/apollo/common/entity/BaseEntity.java

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ protected ToStringHelper toStringHelper() {
149149
.add("dataChangeLastModifiedTime", dataChangeLastModifiedTime);
150150
}
151151

152+
@Override
152153
public String toString(){
153154
return toStringHelper().toString();
154155
}

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/PortalSettings.java

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public HealthCheckTask(ApplicationContext context) {
117117
}
118118
}
119119

120+
@Override
120121
public void run() {
121122

122123
for (Env env : allEnvs) {

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/RestTemplateFactory.java

+4
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ public RestTemplateFactory(final HttpMessageConverters httpMessageConverters,
4747
this.apolloAuditHttpInterceptor = apolloAuditHttpInterceptor;
4848
}
4949

50+
@Override
5051
public RestTemplate getObject() {
5152
return restTemplate;
5253
}
5354

55+
@Override
5456
public Class<RestTemplate> getObjectType() {
5557
return RestTemplate.class;
5658
}
5759

60+
@Override
5861
public boolean isSingleton() {
5962
return true;
6063
}
6164

65+
@Override
6266
public void afterPropertiesSet() throws UnsupportedEncodingException {
6367

6468
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/SystemInfoController.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.ctrip.framework.apollo.portal.environment.Env;
2626
import com.ctrip.framework.apollo.portal.environment.PortalMetaDomainService;
2727
import java.util.List;
28+
import java.util.Objects;
2829
import javax.annotation.PostConstruct;
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
@@ -145,6 +146,6 @@ private ServiceDTO[] getServerAddress(String metaServerAddress, String path) {
145146
}
146147

147148
private boolean isValidVersion(String version) {
148-
return !version.equals("java-null");
149+
return !Objects.equals(version, "java-null");
149150
}
150151
}

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/po/ServerConfig.java

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public void setComment(String comment) {
7474
this.comment = comment;
7575
}
7676

77+
@Override
7778
public String toString() {
7879
return toStringHelper().add("key", key).add("value", value).add("comment", comment).toString();
7980
}

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultRoleInitializationService.java

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public DefaultRoleInitializationService(final RolePermissionService rolePermissi
5757
}
5858

5959
@Transactional
60+
@Override
6061
public void initAppRoles(App app) {
6162
String appId = app.getAppId();
6263

@@ -91,6 +92,7 @@ public void initAppRoles(App app) {
9192
}
9293

9394
@Transactional
95+
@Override
9496
public void initNamespaceRoles(String appId, String namespaceName, String operator) {
9597

9698
String modifyNamespaceRoleName = RoleUtils.buildModifyNamespaceRoleName(appId, namespaceName);
@@ -107,6 +109,7 @@ public void initNamespaceRoles(String appId, String namespaceName, String operat
107109
}
108110

109111
@Transactional
112+
@Override
110113
public void initNamespaceEnvRoles(String appId, String namespaceName, String operator) {
111114
List<Env> portalEnvs = portalConfig.portalSupportedEnvs();
112115

@@ -116,6 +119,7 @@ public void initNamespaceEnvRoles(String appId, String namespaceName, String ope
116119
}
117120

118121
@Transactional
122+
@Override
119123
public void initNamespaceSpecificEnvRoles(String appId, String namespaceName, String env, String operator) {
120124
String modifyNamespaceEnvRoleName = RoleUtils.buildModifyNamespaceRoleName(appId, namespaceName, env);
121125
if (rolePermissionService.findRoleByRoleName(modifyNamespaceEnvRoleName) == null) {
@@ -131,6 +135,7 @@ public void initNamespaceSpecificEnvRoles(String appId, String namespaceName, St
131135
}
132136

133137
@Transactional
138+
@Override
134139
public void initCreateAppRole() {
135140
if (rolePermissionService.findRoleByRoleName(SystemRoleManagerService.CREATE_APPLICATION_ROLE_NAME) != null) {
136141
return;
@@ -158,6 +163,7 @@ public void createManageAppMasterRole(String appId, String operator) {
158163

159164
// fix historical data
160165
@Transactional
166+
@Override
161167
public void initManageAppMasterRole(String appId, String operator) {
162168
String manageAppMasterRoleName = RoleUtils.buildAppRoleName(appId, PermissionType.MANAGE_APP_MASTER);
163169
if (rolePermissionService.findRoleByRoleName(manageAppMasterRoleName) != null) {

0 commit comments

Comments
 (0)