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 google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to