Changeset 10906 in josm
- Timestamp:
- 2016-08-27T17:23:05+02:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 16 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r10680 r10906 482 482 return DataSource.getDataSourceBounds(dataSources); 483 483 } 484 485 @Override 486 public int hashCode() { 487 final int prime = 31; 488 int result = 1; 489 result = prime * result + ((dataSources == null) ? 0 : dataSources.hashCode()); 490 result = prime * result + ((routes == null) ? 0 : routes.hashCode()); 491 result = prime * result + ((tracks == null) ? 0 : tracks.hashCode()); 492 result = prime * result + ((waypoints == null) ? 0 : waypoints.hashCode()); 493 return result; 494 } 495 496 @Override 497 public boolean equals(Object obj) { 498 if (this == obj) 499 return true; 500 if (obj == null) 501 return false; 502 if (getClass() != obj.getClass()) 503 return false; 504 GpxData other = (GpxData) obj; 505 if (dataSources == null) { 506 if (other.dataSources != null) 507 return false; 508 } else if (!dataSources.equals(other.dataSources)) 509 return false; 510 if (routes == null) { 511 if (other.routes != null) 512 return false; 513 } else if (!routes.equals(other.routes)) 514 return false; 515 if (tracks == null) { 516 if (other.tracks != null) 517 return false; 518 } else if (!tracks.equals(other.tracks)) 519 return false; 520 if (waypoints == null) { 521 if (other.waypoints != null) 522 return false; 523 } else if (!waypoints.equals(other.waypoints)) 524 return false; 525 return true; 526 } 484 527 } -
trunk/src/org/openstreetmap/josm/data/gpx/GpxRoute.java
r7005 r10906 7 7 public class GpxRoute extends WithAttributes { 8 8 public Collection<WayPoint> routePoints = new LinkedList<>(); 9 10 @Override 11 public int hashCode() { 12 return 31 * super.hashCode() + ((routePoints == null) ? 0 : routePoints.hashCode()); 13 } 14 15 @Override 16 public boolean equals(Object obj) { 17 if (this == obj) 18 return true; 19 if (!super.equals(obj)) 20 return false; 21 if (getClass() != obj.getClass()) 22 return false; 23 GpxRoute other = (GpxRoute) obj; 24 if (routePoints == null) { 25 if (other.routePoints != null) 26 return false; 27 } else if (!routePoints.equals(other.routePoints)) 28 return false; 29 return true; 30 } 9 31 } -
trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrack.java
r9949 r10906 17 17 public class ImmutableGpxTrack extends WithAttributes implements GpxTrack { 18 18 19 private final Collection<GpxTrackSegment> segments;19 private final List<GpxTrackSegment> segments; 20 20 private final double length; 21 21 private final Bounds bounds; … … 34 34 } 35 35 this.attr = Collections.unmodifiableMap(new HashMap<>(attributes)); 36 this.segments = Collections.unmodifiable Collection(newSegments);36 this.segments = Collections.unmodifiableList(newSegments); 37 37 this.length = calculateLength(); 38 38 this.bounds = calculateBounds(); … … 90 90 return 0; 91 91 } 92 93 @Override 94 public int hashCode() { 95 return 31 * super.hashCode() + ((segments == null) ? 0 : segments.hashCode()); 96 } 97 98 @Override 99 public boolean equals(Object obj) { 100 if (this == obj) 101 return true; 102 if (!super.equals(obj)) 103 return false; 104 if (getClass() != obj.getClass()) 105 return false; 106 ImmutableGpxTrack other = (ImmutableGpxTrack) obj; 107 if (segments == null) { 108 if (other.segments != null) 109 return false; 110 } else if (!segments.equals(other.segments)) 111 return false; 112 return true; 113 } 92 114 } -
trunk/src/org/openstreetmap/josm/data/gpx/ImmutableGpxTrackSegment.java
r8510 r10906 5 5 import java.util.Collection; 6 6 import java.util.Collections; 7 import java.util.List; 7 8 8 9 import org.openstreetmap.josm.data.Bounds; … … 10 11 public class ImmutableGpxTrackSegment implements GpxTrackSegment { 11 12 12 private final Collection<WayPoint> wayPoints;13 private final List<WayPoint> wayPoints; 13 14 private final Bounds bounds; 14 15 private final double length; 15 16 17 /** 18 * Constructs a new {@code ImmutableGpxTrackSegment}. 19 * @param wayPoints list of waypoints 20 */ 16 21 public ImmutableGpxTrackSegment(Collection<WayPoint> wayPoints) { 17 this.wayPoints = Collections.unmodifiable Collection(new ArrayList<>(wayPoints));22 this.wayPoints = Collections.unmodifiableList(new ArrayList<>(wayPoints)); 18 23 this.bounds = calculateBounds(); 19 24 this.length = calculateLength(); … … 70 75 } 71 76 77 @Override 78 public int hashCode() { 79 return 31 + ((wayPoints == null) ? 0 : wayPoints.hashCode()); 80 } 81 82 @Override 83 public boolean equals(Object obj) { 84 if (this == obj) 85 return true; 86 if (obj == null) 87 return false; 88 if (getClass() != obj.getClass()) 89 return false; 90 ImmutableGpxTrackSegment other = (ImmutableGpxTrackSegment) obj; 91 if (wayPoints == null) { 92 if (other.wayPoints != null) 93 return false; 94 } else if (!wayPoints.equals(other.wayPoints)) 95 return false; 96 return true; 97 } 72 98 } -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r10467 r10906 159 159 return new ArrayList<>(attr.keySet()); 160 160 } 161 162 @Override 163 public int hashCode() { 164 final int prime = 31; 165 int result = super.hashCode(); 166 long temp = Double.doubleToLongBits(lat); 167 result = prime * result + (int) (temp ^ (temp >>> 32)); 168 temp = Double.doubleToLongBits(lon); 169 result = prime * result + (int) (temp ^ (temp >>> 32)); 170 temp = Double.doubleToLongBits(time); 171 result = prime * result + (int) (temp ^ (temp >>> 32)); 172 return result; 173 } 174 175 @Override 176 public boolean equals(Object obj) { 177 if (this == obj) 178 return true; 179 if (!super.equals(obj)) 180 return false; 181 if (getClass() != obj.getClass()) 182 return false; 183 WayPoint other = (WayPoint) obj; 184 if (Double.doubleToLongBits(lat) != Double.doubleToLongBits(other.lat)) 185 return false; 186 if (Double.doubleToLongBits(lon) != Double.doubleToLongBits(other.lon)) 187 return false; 188 if (Double.doubleToLongBits(time) != Double.doubleToLongBits(other.time)) 189 return false; 190 return true; 191 } 161 192 } -
trunk/src/org/openstreetmap/josm/data/gpx/WithAttributes.java
r8510 r10906 90 90 ext.put(key, value); 91 91 } 92 93 @Override 94 public int hashCode() { 95 return 31 + ((attr == null) ? 0 : attr.hashCode()); 96 } 97 98 @Override 99 public boolean equals(Object obj) { 100 if (this == obj) 101 return true; 102 if (obj == null) 103 return false; 104 if (getClass() != obj.getClass()) 105 return false; 106 WithAttributes other = (WithAttributes) obj; 107 if (attr == null) { 108 if (other.attr != null) 109 return false; 110 } else if (!attr.equals(other.attr)) 111 return false; 112 return true; 113 } 92 114 } -
trunk/src/org/openstreetmap/josm/io/NmeaReader.java
r10632 r10906 29 29 */ 30 30 public class NmeaReader { 31 32 /** Handler for the different types that NMEA speaks. */33 public enum NMEA_TYPE {34 35 /** RMC = recommended minimum sentence C. */36 GPRMC("$GPRMC"),37 /** GPS positions. */38 GPGGA("$GPGGA"),39 /** SA = satellites active. */40 GPGSA("$GPGSA"),41 /** Course over ground and ground speed */42 GPVTG("$GPVTG");43 44 private final String type;45 46 NMEA_TYPE(String type) {47 this.type = type;48 }49 50 public String getType() {51 return this.type;52 }53 }54 31 55 32 // GPVTG -
trunk/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java
r10758 r10906 5 5 6 6 import java.io.FileInputStream; 7 import java.io.IOException; 7 8 import java.text.SimpleDateFormat; 8 9 import java.util.ArrayList; … … 12 13 import org.junit.Rule; 13 14 import org.junit.Test; 15 import org.openstreetmap.josm.TestUtils; 14 16 import org.openstreetmap.josm.data.coor.LatLon; 15 17 import org.openstreetmap.josm.data.gpx.GpxConstants; 18 import org.openstreetmap.josm.data.gpx.GpxData; 19 import org.openstreetmap.josm.data.gpx.GpxTrack; 20 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; 16 21 import org.openstreetmap.josm.data.gpx.WayPoint; 17 import org.openstreetmap.josm.io.NmeaReader.NMEA_TYPE;18 22 import org.openstreetmap.josm.testutils.JOSMTestRules; 23 import org.xml.sax.SAXException; 19 24 20 25 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 21 import nl.jqno.equalsverifier.EqualsVerifier;22 26 23 27 /** … … 31 35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 32 36 public JOSMTestRules test = new JOSMTestRules(); 33 34 /**35 * Unit test of methods {@link NMEA_TYPE#equals} and {@link NMEA_TYPE#hashCode}.36 */37 @Test38 public void testEqualsContract() {39 EqualsVerifier.forClass(NMEA_TYPE.class).verify();40 }41 37 42 38 /** … … 69 65 assertEquals(null, wayPoints.get(0).get(GpxConstants.PT_PDOP)); 70 66 } 67 68 private static void compareWithReference(int ticket, String filename, int numCoor) throws IOException, SAXException { 69 GpxData gpx = GpxReaderTest.parseGpxData(TestUtils.getRegressionDataFile(ticket, filename+".gpx")); 70 NmeaReader in = new NmeaReader(new FileInputStream(TestUtils.getRegressionDataFile(ticket, filename+".nmea"))); 71 assertEquals(numCoor, in.getNumberOfCoordinates()); 72 assertEquals(0, in.getParserMalformed()); 73 assertEquals(in.data.dataSources, gpx.dataSources); 74 assertEquals(1, gpx.tracks.size()); 75 assertEquals(1, in.data.tracks.size()); 76 GpxTrack gpxTrack = gpx.tracks.iterator().next(); 77 GpxTrack nmeaTrack = in.data.tracks.iterator().next(); 78 assertEquals(gpxTrack.getBounds(), nmeaTrack.getBounds()); 79 assertEquals(1, gpxTrack.getSegments().size()); 80 assertEquals(1, nmeaTrack.getSegments().size()); 81 GpxTrackSegment gpxSeg = gpxTrack.getSegments().iterator().next(); 82 GpxTrackSegment nmeaSeg = nmeaTrack.getSegments().iterator().next(); 83 assertEquals(gpxSeg.getBounds(), nmeaSeg.getBounds()); 84 assertEquals(numCoor, gpxSeg.getWayPoints().size()); 85 assertEquals(numCoor, nmeaSeg.getWayPoints().size()); 86 WayPoint gpxWpt = gpxSeg.getWayPoints().iterator().next(); 87 WayPoint nmeaWpt = nmeaSeg.getWayPoints().iterator().next(); 88 assertEquals(gpxWpt.getCoor().getRoundedToOsmPrecision(), nmeaWpt.getCoor().getRoundedToOsmPrecision()); 89 } 90 91 /** 92 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/1433">Bug #1433</a>. 93 * @throws Exception if an error occurs 94 */ 95 @Test 96 public void testTicket1433() throws Exception { 97 compareWithReference(1433, "2008-08-14-16-04-58", 1241); 98 } 99 100 /** 101 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/1853">Bug #1853</a>. 102 * @throws Exception if an error occurs 103 */ 104 @Test 105 public void testTicket1853() throws Exception { 106 compareWithReference(1853, "PosData-20081216-115434", 1285); 107 } 108 109 /** 110 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/2147">Bug #2147</a>. 111 * @throws Exception if an error occurs 112 */ 113 @Test 114 public void testTicket2147() throws Exception { 115 compareWithReference(2147, "WG20080203171807.log", 487); 116 } 71 117 }
Note:
See TracChangeset
for help on using the changeset viewer.