posted 13 years ago
I'll clarify: (the Object identifies and translates 'A' into new Character('A'), so that is not the problem)
this is the Node class:
it prints :
A
A
true
meaning it compares two different nodes and 'equals' checks if they have the same name.
this is the Edge Class:
prints
(C,D)
(C,D)
true
so here the equals also works.
in the graph class i did this:
it prints:
Nodes: [A,D,B,A,C]
Edges: [(A,B),(B,C)(A,C)]
nodes1: [A,C,B,D]
Edges 1:[(A,B),(B,C)(A,C)]
false
true
so there are two problems here.
1) How can I add another 'A' to Nodes? a hashset isn't supposed to allow it. i.e it has two similar elements. I know it sees them as different because it is looking at the 'Node' wrapping.
2) If I erase the extra 'A' from Nodes, and to the equals method again (which currently only checks the _nodes)
it still returns false even though they have the same elements in the set.
the last line gives 'true' because the set has wrapped the Characters with the nodes, so I guess the equals method is comparing that. (So these 2 problems are actually the same I think..?)
That is where I am stuck..
Hope this helps...