I have a code which takes a bipartite graph as an input and returns a map with key"1" with value which is a list of "nodes in set1" and key"2" whose value is list of "nodes in set2". Now, map is mutable. In theory I should use a defensive copy for returning a map. But, in this case is it really required ? It appears an overkill.
ex:
class BiPartite {
Graph graph;
Map bipartite
Bipartite(graph) {
this.graph = graph;
}
void calcBipartite() {
// calculate map
}
Map getMap() {
// should i make defensive copy ? Appears overkill.
}
}
graph
, assumingGraph
is mutable.