Changeset 10334 in josm
- Timestamp:
- 2016-06-07T21:26:44+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/CachedLatLon.java
r8846 r10334 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.coor; 3 4 import java.util.Objects; 3 5 4 6 import org.openstreetmap.josm.Main; … … 54 56 */ 55 57 public final EastNorth getEastNorth() { 56 if ( proj != Main.getProjection()) {58 if (!Objects.equals(proj, Main.getProjection())) { 57 59 proj = Main.getProjection(); 58 60 eastNorth = proj.latlon2eastNorth(this); … … 62 64 63 65 @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 64 79 public String toString() { 65 80 return "CachedLatLon[lat="+lat()+",lon="+lon()+']'; -
trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java
r9243 r10334 13 13 private static final long serialVersionUID = 1L; 14 14 15 /** 16 * Constructs a new {@code EastNorth}. 17 * @param east easting 18 * @param north northing 19 */ 15 20 public EastNorth(double east, double north) { 16 21 super(east, north); 17 22 } 18 23 24 /** 25 * Returns easting. 26 * @return easting 27 */ 19 28 public double east() { 20 29 return x; 21 30 } 22 31 32 /** 33 * Returns northing. 34 * @return northing 35 */ 23 36 public double north() { 24 37 return y; … … 53 66 } 54 67 68 /** 69 * Scales this {@link EastNorth} instance to a given factor and returns the result. 70 * @param s factor 71 * @return The result. 72 */ 55 73 public EastNorth scale(double s) { 56 74 return new EastNorth(s * x, s * y); -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r10181 r10334 56 56 public static final LatLon ZERO = new LatLon(0, 0); 57 57 58 /** 59 * North and south pole. 60 */ 58 /** North pole. */ 61 59 public static final LatLon NORTH_POLE = new LatLon(90, 0); 60 /** South pole. */ 62 61 public static final LatLon SOUTH_POLE = new LatLon(-90, 0); 63 62 … … 227 226 } 228 227 229 230 228 /** 231 229 * Returns the latitude, i.e., the north-south position in degrees. … … 487 485 public boolean equals(Object obj) { 488 486 if (this == obj) return true; 489 if ( !(obj instanceof LatLon)) return false;487 if (obj == null || getClass() != obj.getClass()) return false; 490 488 LatLon that = (LatLon) obj; 491 489 return Double.compare(that.x, x) == 0 && 492 490 Double.compare(that.y, y) == 0; 493 491 } 494 492 -
trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java
r10222 r10334 3 3 4 4 import static org.junit.Assert.assertEquals; 5 6 import java.text.DecimalFormat; 5 7 6 8 import org.junit.Before; … … 9 11 10 12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 13 import nl.jqno.equalsverifier.EqualsVerifier; 11 14 12 15 /** … … 120 123 121 124 /** 122 * Test of {@link LatLon#equals}125 * Unit test of methods {@link LatLon#equals} and {@link LatLon#hashCode}. 123 126 */ 124 127 @Test 125 public void testEquals() { 126 for (int i = 1; i < SAMPLE_VALUES.length; i++) { 127 LatLon a = new LatLon(SAMPLE_VALUES[i-1], SAMPLE_VALUES[i]); 128 LatLon b = new LatLon(SAMPLE_VALUES[i-1], SAMPLE_VALUES[i]); 129 assertEquals(a, b); 130 } 131 } 132 133 /** 134 * Test of {@link LatLon#hashCode} 135 */ 136 @Test 137 public void testHashCode() { 138 for (int i = 1; i < SAMPLE_VALUES.length; i++) { 139 LatLon a = new LatLon(SAMPLE_VALUES[i-1], SAMPLE_VALUES[i]); 140 LatLon b = new LatLon(SAMPLE_VALUES[i-1], SAMPLE_VALUES[i]); 141 assertEquals(a.hashCode(), b.hashCode()); 142 } 128 public void equalsContract() { 129 EqualsVerifier.forClass(LatLon.class).usingGetClass() 130 .withPrefabValues(DecimalFormat.class, new DecimalFormat("00.0"), new DecimalFormat("00.000")) 131 .verify(); 143 132 } 144 133
Note:
See TracChangeset
for help on using the changeset viewer.