-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add exists function to HazeDatabase.java #88
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of varargs parameter in exists() was nice. This parameter avoids writing boilerplate code which can handle an arbitrary number of parameters automatically, using an array under the hood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, almost there.
I think you need to return a string from your method like this:
":" + numberOfKeys + "\r\n"
because the outputstream will send a string to the client and the client is expecting the format ":1\r\n"
Some tests would also be nice to check if your code works as intended.
Add that this pull request or create a new issue for that?
Thank you for the feedback @safstromo. I'll make the changes and add the tests to this pull request. I would appreciate if you could take a look at my code afterwards as well. |
a2d4558
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, the code looks good and it clearly does what it is supposed to do. The unit tests are also adequate and they are all passing, good job!
I also like the idea of being efficient and using varargs as a parameter, but I'm a bit unsure about how we are going to be able to take advantage of the flexibility though. As this is like a server application where we are dependent on arbitrary user input during runtime, how do we call the function with the correct number of arguments?
There is something called a spread operator in JavaScript (looks just like the varargs actually: ...
) that you can use to spread out values from an array or object into for example a method call. Is there something similar we could use in Java, or is there any other solution? Otherwise, maybe it would be better to go with a list/array containing all the keys to check for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good after the changes Oliver suggested
2a53a4f
to
c10b9ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to use List as input parameter, otherwise there will be issues when you call the method from executeCommand due to compatibility with the other methods 🤗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I imported java.util.List and java.util.Collections
…urrence of key in the database
…in database but just one occurrence of the wanted key
…ing keys in database and asking for one key twice, and the other is asked for once.
Co-authored-by: Julia Lerebäck Corell <112405931+jLereback@users.noreply.github.com>
Co-authored-by: Julia Lerebäck Corell <112405931+jLereback@users.noreply.github.com>
Co-authored-by: Julia Lerebäck Corell <112405931+jLereback@users.noreply.github.com>
Co-authored-by: Julia Lerebäck Corell <112405931+jLereback@users.noreply.github.com>
Co-authored-by: Julia Lerebäck Corell <112405931+jLereback@users.noreply.github.com>
Co-authored-by: Julia Lerebäck Corell <112405931+jLereback@users.noreply.github.com>
94ab1d3
6a5e973
to
94ab1d3
Compare
SonarCloud Quality Gate failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I have created an exists function that takes in a number of String parameters as keys, compares them to the existing Map to see if the key exists and send back an integer value equating to the number of keys available in the database that match the parameters sent in.