Skip to content

feat: convert string commands to enum#249

Open
jmarkerink wants to merge 4 commits intobwaldvogel:mainfrom
jmarkerink:feat/convert-string-commands-to-enum
Open

feat: convert string commands to enum#249
jmarkerink wants to merge 4 commits intobwaldvogel:mainfrom
jmarkerink:feat/convert-string-commands-to-enum

Conversation

@jmarkerink
Copy link

@jmarkerink jmarkerink commented Jan 17, 2026

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:

  • compile-time safety - typos are caught at compile time
  • documentation - enum serves as documentation of all supported commands
  • performance - single toLowerCase() with HashMap lookup

@bwaldvogel
Copy link
Owner

Could you please cleanup and squash the commits of this PR? (eg. using git rebase --interactive)


import java.util.Objects;

public class DatabaseCommand {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Author

@jmarkerink jmarkerink Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 queryValue to e.g. queryCommand or
  • 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.

@jmarkerink jmarkerink force-pushed the feat/convert-string-commands-to-enum branch from d07dd6f to 85528e2 Compare February 22, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants