lundi 7 décembre 2020

Java - Replacing If/else with HashMap - Optimized Approach [closed]

I have a class with almost 500 if/else, and in each if statement, I am checking contains some string if it is positive then I will set some values in a model object. Now I am doing the activity of cleaning the entire class or redesign it. So I thought to have a static Hash Map with condition string and a model object with the values set in it. The thing is the actual raw log comes from external devices so once the log comes in, i should iterate the whole map and take the values set model object, So Is there a way to use any algorithmic approach to reorder the Map by keeping the matched index at the first position, So that the next time it will be do it in a fraction of seconds. Is it the correct way to design or any other better approach for parsing data in real time streaming in java without huge number of if/else or regexes?

Thanks in Advance.

Aucun commentaire:

Enregistrer un commentaire