Ignore:
Timestamp:
2016-01-09T23:20:37+01:00 (9 years ago)
Author:
simon04
Message:

Java 7: use Objects.equals and Objects.hash

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

Legend:

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

    r7509 r9371  
    33
    44import java.io.Serializable;
     5import java.util.Objects;
    56
    67import org.openstreetmap.josm.data.osm.BBox;
     
    113114    }
    114115
    115     protected final int computeHashCode(int init) {
    116         final int prime = 31;
    117         int result = init;
    118         long temp;
    119         temp = java.lang.Double.doubleToLongBits(x);
    120         result = prime * result + (int) (temp ^ (temp >>> 32));
    121         temp = java.lang.Double.doubleToLongBits(y);
    122         result = prime * result + (int) (temp ^ (temp >>> 32));
    123         return result;
    124     }
    125 
    126     @Override
    127     public int hashCode() {
    128         return computeHashCode(1);
    129     }
    130 
    131     @Override
    132     public boolean equals(Object obj) {
    133         if (this == obj)
    134             return true;
    135         if (obj == null || getClass() != obj.getClass())
    136             return false;
    137         Coordinate other = (Coordinate) obj;
    138         if (java.lang.Double.doubleToLongBits(x) != java.lang.Double.doubleToLongBits(other.x))
    139             return false;
    140         if (java.lang.Double.doubleToLongBits(y) != java.lang.Double.doubleToLongBits(other.y))
    141             return false;
    142         return true;
    143     }
    144116}
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r9243 r9371  
    1616import java.util.Arrays;
    1717import java.util.Locale;
     18import java.util.Objects;
    1819
    1920import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
     
    428429    @Override
    429430    public int hashCode() {
    430         return computeHashCode(super.hashCode());
     431        return Objects.hash(super.hashCode());
    431432    }
    432433
    433434    @Override
    434435    public boolean equals(Object obj) {
    435         if (this == obj)
    436             return true;
    437         if (!super.equals(obj))
    438             return false;
    439         if (getClass() != obj.getClass())
    440             return false;
    441         Coordinate other = (Coordinate) obj;
    442         if (java.lang.Double.doubleToLongBits(x) != java.lang.Double.doubleToLongBits(other.x))
    443             return false;
    444         if (java.lang.Double.doubleToLongBits(y) != java.lang.Double.doubleToLongBits(other.y))
    445             return false;
    446         return true;
     436        if (this == obj) return true;
     437        if (obj == null || getClass() != obj.getClass()) return false;
     438        return super.equals(obj);
    447439    }
    448440
Note: See TracChangeset for help on using the changeset viewer.