dictionary - Java - get value from equivalent key in ConcurrentHashMap -
for code:
//... system.out.println(main.getcurrentpage().getdots()); //type: concurrenthashmap<point,string> system.out.println(mdp.getactivepoint()); //type: point system.out.println(main.getrealcurrentpage().getdots().get(mdp.getactivepoint())); //type: string //...
i output:
{java.awt.point[x=278,y=354]=a1, java.awt.point[x=542,y=370]=a1} java.awt.point[x=278,y=354] null
i don't understand why third line of output isn't
a1
because point printed in second line of output contained in keyset of map.
i thought because they're not being treated same object/reference reason, made class extends concurrenthashmap:
public class goodchashmap<k,v> extends concurrenthashmap<k,v>{ public goodchashmap(){ super(); } public goodchashmap(goodchashmap<k,v> m){ super(m); } @override public v get(object key){ if(key instanceof point){ //system.out.println("!!!! hit"); point point = (point) key; for(object o : keyset()){ point p = (point) o; if(point.x == p.x && point.y == p.y){ //system.out.println("this thing"); return super.get(p); } } return null; }else{ return super.get(key); } } }
this designed if point passed in method, iterates through own keyset and, if point there has same coordinates argument, uses point keyset in default concurrenthashmap method. however, fails.
can me understand , overcome behavior?
Comments
Post a Comment