Changeset 19232 in osm for applications/viewer


Ignore:
Timestamp:
2009-12-28T13:31:52+01:00 (15 years ago)
Author:
stotz
Message:

Implemented hashCode() based on equals(..)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/Tile.java

    r18772 r19232  
    180180        return loading;
    181181    }
     182
    182183    public void setLoaded(boolean loaded) {
    183184        this.loaded = loaded;
     
    209210    }
    210211
     212    /**
     213     * Note that the hash code does not include the {@link #source}.
     214     * Therefore a hash based collection can only contain tiles
     215     * of one {@link #source}.
     216     */
     217    @Override
     218    public int hashCode() {
     219        final int prime = 31;
     220        int result = 1;
     221        result = prime * result + xtile;
     222        result = prime * result + ytile;
     223        result = prime * result + zoom;
     224        return result;
     225    }
     226
     227    /**
     228     * Compares this object with <code>obj</code> based on
     229     * the fields {@link #xtile}, {@link #ytile} and
     230     * {@link #zoom}.
     231     * The {@link #source} field is ignored.
     232     */
    211233    @Override
    212234    public boolean equals(Object obj) {
    213         if (!(obj instanceof Tile))
    214             return false;
    215         Tile tile = (Tile) obj;
    216         return (xtile == tile.xtile) && (ytile == tile.ytile) && (zoom == tile.zoom);
     235        if (this == obj)
     236            return true;
     237        if (obj == null)
     238            return false;
     239        if (getClass() != obj.getClass())
     240            return false;
     241        Tile other = (Tile) obj;
     242        if (xtile != other.xtile)
     243            return false;
     244        if (ytile != other.ytile)
     245            return false;
     246        if (zoom != other.zoom)
     247            return false;
     248        return true;
    217249    }
    218250
     
    220252        return zoom + "/" + xtile + "/" + ytile + "@" + source.getName();
    221253    }
     254
    222255    public String getStatus() {
    223256        String status = "new";
     
    230263        return status;
    231264    }
     265
    232266    public boolean hasError() {
    233267        return error;
Note: See TracChangeset for help on using the changeset viewer.