Commit d7c1beda authored by amir.yosef's avatar amir.yosef

Update CommandUtil

parent d8ae6da7
...@@ -2,46 +2,23 @@ package util; ...@@ -2,46 +2,23 @@ package util;
import model.Command; import model.Command;
import java.util.Map;
public class CommandUtil { public class CommandUtil {
private static final Map<String, Command> COMMAND_MAP = Map.of(
"echo", Command.ECHO,
"ping", Command.PING,
"set", Command.SET,
"get", Command.GET,
"info", Command.INFO
);
public static Command getCommand(String command) { public static Command getCommand(String command) {
if (command.toLowerCase().contains(Command.ECHO.getValue().toLowerCase())) { return COMMAND_MAP.entrySet().stream()
return Command.ECHO; .filter(entry -> command.toLowerCase().contains(entry.getKey().toLowerCase()))
} else if (command.toLowerCase().contains(Command.PING.getValue().toLowerCase())) { .map(Map.Entry::getValue)
return Command.PING; .findFirst()
} else if (command.toLowerCase().contains(Command.SET.getValue().toLowerCase())) { .orElse(Command.UNKNOWN);
return Command.SET;
} else if (command.toLowerCase().contains(Command.GET.getValue().toLowerCase())) {
return Command.GET;
} else if (command.toLowerCase().contains(Command.INFO.getValue().toLowerCase())) {
return Command.INFO;
} else if (command.toLowerCase().contains(Command.REPLCONF.getValue().toLowerCase()) || command.equalsIgnoreCase(Command.REPLCONF.getValue())) {
return Command.REPLCONF;
} else if (command.toLowerCase().contains(Command.FULLRESYNC.getValue().toLowerCase()) || command.equalsIgnoreCase(Command.FULLRESYNC.getValue())) {
return Command.FULLRESYNC;
} else if (command.toLowerCase().contains(Command.PSYNC.getValue()) || command.equalsIgnoreCase(Command.PSYNC.getValue())) {
return Command.PSYNC;
} else if (command.toLowerCase().contains(Command.WAIT.getValue()) || command.equalsIgnoreCase(Command.WAIT.getValue())) {
return Command.WAIT;
} else if (command.toLowerCase().contains(Command.CONFIG.getValue()) || command.equalsIgnoreCase(Command.CONFIG.getValue())) {
return Command.CONFIG;
} else if (command.toLowerCase().contains(Command.KEYS.getValue()) || command.equalsIgnoreCase(Command.KEYS.getValue())) {
return Command.KEYS;
} else if (command.toLowerCase().contains(Command.TYPE.getValue()) || command.equalsIgnoreCase(Command.TYPE.getValue())) {
return Command.TYPE;
} else if (command.toLowerCase().contains(Command.XADD.getValue()) || command.equalsIgnoreCase(Command.XADD.getValue())) {
return Command.XADD;
} else if (command.toLowerCase().contains(Command.XRANGE.getValue()) || command.equalsIgnoreCase(Command.XRANGE.getValue())) {
return Command.XRANGE;
} else if (command.toLowerCase().contains(Command.XREAD.getValue()) || command.equalsIgnoreCase(Command.XREAD.getValue())) {
return Command.XREAD;
} else if (command.toLowerCase().contains(Command.INCR.getValue()) || command.equalsIgnoreCase(Command.INCR.getValue())) {
return Command.INCR;
} else if (command.toLowerCase().contains(Command.MULTI.getValue()) || command.equalsIgnoreCase(Command.MULTI.getValue())) {
return Command.MULTI;
} else if (command.toLowerCase().contains(Command.EXEC.getValue()) || command.equalsIgnoreCase(Command.EXEC.getValue())) {
return Command.EXEC;
} else if (command.toLowerCase().contains(Command.DISCARD.getValue()) || command.equalsIgnoreCase(Command.DISCARD.getValue())) {
return Command.DISCARD;
} else return Command.UNKNOWN;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment