I am making a Java and Spring webapp that scrapes data from a web and then publishes it through an API. Some of the raw scrapped data is in the form of
Set<SomeObject> which I then convert to a
Set<ConvertedObject>. The thing is, there is a field that has a repeating value in a lot of
SomeObject and I want to avoid converting it more than once - it isn't an expensive operation but still.
So far I have come up with two solutions:
- Extract that field from
Map<String, Set<SomeObject>>, which is easy to do from the web I am scrapping (like 5 lines of code).
- Keep the field inside
SomeObjectand make an internal service with cache to convert that field, which is also easy to do with Spring.
The possible values are not so many; 7 values cover 95%+ of the entities, but some times there are some other values apart from those which I am able to parse.
I like the second solution in that the code becomes cleaner, no complicated Map and Set structure, but it is also a more sophisticated one in my opinion that isn't really necessary.
Which one do you think is better?
To better clarify, I am most concerned with clean code rather than efficiency. Plus, I am also interested in a general answer regarding Spring web applications design. Should I use components everywhere I can or sometimes vanilla solutions are better?