Skip to content

Commit 4fdb23d

Browse files
authored
delombok var val (#94)
* done for server package * done for config package * done for command.impl package * done for command package * done for all * run refactor auto by intellij * done config props * fix tests
1 parent 9a80c8d commit 4fdb23d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+129
-171
lines changed

app/src/main/java/dev/keva/app/Application.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import com.keva.config.ConfigLoader;
66
import dev.keva.core.config.KevaConfig;
77
import dev.keva.core.server.KevaServer;
8+
import dev.keva.core.server.Server;
89
import lombok.extern.slf4j.Slf4j;
9-
import lombok.val;
1010
import org.slf4j.LoggerFactory;
1111

1212
@Slf4j
1313
public final class Application {
1414
static {
15-
val ctx = (LoggerContext) LoggerFactory.getILoggerFactory();
15+
LoggerContext ctx = (LoggerContext) LoggerFactory.getILoggerFactory();
1616
ctx.getLogger("io.netty").setLevel(Level.OFF);
1717
ctx.getLogger("net.openhft").setLevel(Level.OFF);
1818
ctx.getLogger("org.reflections").setLevel(Level.OFF);
@@ -21,8 +21,8 @@ public final class Application {
2121

2222
public static void main(String[] args) {
2323
try {
24-
val config = ConfigLoader.loadConfig(args, KevaConfig.class);
25-
val server = KevaServer.of(config);
24+
KevaConfig config = ConfigLoader.loadConfig(args, KevaConfig.class);
25+
Server server = KevaServer.of(config);
2626
Runtime.getRuntime().addShutdownHook(new Thread(server::shutdown));
2727
server.run();
2828
} catch (Exception e) {

config/src/main/java/com/keva/config/ConfigLoader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.keva.config;
22

3+
import com.keva.config.util.ArgsHolder;
34
import com.keva.config.util.ArgsParser;
45
import com.keva.config.util.ConfigLoaderUtil;
56
import lombok.extern.slf4j.Slf4j;
6-
import lombok.val;
77

88
import java.io.FileInputStream;
99
import java.io.IOException;
@@ -16,10 +16,10 @@ public final class ConfigLoader {
1616

1717
public static <T> T loadConfig(String[] args, Class<T> clazz) throws IOException {
1818
T returnConf = ConfigLoaderUtil.fromProperties(new Properties(), clazz);
19-
val config = ArgsParser.parse(args);
20-
val overrider = ConfigLoaderUtil.fromArgs(config, clazz);
19+
ArgsHolder config = ArgsParser.parse(args);
20+
T overrider = ConfigLoaderUtil.fromArgs(config, clazz);
2121

22-
val configFilePath = config.getArgVal("f");
22+
String configFilePath = config.getArgVal("f");
2323
if (configFilePath != null) {
2424
returnConf = loadConfigFromFile(configFilePath, clazz);
2525
}
@@ -33,8 +33,8 @@ public static <T> T loadConfigFromFile(String filePath, Class<T> clazz) throws I
3333
if (filePath.isEmpty()) {
3434
filePath = DEFAULT_FILE_PATH;
3535
}
36-
val props = new Properties();
37-
try (val file = new FileInputStream(filePath)) {
36+
Properties props = new Properties();
37+
try (FileInputStream file = new FileInputStream(filePath)) {
3838
props.load(file);
3939
}
4040

config/src/main/java/com/keva/config/util/ArgsParser.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.keva.config.util;
22

3-
import lombok.val;
4-
53
public final class ArgsParser {
64
public static ArgsHolder parse(String[] args) {
7-
val holder = new ArgsHolder();
5+
ArgsHolder holder = new ArgsHolder();
86
for (int i = 0; i < args.length; i++) {
9-
val token = args[i];
7+
String token = args[i];
108
if (token.startsWith("--")) {
11-
val name = token.substring(2);
9+
String name = token.substring(2);
1210
if (i >= args.length - 1) {
1311
holder.addFlag(name);
1412
} else if (args[i + 1].startsWith("--")) {

config/src/main/java/com/keva/config/util/ConfigLoaderUtil.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
import com.keva.config.annotation.ConfigProp;
66
import lombok.NonNull;
77
import lombok.SneakyThrows;
8-
import lombok.val;
98

9+
import java.lang.reflect.Field;
1010
import java.util.Properties;
1111

1212
public class ConfigLoaderUtil {
1313
@SneakyThrows
1414
public static <T> T fromProperties(@NonNull Properties props, Class<T> clazz) {
15-
val configHolder = clazz.getDeclaredConstructor().newInstance();
16-
val fields = clazz.getDeclaredFields();
17-
for (val field : fields) {
15+
T configHolder = clazz.getDeclaredConstructor().newInstance();
16+
Field[] fields = clazz.getDeclaredFields();
17+
for (Field field : fields) {
1818
if (field.isAnnotationPresent(ConfigProp.class)) {
1919
field.setAccessible(true);
20-
val annotation = field.getAnnotation(ConfigProp.class);
21-
val value = parse(props.getProperty(annotation.name(), annotation.defaultVal()), field.getType());
20+
ConfigProp annotation = field.getAnnotation(ConfigProp.class);
21+
Object value = parse(props.getProperty(annotation.name(), annotation.defaultVal()), field.getType());
2222
field.set(configHolder, value);
2323
}
2424
}
@@ -28,21 +28,21 @@ public static <T> T fromProperties(@NonNull Properties props, Class<T> clazz) {
2828

2929
@SneakyThrows
3030
public static <T> T fromArgs(@NonNull ArgsHolder args, Class<T> clazz) {
31-
val configHolder = clazz.getDeclaredConstructor().newInstance();
31+
T configHolder = clazz.getDeclaredConstructor().newInstance();
3232

33-
val fields = clazz.getDeclaredFields();
34-
for (val field : fields) {
33+
Field[] fields = clazz.getDeclaredFields();
34+
for (Field field : fields) {
3535
if (field.isAnnotationPresent(CliProp.class)) {
3636
field.setAccessible(true);
37-
val cliAnnotate = field.getAnnotation(CliProp.class);
37+
CliProp cliAnnotate = field.getAnnotation(CliProp.class);
3838
String strVal = null;
3939
if (cliAnnotate.type() == CliPropType.VAL) {
4040
strVal = args.getArgVal(cliAnnotate.name());
4141
} else if (cliAnnotate.type() == CliPropType.FLAG) {
4242
strVal = args.getFlag(cliAnnotate.name());
4343
}
4444
if (strVal != null) {
45-
val value = parse(strVal, field.getType());
45+
Object value = parse(strVal, field.getType());
4646
field.set(configHolder, value);
4747
}
4848
}
@@ -54,9 +54,9 @@ public static <T> T fromArgs(@NonNull ArgsHolder args, Class<T> clazz) {
5454
@SneakyThrows
5555
public static <T> void merge(T obj1, T obj2) {
5656
if (obj1 != null && obj2 != null && !obj1.equals(obj2)) {
57-
for (val field : obj2.getClass().getDeclaredFields()) {
57+
for (Field field : obj2.getClass().getDeclaredFields()) {
5858
field.setAccessible(true);
59-
val overrideVal = field.get(obj2);
59+
Object overrideVal = field.get(obj2);
6060
if (overrideVal != null) {
6161
field.set(obj1, overrideVal);
6262
}

core/src/main/java/dev/keva/core/aof/AOFManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package dev.keva.core.aof;
22

33
import dev.keva.core.command.mapping.CommandMapper;
4+
import dev.keva.core.command.mapping.CommandWrapper;
45
import dev.keva.core.config.KevaConfig;
56
import dev.keva.ioc.annotation.Autowired;
67
import dev.keva.ioc.annotation.Component;
78
import dev.keva.protocol.resp.Command;
89
import dev.keva.util.hashbytes.BytesKey;
910
import lombok.extern.slf4j.Slf4j;
10-
import lombok.val;
1111

1212
import java.io.IOException;
1313
import java.util.List;
@@ -36,8 +36,8 @@ public void init() {
3636
if (commands != null) {
3737
log.info("Processing {} commands from AOF file", commands.size());
3838
for (Command command : commands) {
39-
val name = command.getName();
40-
val commandWrapper = commandMapper.getMethods().get(new BytesKey(name));
39+
byte[] name = command.getName();
40+
CommandWrapper commandWrapper = commandMapper.getMethods().get(new BytesKey(name));
4141
if (commandWrapper != null) {
4242
commandWrapper.execute(null, command);
4343
}

core/src/main/java/dev/keva/core/command/impl/hash/HDel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import dev.keva.ioc.annotation.Component;
99
import dev.keva.protocol.resp.reply.IntegerReply;
1010
import dev.keva.store.KevaDatabase;
11-
import lombok.val;
1211

1312
@Component
1413
@CommandImpl("hdel")
@@ -25,8 +24,8 @@ public HDel(KevaDatabase database) {
2524
@Execute
2625
public IntegerReply execute(byte[] key, byte[]... fields) {
2726
int deleted = 0;
28-
for (val field : fields) {
29-
val result = database.hdel(key, field);
27+
for (byte[] field : fields) {
28+
boolean result = database.hdel(key, field);
3029
if (result) {
3130
deleted++;
3231
}

core/src/main/java/dev/keva/core/command/impl/hash/HExists.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import dev.keva.ioc.annotation.Component;
88
import dev.keva.protocol.resp.reply.IntegerReply;
99
import dev.keva.store.KevaDatabase;
10-
import lombok.val;
1110

1211
@Component
1312
@CommandImpl("hexists")
@@ -22,7 +21,7 @@ public HExists(KevaDatabase database) {
2221

2322
@Execute
2423
public IntegerReply execute(byte[] key, byte[] field) {
25-
val got = database.hget(key, field);
24+
byte[] got = database.hget(key, field);
2625
return got == null ? new IntegerReply(0) : new IntegerReply(1);
2726
}
2827
}

core/src/main/java/dev/keva/core/command/impl/hash/HGet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import dev.keva.ioc.annotation.Component;
88
import dev.keva.protocol.resp.reply.BulkReply;
99
import dev.keva.store.KevaDatabase;
10-
import lombok.val;
1110

1211
@Component
1312
@CommandImpl("hget")
@@ -22,7 +21,7 @@ public HGet(KevaDatabase database) {
2221

2322
@Execute
2423
public BulkReply execute(byte[] key, byte[] field) {
25-
val got = database.hget(key, field);
24+
byte[] got = database.hget(key, field);
2625
return got == null ? BulkReply.NIL_REPLY : new BulkReply(got);
2726
}
2827
}

core/src/main/java/dev/keva/core/command/impl/hash/HGetAll.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import dev.keva.protocol.resp.reply.BulkReply;
99
import dev.keva.protocol.resp.reply.MultiBulkReply;
1010
import dev.keva.store.KevaDatabase;
11-
import lombok.val;
1211

1312
@Component
1413
@CommandImpl("hgetall")
@@ -23,7 +22,7 @@ public HGetAll(KevaDatabase database) {
2322

2423
@Execute
2524
public MultiBulkReply execute(byte[] key) {
26-
val got = database.hgetAll(key);
25+
byte[][] got = database.hgetAll(key);
2726
BulkReply[] replies = new BulkReply[got.length];
2827
for (int i = 0; i < got.length; i++) {
2928
replies[i] = new BulkReply(got[i]);

core/src/main/java/dev/keva/core/command/impl/hash/HKeys.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import dev.keva.protocol.resp.reply.BulkReply;
99
import dev.keva.protocol.resp.reply.MultiBulkReply;
1010
import dev.keva.store.KevaDatabase;
11-
import lombok.val;
1211

1312
@Component
1413
@CommandImpl("hkeys")
@@ -23,7 +22,7 @@ public HKeys(KevaDatabase database) {
2322

2423
@Execute
2524
public MultiBulkReply execute(byte[] key) {
26-
val got = database.hkeys(key);
25+
byte[][] got = database.hkeys(key);
2726
BulkReply[] replies = new BulkReply[got.length];
2827
for (int i = 0; i < got.length; i++) {
2928
replies[i] = new BulkReply(got[i]);

0 commit comments

Comments
 (0)