1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import java.util.Date;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.coor.CoordinateFormat;
|
---|
7 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
8 | import org.openstreetmap.josm.tools.DateUtils;
|
---|
9 |
|
---|
10 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
11 |
|
---|
12 | public class ChangesetQuery {
|
---|
13 | private Long user = null;
|
---|
14 | private LatLon min = null;
|
---|
15 | private LatLon max = null;
|
---|
16 | private Date closedAfter = null;
|
---|
17 | private Date createdBefore = null;
|
---|
18 | private Boolean open = null;
|
---|
19 | private Boolean closed = null;
|
---|
20 |
|
---|
21 | public ChangesetQuery() {}
|
---|
22 |
|
---|
23 | public ChangesetQuery forUser(long uid) {
|
---|
24 | if (uid <= 0)
|
---|
25 | throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0 expected. Got ''{1}''.", "uid", uid));
|
---|
26 | this.user = uid;
|
---|
27 | return this;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public ChangesetQuery inBbox(double minLon, double minLat, double maxLon, double maxLat) {
|
---|
31 | return inBbox(new LatLon(minLon, minLat), new LatLon(maxLon, maxLat));
|
---|
32 | }
|
---|
33 |
|
---|
34 | public ChangesetQuery inBbox(LatLon min, LatLon max) {
|
---|
35 | this.min = min;
|
---|
36 | this.max = max;
|
---|
37 | return this;
|
---|
38 | }
|
---|
39 |
|
---|
40 | public ChangesetQuery closedAfter(Date d) {
|
---|
41 | this.closedAfter = d;
|
---|
42 | return this;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public ChangesetQuery between(Date closedAfter, Date createdBefore ) {
|
---|
46 | this.closedAfter = closedAfter;
|
---|
47 | this.createdBefore = createdBefore;
|
---|
48 | return this;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public ChangesetQuery beingOpen() {
|
---|
52 | this.open = true;
|
---|
53 | this.closed = null;
|
---|
54 | return this;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public ChangesetQuery beingClosed() {
|
---|
58 | this.open = null;
|
---|
59 | this.closed = true;
|
---|
60 | return this;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public String getQueryString() {
|
---|
64 | StringBuffer sb = new StringBuffer();
|
---|
65 | if (user != null) {
|
---|
66 | sb.append("user").append("=").append(user);
|
---|
67 | }
|
---|
68 | if (min!=null && max != null) {
|
---|
69 | if (sb.length() > 0) {
|
---|
70 | sb.append("&");
|
---|
71 | }
|
---|
72 | sb.append("min_lon").append("=").append(min.lonToString(CoordinateFormat.DECIMAL_DEGREES));
|
---|
73 | sb.append("&");
|
---|
74 | sb.append("min_lat").append("=").append(min.latToString(CoordinateFormat.DECIMAL_DEGREES));
|
---|
75 | sb.append("&");
|
---|
76 | sb.append("max_lon").append("=").append(max.lonToString(CoordinateFormat.DECIMAL_DEGREES));
|
---|
77 | sb.append("&");
|
---|
78 | sb.append("max_lat").append("=").append(max.latToString(CoordinateFormat.DECIMAL_DEGREES));
|
---|
79 | }
|
---|
80 | if (closedAfter != null && createdBefore != null) {
|
---|
81 | if (sb.length() > 0) {
|
---|
82 | sb.append("&");
|
---|
83 | }
|
---|
84 | sb.append("time").append("=").append(DateUtils.fromDate(closedAfter))
|
---|
85 | .append(",").append(DateUtils.fromDate(createdBefore));
|
---|
86 | } else if (closedAfter != null) {
|
---|
87 | if (sb.length() > 0) {
|
---|
88 | sb.append("&");
|
---|
89 | }
|
---|
90 | sb.append("time").append("=").append(DateUtils.fromDate(closedAfter));
|
---|
91 | }
|
---|
92 |
|
---|
93 | if (open != null) {
|
---|
94 | if (sb.length() > 0) {
|
---|
95 | sb.append("&");
|
---|
96 | }
|
---|
97 | sb.append("open=true");
|
---|
98 | } else if (closed != null) {
|
---|
99 | if (sb.length() > 0) {
|
---|
100 | sb.append("&");
|
---|
101 | }
|
---|
102 | sb.append("closed=true");
|
---|
103 | }
|
---|
104 | return sb.toString();
|
---|
105 | }
|
---|
106 | }
|
---|