vendredi 6 avril 2018

Can Collection be used as an key in Hashmap java?

I have following scenario (modified one than actual business purpose).

  1. I have a program which predicts how much calories a person will loose for the next 13 weeks based on certain attributes.
  2. I want to cache this result in the database so that i don't call the prediction again for the same combination.
  3. I have class person class Person { int personId; String weekStartDate; }
  4. I have HashMap<List<Person>, Integer> - The key is 13 weeks data of a person and the value is the prediction
  5. I will keep the hashvalue in the database for caching purpose

Is there a better way to handle above scenario? Any design pattern to support such scenarios

Aucun commentaire:

Enregistrer un commentaire