不变属性添加final关键字

This commit is contained in:
庄佳彬 2023-05-12 11:29:40 +08:00
parent 2be8dc0c39
commit 203b7dff12
4 changed files with 13 additions and 17 deletions

View File

@ -25,8 +25,8 @@ import java.util.Enumeration;
*/ */
public class DefaultMessageFactory implements MessageFactory { public class DefaultMessageFactory implements MessageFactory {
private String platform = "mybatis-flex"; private final String platform = "mybatis-flex";
private String hostIp = getHostIp(); private final String hostIp = getHostIp();
@Override @Override

View File

@ -28,12 +28,12 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
*/ */
public class ScheduledMessageCollector implements MessageCollector, Runnable { public class ScheduledMessageCollector implements MessageCollector, Runnable {
private long period; private final long period;
private ScheduledExecutorService scheduler; private final ScheduledExecutorService scheduler;
private MessageReporter messageSender; private final MessageReporter messageSender;
private List<AuditMessage> messages = Collections.synchronizedList(new ArrayList<>()); private final List<AuditMessage> messages = Collections.synchronizedList(new ArrayList<>());
private ReentrantReadWriteLock rrwLock = new ReentrantReadWriteLock(); private final ReentrantReadWriteLock rrwLock = new ReentrantReadWriteLock();
public ScheduledMessageCollector() { public ScheduledMessageCollector() {
this(10, new ConsoleMessageReporter()); this(10, new ConsoleMessageReporter());

View File

@ -22,9 +22,9 @@ import java.util.List;
public class HttpMessageReporter implements MessageReporter { public class HttpMessageReporter implements MessageReporter {
private String endpoint; private final String endpoint;
private String secretKey; private final String secretKey;
private JSONFormatter jsonFormatter; private final JSONFormatter jsonFormatter;
public HttpMessageReporter(String endpoint, String secretKey, JSONFormatter jsonFormatter) { public HttpMessageReporter(String endpoint, String secretKey, JSONFormatter jsonFormatter) {
this.endpoint = endpoint; this.endpoint = endpoint;

View File

@ -27,7 +27,7 @@ import java.util.Map;
public class DataSourceBuilder { public class DataSourceBuilder {
private static Map<String, String> dataSourceAlias = new HashMap<>(); private static final Map<String, String> dataSourceAlias = new HashMap<>();
static { static {
dataSourceAlias.put("druid", "com.alibaba.druid.pool.DruidDataSource"); dataSourceAlias.put("druid", "com.alibaba.druid.pool.DruidDataSource");
@ -39,7 +39,7 @@ public class DataSourceBuilder {
dataSourceAlias.put("dbcp2", "org.apache.commons.dbcp2.BasicDataSource"); dataSourceAlias.put("dbcp2", "org.apache.commons.dbcp2.BasicDataSource");
} }
private Map<String, String> dataSourceProperties; private final Map<String, String> dataSourceProperties;
public DataSourceBuilder(Map<String, String> dataSourceProperties) { public DataSourceBuilder(Map<String, String> dataSourceProperties) {
this.dataSourceProperties = dataSourceProperties; this.dataSourceProperties = dataSourceProperties;
@ -49,11 +49,7 @@ public class DataSourceBuilder {
String dataSourceClassName = null; String dataSourceClassName = null;
String type = dataSourceProperties.get("type"); String type = dataSourceProperties.get("type");
if (StringUtil.isNotBlank(type)) { if (StringUtil.isNotBlank(type)) {
if (dataSourceAlias.containsKey(type)) { dataSourceClassName = dataSourceAlias.getOrDefault(type, type);
dataSourceClassName = dataSourceAlias.get(type);
} else {
dataSourceClassName = type;
}
} else { } else {
dataSourceClassName = detectDataSourceClass(); dataSourceClassName = detectDataSourceClass();
} }