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

ConfigurationSqlDao getValue type switch #498

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

TheDavSmasher
Copy link

Overview

Method getValue previously ran an if-else chain over all the Types that are currently supported and then returned the string value parsed cast to the type. This was changed to a switch statement.

Details

Due to Java limitations, a switch statement cannot be run directly over a Class<?> object. Another option that failed was using reflection to create an instance and use Pattern Matching, but the types supported had inconsistent Constructor signatures (where a Constructor with the same arguments was not shared between all types).

Such being the case, I turned to a switch statement over the Class's name, which should provide the same readability improvement while keeping the same functionality.

Testing

Tested manually with the Debugger's "Evaluate Expression" tool, using the same expressions/values as other usages within the application, as well as initializing the server (which utilizes this method).

Additional Notes

This PR was made due to a code quality observation I made and is not linked to any issues for the moment (since I'm waiting on clarification/approvals on other issues).

@TheDavSmasher TheDavSmasher added the clean-up Something in the code is a mess and needs refactoring label Dec 23, 2024
Copy link
Contributor

@frozenfrank frozenfrank left a comment

Choose a reason for hiding this comment

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

I like this change! I won't approve it just because I haven't specifically evaluated the code, but this code certainly looks like something we want to approve.

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean-up Something in the code is a mess and needs refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants