PDA

View Full Version : override hash set and equals problem



mickey
9th September 2010, 00:53
Hello,
got a probem:


class Var {
String name, type;
}
class A {
String flag;
public Map<String,Integer> names = new LinkedHashMap<String, Integer>();
public Map<Var, Integer> paramList = new LinkedHashMap<Var, Integer>();
}
//main
Map<A, Set<B>> map = new LinkedHashMap<A, Set<B>>();
//now I must put stuff inside the map


I need override but a1.equals(a2) if it has equal:
- flag
- Var.type (and not the name)

I overrode by Eclipse just for the flag and added this to the equal:


if (paramList == null) {
if (other.paramList != null)
return false;
// } else if (!paramList.equals(other.paramList))
// return false;

} else if ( !this.getATypeParameters().equals( other.getATypeParameters()) )
return false;

getATypeParameters is my function that return a Set of Var.type. Apparently work; does it make sense? Is it fine?
thanks

mickey
9th September 2010, 18:28
Hello can't anybody advice me?
thanks