feat: convert string commands to enum#249
feat: convert string commands to enum#249jmarkerink wants to merge 4 commits intobwaldvogel:mainfrom
Conversation
|
Could you please cleanup and squash the commits of this PR? (eg. using git rebase --interactive) |
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class DatabaseCommand { |
There was a problem hiding this comment.
Can you elaborate on the purpose of this class? It’s not very unintuitive IMO. Why is it okay that equals/hashCode takes only the command field?
Why do we need the static constructors?
Is queryValue a good field name?
There was a problem hiding this comment.
Could you please cleanup and squash the commits of this PR? (eg. using git rebase --interactive)
I have cleanup a bit. Thanks, learned something from this exercise 🤓
Because the command string is case-insensitive in some cases I wrapped it in this value object so we can access the received command too and parsing can be done in a few places.
To exclude the case sensitivity I left out the received query command string in the equals / hashCode.
Static constructor in this case, is a style I prefer, but I can changed this to you preference.
How do you want proceed with this PR, do you think this can be a good addition if we amend your comments?
Shall I
- Remove the static constructors and rename
queryValueto e.g.queryCommandor - Drop the value object DatabaseCommand and change e.g. the code, from
public Document handleCommand(Channel channel, String databaseName, DatabaseCommand command, Document query) {
return switch (command.getCommand()) {
To
public Document handleCommand(Channel channel, String databaseName, String command, Document query) {
return switch (Command.parseString(command)) {
Please share you thoughts.
d07dd6f to
85528e2
Compare
I hope you are appreciating this refactoring with strong typing.
I have modeled the supported/implemented commands in a enumeration and wrapped it in a value object so we can retrieve the original query command string because of the case insensitivity.
Some benefits: