Hi!
A program I am working on now uses HashMaps. The key is a NodePair structure shown below. When I put things into the HashMap, I can see that the information has been entered (using JBuilder's watch tool) but when I extract information using the command:
(<cast to object>
myMap.get(new NodePair(start, end)) where start & end are Strings
I simply get a null value. Maybe the problem has something to do with the fact that if the equals method was used to check the information in the HashMap and the new NodePair, they would be different. Can anyone shed some light on this? Thank you in advance!
Phil
------------- code ------------------
public class NodePair
{
private String startNodeName;
private String endNodeName;
/**
* Class constructor setting the start & end node names.
*/
public NodePair(String startNodeName, String endNodeName)
{
this.startNodeName = startNodeName;
this.endNodeName = endNodeName;
}
/**
* Calculates the combined hash code of the node pair
*/
public int hashCode()
{
// multiply by 3 so that you can distinguish between
// directed and undirected edge
int hashKey = (3 * startNodeName.hashCode()) ^ (endNodeName.hashCode());
return hashKey;
}
public String getStartNodeName()
{
return startNodeName;
}
public String getEndNodeName()
{
return endNodeName;
}
}