Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some more Argumentexceptions to handle wrong inputs #135 #187

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/org/fungover/haze/HazeDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public String get(List<String> inputList) {
}

public String delete(List<String> keys) {
if (keys.isEmpty())
throw new IllegalArgumentException("No keys provided");

var counter = new AtomicInteger(0);
lock.lock();
try {
Expand All @@ -62,6 +65,9 @@ public String delete(List<String> keys) {
}

public String exists(List<String> keys) {
if (keys.isEmpty())
return ":0\r\n";

lock.lock();
int numberOfKeys = 0;
try {
Expand Down Expand Up @@ -109,6 +115,12 @@ public Map<String, String> copy() {
}

public String ping(List<String> messageList) {
if (messageList == null || messageList.isEmpty()) {
throw new IllegalArgumentException("No message provided");
} else if (messageList.size() > 2) {
throw new IllegalArgumentException("Too many arguments for PING command");
}

if (messageList.size() == 1)
return "+PONG\r\n";
else return "$" + (messageList.get(1)).length() + "\r\n" + messageList.get(1) + "\r\n";
Expand Down
Loading