Changeset 2457 in josm for trunk/src/org


Ignore:
Timestamp:
2009-11-15T11:43:04+01:00 (15 years ago)
Author:
Gubaer
Message:

Added hashCode() and equals() on LatLon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r2332 r2457  
    2828     * Replies true if lat is in the range [-90,90]
    2929     *
    30      * @param lat the latitude 
     30     * @param lat the latitude
    3131     * @return true if lat is in the range [-90,90]
    3232     */
     
    3838     * Replies true if lon is in the range [-180,180]
    3939     *
    40      * @param lon the longitude 
     40     * @param lon the longitude
    4141     * @return true if lon is in the range [-180,180]
    4242     */
     
    4444        return lon >= -180d && lon <= 180d;
    4545    }
    46    
     46
    4747    public static String dms(double pCoordinate) {
    4848
     
    7373        case DECIMAL_DEGREES: return cDdFormatter.format(y);
    7474        case DEGREES_MINUTES_SECONDS: return dms(y) + ((y < 0) ?
    75             /* short symbol for South */ tr("S") :
    76             /* short symbol for North */ tr("N"));
     75                /* short symbol for South */ tr("S") :
     76                    /* short symbol for North */ tr("N"));
    7777        default: return "ERR";
    7878        }
     
    8787        case DECIMAL_DEGREES: return cDdFormatter.format(x);
    8888        case DEGREES_MINUTES_SECONDS: return dms(x) + ((x < 0) ?
    89             /* short symbol for West */ tr("W") :
    90             /* short symbol for East */ tr("E"));
     89                /* short symbol for West */ tr("W") :
     90                    /* short symbol for East */ tr("E"));
    9191        default: return "ERR";
    9292        }
     
    179179        return "LatLon[lat="+lat()+",lon="+lon()+"]";
    180180    }
     181
     182    @Override
     183    public int hashCode() {
     184        final int prime = 31;
     185        int result = super.hashCode();
     186        long temp;
     187        temp = java.lang.Double.doubleToLongBits(x);
     188        result = prime * result + (int) (temp ^ (temp >>> 32));
     189        temp = java.lang.Double.doubleToLongBits(y);
     190        result = prime * result + (int) (temp ^ (temp >>> 32));
     191        return result;
     192    }
     193
     194    @Override
     195    public boolean equals(Object obj) {
     196        if (this == obj)
     197            return true;
     198        if (!super.equals(obj))
     199            return false;
     200        if (getClass() != obj.getClass())
     201            return false;
     202        Coordinate other = (Coordinate) obj;
     203        if (java.lang.Double.doubleToLongBits(x) != java.lang.Double.doubleToLongBits(other.x))
     204            return false;
     205        if (java.lang.Double.doubleToLongBits(y) != java.lang.Double.doubleToLongBits(other.y))
     206            return false;
     207        return true;
     208    }
    181209}
Note: See TracChangeset for help on using the changeset viewer.