Changeset 10334 in josm for trunk/src/org


Ignore:
Timestamp:
2016-06-07T21:26:44+02:00 (8 years ago)
Author:
Don-vip
Message:

fix equals methods for Coordinate classes

Location:
trunk/src/org/openstreetmap/josm/data/coor
Files:
3 edited

Legend:

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

    r8846 r10334  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.coor;
     3
     4import java.util.Objects;
    35
    46import org.openstreetmap.josm.Main;
     
    5456     */
    5557    public final EastNorth getEastNorth() {
    56         if (proj != Main.getProjection()) {
     58        if (!Objects.equals(proj, Main.getProjection())) {
    5759            proj = Main.getProjection();
    5860            eastNorth = proj.latlon2eastNorth(this);
     
    6264
    6365    @Override
     66    public int hashCode() {
     67        return Objects.hash(x, y, eastNorth);
     68    }
     69
     70    @Override
     71    public boolean equals(Object obj) {
     72        if (!super.equals(obj))
     73            return false;
     74        CachedLatLon other = (CachedLatLon) obj;
     75        return Objects.equals(eastNorth, other.eastNorth);
     76    }
     77
     78    @Override
    6479    public String toString() {
    6580        return "CachedLatLon[lat="+lat()+",lon="+lon()+']';
  • trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java

    r9243 r10334  
    1313    private static final long serialVersionUID = 1L;
    1414
     15    /**
     16     * Constructs a new {@code EastNorth}.
     17     * @param east easting
     18     * @param north northing
     19     */
    1520    public EastNorth(double east, double north) {
    1621        super(east, north);
    1722    }
    1823
     24    /**
     25     * Returns easting.
     26     * @return easting
     27     */
    1928    public double east() {
    2029        return x;
    2130    }
    2231
     32    /**
     33     * Returns northing.
     34     * @return northing
     35     */
    2336    public double north() {
    2437        return y;
     
    5366    }
    5467
     68    /**
     69     * Scales this {@link EastNorth} instance to a given factor and returns the result.
     70     * @param s factor
     71     * @return The result.
     72     */
    5573    public EastNorth scale(double s) {
    5674        return new EastNorth(s * x, s * y);
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r10181 r10334  
    5656    public static final LatLon ZERO = new LatLon(0, 0);
    5757
    58     /**
    59      * North and south pole.
    60      */
     58    /** North pole. */
    6159    public static final LatLon NORTH_POLE = new LatLon(90, 0);
     60    /** South pole. */
    6261    public static final LatLon SOUTH_POLE = new LatLon(-90, 0);
    6362
     
    227226    }
    228227
    229 
    230228    /**
    231229     * Returns the latitude, i.e., the north-south position in degrees.
     
    487485    public boolean equals(Object obj) {
    488486        if (this == obj) return true;
    489         if (!(obj instanceof LatLon)) return false;
     487        if (obj == null || getClass() != obj.getClass()) return false;
    490488        LatLon that = (LatLon) obj;
    491489        return Double.compare(that.x, x) == 0 &&
    492                 Double.compare(that.y, y) == 0;
     490               Double.compare(that.y, y) == 0;
    493491    }
    494492
Note: See TracChangeset for help on using the changeset viewer.