[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[7575] | 2 | package org.openstreetmap.josm.data;
|
---|
[247] | 3 |
|
---|
[7575] | 4 | import java.awt.geom.Area;
|
---|
| 5 | import java.util.ArrayList;
|
---|
| 6 | import java.util.Collection;
|
---|
| 7 | import java.util.List;
|
---|
[9371] | 8 | import java.util.Objects;
|
---|
[7575] | 9 |
|
---|
[6229] | 10 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
[247] | 11 |
|
---|
[6229] | 12 | /**
|
---|
| 13 | * A data source, defined by bounds and textual description for the origin.
|
---|
[7575] | 14 | * @since 247 (creation)
|
---|
| 15 | * @since 7575 (moved package)
|
---|
[6229] | 16 | */
|
---|
[2986] | 17 | public class DataSource {
|
---|
[7575] | 18 |
|
---|
[6229] | 19 | /**
|
---|
| 20 | * The bounds of this data source
|
---|
| 21 | */
|
---|
[1169] | 22 | public final Bounds bounds;
|
---|
[7575] | 23 |
|
---|
[6229] | 24 | /**
|
---|
| 25 | * The textual description of the origin (example: "OpenStreetMap Server")
|
---|
| 26 | */
|
---|
[1169] | 27 | public final String origin;
|
---|
| 28 |
|
---|
[6229] | 29 | /**
|
---|
| 30 | * Constructs a new {@code DataSource}.
|
---|
| 31 | * @param bounds The bounds of this data source
|
---|
| 32 | * @param origin The textual description of the origin (example: "OpenStreetMap Server")
|
---|
| 33 | * @throws IllegalArgumentException if bounds is {@code null}
|
---|
| 34 | */
|
---|
[1169] | 35 | public DataSource(Bounds bounds, String origin) {
|
---|
[6229] | 36 | CheckParameterUtil.ensureParameterNotNull(bounds, "bounds");
|
---|
[1169] | 37 | this.bounds = bounds;
|
---|
| 38 | this.origin = origin;
|
---|
[290] | 39 | }
|
---|
[7575] | 40 |
|
---|
| 41 | @Override
|
---|
| 42 | public int hashCode() {
|
---|
[9371] | 43 | return Objects.hash(bounds, origin);
|
---|
[7575] | 44 | }
|
---|
| 45 |
|
---|
| 46 | @Override
|
---|
| 47 | public boolean equals(Object obj) {
|
---|
[9371] | 48 | if (this == obj) return true;
|
---|
| 49 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
| 50 | DataSource that = (DataSource) obj;
|
---|
| 51 | return Objects.equals(bounds, that.bounds) &&
|
---|
| 52 | Objects.equals(origin, that.origin);
|
---|
[7575] | 53 | }
|
---|
| 54 |
|
---|
| 55 | @Override
|
---|
| 56 | public String toString() {
|
---|
[8846] | 57 | return "DataSource [bounds=" + bounds + ", origin=" + origin + ']';
|
---|
[7575] | 58 | }
|
---|
| 59 |
|
---|
| 60 | /**
|
---|
| 61 | * Returns the total area of downloaded data (the "yellow rectangles").
|
---|
| 62 | * @param dataSources list of data sources
|
---|
| 63 | * @return Area object encompassing downloaded data.
|
---|
| 64 | * @see Data#getDataSourceArea()
|
---|
| 65 | */
|
---|
| 66 | public static Area getDataSourceArea(Collection<DataSource> dataSources) {
|
---|
| 67 | if (dataSources == null || dataSources.isEmpty()) {
|
---|
| 68 | return null;
|
---|
| 69 | }
|
---|
| 70 | Area a = new Area();
|
---|
| 71 | for (DataSource source : dataSources) {
|
---|
| 72 | // create area from data bounds
|
---|
| 73 | a.add(new Area(source.bounds.asRect()));
|
---|
| 74 | }
|
---|
| 75 | return a;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /**
|
---|
| 79 | * <p>Replies the list of data source bounds.</p>
|
---|
| 80 | *
|
---|
| 81 | * <p>Dataset maintains a list of data sources which have been merged into the
|
---|
| 82 | * data set. Each of these sources can optionally declare a bounding box of the
|
---|
| 83 | * data it supplied to the dataset.</p>
|
---|
| 84 | *
|
---|
| 85 | * <p>This method replies the list of defined (non {@code null}) bounding boxes.</p>
|
---|
| 86 | * @param dataSources list of data sources
|
---|
| 87 | *
|
---|
| 88 | * @return the list of data source bounds. An empty list, if no non-null data source
|
---|
| 89 | * bounds are defined.
|
---|
| 90 | * @see Data#getDataSourceBounds()
|
---|
| 91 | */
|
---|
| 92 | public static List<Bounds> getDataSourceBounds(Collection<DataSource> dataSources) {
|
---|
| 93 | if (dataSources == null) {
|
---|
| 94 | return null;
|
---|
| 95 | }
|
---|
| 96 | List<Bounds> ret = new ArrayList<>(dataSources.size());
|
---|
| 97 | for (DataSource ds : dataSources) {
|
---|
| 98 | if (ds.bounds != null) {
|
---|
| 99 | ret.add(ds.bounds);
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | return ret;
|
---|
| 103 | }
|
---|
[247] | 104 | }
|
---|