Using a hash table for these kinds of objects may or may not be a
good idea due to the unlikelihood of two doubles computed at different
times using different sets of operations being exactly equal (==) to
one another.  What are you trying to accomplish by storing them in a
hash table?

Dan

On Mar 31, 8:20 am, googelybear <[email protected]> wrote:
> Hi,
>
> this question might seem stupid but how can one implement hashCode()
> and equals() for a simple 2d point class as follows:
>
> public class Point {
>
>         private double fX;
>
>         private double fY;
>
>         public double getX() {
>                 return fX;
>         }
>
>         public void setX(double x) {
>                 this.fX= x;
>         }
>
>         public double getY() {
>                 return fY;
>         }
>
>         public void setY(double y) {
>                 this.fY= y;
>         }
>
> }
>
> The generated equals() and hashCode() methods from Eclipse do NOT work
> with GWT as method Double.doubleToLongBits()  is missing:
>
>         @Override
>         public int hashCode() {
>                 final int prime= 31;
>                 int result= 1;
>                 long temp;
>                 temp= Double.doubleToLongBits(fX);
>                 result= prime * result + (int) (temp ^ (temp >>> 32));
>                 temp= Double.doubleToLongBits(fY);
>                 result= prime * result + (int) (temp ^ (temp >>> 32));
>                 return result;
>         }
>
>         @Override
>         public boolean equals(Object obj) {
>                 if (this == obj)
>                         return true;
>                 if (obj == null)
>                         return false;
>                 if (!(obj instanceof Point))
>                         return false;
>                 Point other= (Point) obj;
>                 if (Double.doubleToLongBits(fX) !=
> Double.doubleToLongBits(other.fX))
>                         return false;
>                 if (Double.doubleToLongBits(fY) !=
> Double.doubleToLongBits(other.fY))
>                         return false;
>                 return true;
>         }
>
> Does anyone have an idea how to implement this?
>
> thanks a bunch,
>
> Dennis

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to