Found my answer here:
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/f44e5874eb20b41b/f34caf3a7bf64daa

Simply hash the Double.toString() .

Anyone has a better idea?


On Mar 31, 2:53 pm, googelybear <[email protected]> wrote:
> It seems that this got reverted at some 
> point:http://code.google.com/p/google-web-toolkit/source/diff?spec=svn2434&;...
>
> does anyone know why?
>
> On Mar 31, 2:35 pm, googelybear <[email protected]> wrote:
>
>
>
> > I just found a post in the gwt contributors group but I cannot find it
> > anywhere in gwt, any 
> > ideas?http://groups.google.com/group/google-web-toolkit-contributors/browse...
>
> > On Mar 31, 2:20 pm, 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