I have a HashMap that stores a custom Object and maps it to a certain ArrayList in a class. My class communicates with another class (think MVC style) and it passes a copy of that hashmap. So, in my "model", I would have:
public Map<AbstractArtistry, ArrayList<AbstractCommand>> getHashMap() {
return new LinkedHashMap<AbstractArtistry, ArrayList<AbstractCommand>>(this.hashmap);
}
However, my "controller", when it gets that, can still edit the AbstractArtistries inside of the model's this.hashmap. To avoid this, do I have to create a new instance of an Abstract Artistry over and over, or is there a cleaner way to do this? Meaning, would I have to loop over model.hashmap.keySet(), create a new instance of every artistry, insert it into a new hashmap (and do the same for all the values), and then return that new hashmap? Or is there a cleaner way?