Ignore:
Timestamp:
2014-09-21T23:00:38+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #7976 - Get downloaded gpx areas, on the same model as osm data

File:
1 moved

Legend:

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

    r7573 r7575  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.data.osm;
     2package org.openstreetmap.josm.data;
    33
    4 import org.openstreetmap.josm.data.Bounds;
     4import java.awt.geom.Area;
     5import java.util.ArrayList;
     6import java.util.Collection;
     7import java.util.List;
     8
    59import org.openstreetmap.josm.tools.CheckParameterUtil;
    610
    711/**
    812 * A data source, defined by bounds and textual description for the origin.
    9  * @since 247
     13 * @since 247 (creation)
     14 * @since 7575 (moved package)
    1015 */
    1116public class DataSource {
     17
    1218    /**
    1319     * The bounds of this data source
    1420     */
    1521    public final Bounds bounds;
     22
    1623    /**
    1724     * The textual description of the origin (example: "OpenStreetMap Server")
     
    3037        this.origin = origin;
    3138    }
     39
     40    @Override
     41    public int hashCode() {
     42        final int prime = 31;
     43        int result = 1;
     44        result = prime * result + ((bounds == null) ? 0 : bounds.hashCode());
     45        result = prime * result + ((origin == null) ? 0 : origin.hashCode());
     46        return result;
     47    }
     48
     49    @Override
     50    public boolean equals(Object obj) {
     51        if (this == obj)
     52            return true;
     53        if (obj == null)
     54            return false;
     55        if (getClass() != obj.getClass())
     56            return false;
     57        DataSource other = (DataSource) obj;
     58        if (bounds == null) {
     59            if (other.bounds != null)
     60                return false;
     61        } else if (!bounds.equals(other.bounds))
     62            return false;
     63        if (origin == null) {
     64            if (other.origin != null)
     65                return false;
     66        } else if (!origin.equals(other.origin))
     67            return false;
     68        return true;
     69    }
     70
     71    @Override
     72    public String toString() {
     73        return "DataSource [bounds=" + bounds + ", origin=" + origin + "]";
     74    }
     75
     76    /**
     77     * Returns the total area of downloaded data (the "yellow rectangles").
     78     * @param dataSources list of data sources
     79     * @return Area object encompassing downloaded data.
     80     * @see Data#getDataSourceArea()
     81     */
     82    public static Area getDataSourceArea(Collection<DataSource> dataSources) {
     83        if (dataSources == null || dataSources.isEmpty()) {
     84            return null;
     85        }
     86        Area a = new Area();
     87        for (DataSource source : dataSources) {
     88            // create area from data bounds
     89            a.add(new Area(source.bounds.asRect()));
     90        }
     91        return a;
     92    }
     93
     94    /**
     95     * <p>Replies the list of data source bounds.</p>
     96     *
     97     * <p>Dataset maintains a list of data sources which have been merged into the
     98     * data set. Each of these sources can optionally declare a bounding box of the
     99     * data it supplied to the dataset.</p>
     100     *
     101     * <p>This method replies the list of defined (non {@code null}) bounding boxes.</p>
     102     * @param dataSources list of data sources
     103     *
     104     * @return the list of data source bounds. An empty list, if no non-null data source
     105     * bounds are defined.
     106     * @see Data#getDataSourceBounds()
     107     */
     108    public static List<Bounds> getDataSourceBounds(Collection<DataSource> dataSources) {
     109        if (dataSources == null) {
     110            return null;
     111        }
     112        List<Bounds> ret = new ArrayList<>(dataSources.size());
     113        for (DataSource ds : dataSources) {
     114            if (ds.bounds != null) {
     115                ret.add(ds.bounds);
     116            }
     117        }
     118        return ret;
     119    }
    32120}
Note: See TracChangeset for help on using the changeset viewer.