This sounds too much like "I want to have the new and old values in memory, but I do not want to have the new and old values in memory".
Options:
a) A map of all the added
elements, when save do putAll
.
b) Your map, instead of <ClassKey, ClassValue>
, holds <ClassKey, ClassValue2>
. Value2
holds two items of ClassValue
, the new and old instance. At save
, you pass the new one (if any) to the old one. It will be useful only if you are changing most of the entries in each "transaction".
Not mentioned is the issue of deleting elements, which will bring you yet more joy. With option 2 you can set a boolean at Value2
, with option a you will need more workarounds.