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

Last change on this file since 9168 was 8846, checked in by Don-vip, 9 years ago

sonar - fb-contrib - minor performance improvements:

  • Method passes constant String of length 1 to character overridden method
  • Method needlessly boxes a boolean constant
  • Method uses iterator().next() on a List to get the first item
  • Method converts String to boxed primitive using excessive boxing
  • Method converts String to primitive using excessive boxing
  • Method creates array using constants
  • Class defines List based fields but uses them like Sets
  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data;
3
4import java.awt.geom.Area;
5import java.util.ArrayList;
6import java.util.Collection;
7import java.util.List;
8
9import org.openstreetmap.josm.tools.CheckParameterUtil;
10
11/**
12 * A data source, defined by bounds and textual description for the origin.
13 * @since 247 (creation)
14 * @since 7575 (moved package)
15 */
16public class DataSource {
17
18 /**
19 * The bounds of this data source
20 */
21 public final Bounds bounds;
22
23 /**
24 * The textual description of the origin (example: "OpenStreetMap Server")
25 */
26 public final String origin;
27
28 /**
29 * Constructs a new {@code DataSource}.
30 * @param bounds The bounds of this data source
31 * @param origin The textual description of the origin (example: "OpenStreetMap Server")
32 * @throws IllegalArgumentException if bounds is {@code null}
33 */
34 public DataSource(Bounds bounds, String origin) {
35 CheckParameterUtil.ensureParameterNotNull(bounds, "bounds");
36 this.bounds = bounds;
37 this.origin = origin;
38 }
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 }
120}
Note: See TracBrowser for help on using the repository browser.