source: josm/trunk/src/org/openstreetmap/josm/data/DataSource.java

Last change on this file was 18208, checked in by Don-vip, 3 years ago

global use of Utils.isEmpty/isBlank

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