Changeset 12165 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2017-05-15T16:15:28+02:00 (8 years ago)
Author:
michael2402
Message:

Use identity instead of equality to add / remove gpx tracks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r12164 r12165  
    108108            }
    109109        }
    110         privateTracks.addAll(other.getTracks());
    111         privateRoutes.addAll(other.getRoutes());
    112         privateWaypoints.addAll(other.getWaypoints());
     110        other.getTracks().forEach(this::addTrack);
     111        other.getRoutes().forEach(this::addRoute);
     112        other.getWaypoints().forEach(this::addWaypoint);
    113113        dataSources.addAll(other.dataSources);
    114114        fireInvalidate();
     
    129129     */
    130130    public void addTrack(GpxTrack track) {
    131         if (privateTracks.contains(track)) {
     131        if (privateTracks.stream().anyMatch(t -> t == track)) {
    132132            throw new IllegalArgumentException(MessageFormat.format("The track was already added to this data: {0}", track));
    133133        }
     
    143143     */
    144144    public void removeTrack(GpxTrack track) {
    145         if (!privateTracks.remove(track)) {
     145        if (!privateTracks.removeIf(t -> t == track)) {
    146146            throw new IllegalArgumentException(MessageFormat.format("The track was not in this data: {0}", track));
    147147        }
     
    165165     */
    166166    public void addRoute(GpxRoute route) {
    167         if (privateRoutes.contains(route)) {
     167        if (privateRoutes.stream().anyMatch(r -> r == route)) {
    168168            throw new IllegalArgumentException(MessageFormat.format("The route was already added to this data: {0}", route));
    169169        }
     
    178178     */
    179179    public void removeRoute(GpxRoute route) {
    180         if (!privateRoutes.remove(route)) {
     180        if (!privateRoutes.removeIf(r -> r == route)) {
    181181            throw new IllegalArgumentException(MessageFormat.format("The route was not in this data: {0}", route));
    182182        }
     
    199199     */
    200200    public void addWaypoint(WayPoint waypoint) {
    201         if (privateWaypoints.contains(waypoint)) {
     201        if (privateWaypoints.stream().anyMatch(w -> w == waypoint)) {
    202202            throw new IllegalArgumentException(MessageFormat.format("The route was already added to this data: {0}", waypoint));
    203203        }
     
    212212     */
    213213    public void removeWaypoint(WayPoint waypoint) {
    214         if (!privateWaypoints.remove(waypoint)) {
     214        if (!privateWaypoints.removeIf(w -> w == waypoint)) {
    215215            throw new IllegalArgumentException(MessageFormat.format("The route was not in this data: {0}", waypoint));
    216216        }
     
    580580        final int prime = 31;
    581581        int result = 1;
    582         result = prime * result + dataSources.hashCode();
    583         result = prime * result + privateRoutes.hashCode();
    584         result = prime * result + privateTracks.hashCode();
    585         result = prime * result + privateWaypoints.hashCode();
     582        result = prime * result + ((dataSources == null) ? 0 : dataSources.hashCode());
     583        result = prime * result + ((privateRoutes == null) ? 0 : privateRoutes.hashCode());
     584        result = prime * result + ((privateTracks == null) ? 0 : privateTracks.hashCode());
     585        result = prime * result + ((privateWaypoints == null) ? 0 : privateWaypoints.hashCode());
    586586        return result;
    587587    }
Note: See TracChangeset for help on using the changeset viewer.