But SonarLint is complaining about it, so I refactored it into this:
It's high time this old codebase gets converted to LocalDates.
References
- SonarSource - RSPEC-2384
- https://rules.sonarsource.com/java/RSPEC-2384
But SonarLint is complaining about it, so I refactored it into this:
It's high time this old codebase gets converted to LocalDates.
Once again I stumbled upon old code, that could use some refactoring.
It took me and my colleague a few seconds to process what the software designer had in mind when he did this.
As it was up to me to add another field to the construction, making it even more terrible than it was, it was time for a refactoring.
We quite quickly came up with using a Composite Key, which of course is the default way to deal with this sort of thing.
There was some trickery going on to properly deal with NULL keys (which are sometimes not allowed in a Map implementation1).
This disadvantage now disappears with this nice composite key.
I tested it with a list of cars, and I do not wish to withhold the test setup:
Of course it is quite easy to just match on some of the criteria. In this case, we could use a Map containing Lists, where the composite key used has empty fields, and would cause a list of cars to be returned and a full composite key (all search criteria) would just yield a list containing one specific car.
If we wish to use fuzzy matching, we are in a bit of a bind.
I'm pretty sure there are always other (perhaps even better) ways of doing this. If you know of some, let me know.
I'm always interested.
The answer for the VarArgs Pop Quiz.
The reason for the quiz is that there's a potential NullPointerException in there, that you need to be aware of.
According to reference [1], if the argument provided is compatible with String[], it is assumed that that is what you meant. And null is always compatible with any T[].
Also interesting enough and just to drive the point home, it means that the method signatures below are identical and Java will give you a big fat warning that you defined the same method twice.
Pop quiz: what is the output of the following program:
The answer in the following blog post.