Skip to content

Commit 1e1469d

Browse files
committed
ensure we use separate point hints list internally, as we modify it
1 parent 982f837 commit 1e1469d

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

client-hc/src/main/java/com/graphhopper/api/GHMRequest.java

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ public GHMRequest addAllPoints(List<GHPoint> points) {
6161
return this;
6262
}
6363

64-
@Override
65-
public List<GHPoint> getPoints() {
66-
throw new IllegalStateException("use getFromPoints or getToPoints");
67-
}
68-
69-
public List<GHPoint> getFromPoints() {
70-
return fromPoints;
71-
}
72-
73-
public List<GHPoint> getToPoints() {
74-
return toPoints;
75-
}
76-
7764
/**
7865
* This methods adds the coordinate as 'from' and 'to' to the request.
7966
*/
@@ -84,6 +71,11 @@ public GHMRequest addPoint(GHPoint point) {
8471
return this;
8572
}
8673

74+
@Override
75+
public List<GHPoint> getPoints() {
76+
throw new IllegalStateException("use getFromPoints or getToPoints");
77+
}
78+
8779
public GHMRequest addFromPoint(GHPoint point) {
8880
fromPoints.add(point);
8981
identicalLists = false;
@@ -96,90 +88,100 @@ public GHMRequest setFromPoints(List<GHPoint> points) {
9688
return this;
9789
}
9890

99-
public GHRequest addFromPointHint(String pointHint) {
100-
this.fromPointHints.add(pointHint);
91+
public List<GHPoint> getFromPoints() {
92+
return fromPoints;
93+
}
94+
95+
public GHMRequest addToPoint(GHPoint point) {
96+
toPoints.add(point);
97+
identicalLists = false;
10198
return this;
10299
}
103100

104-
public GHRequest setFromPointHints(List<String> pointHints) {
105-
this.fromPointHints = pointHints;
101+
public GHMRequest setToPoints(List<GHPoint> points) {
102+
toPoints = points;
103+
identicalLists = false;
106104
return this;
107105
}
108106

109-
public List<String> getFromPointHints() {
110-
return fromPointHints;
107+
public List<GHPoint> getToPoints() {
108+
return toPoints;
111109
}
112110

113-
public GHMRequest addFromCurbside(String curbside) {
114-
fromCurbsides.add(curbside);
111+
@Override
112+
public GHRequest setPointHints(List<String> pointHints) {
113+
setToPointHints(pointHints);
114+
this.fromPointHints = this.toPointHints;
115115
return this;
116116
}
117117

118-
public GHMRequest setFromCurbsides(List<String> curbsides) {
119-
fromCurbsides = curbsides;
120-
return this;
118+
@Override
119+
public List<String> getPointHints() {
120+
throw new IllegalStateException("Use getFromPointHints or getToPointHints");
121121
}
122122

123-
public List<String> getFromCurbsides() {
124-
return fromCurbsides;
123+
@Override
124+
public boolean hasPointHints() {
125+
return this.fromPointHints.size() == this.fromPoints.size() && !fromPoints.isEmpty() &&
126+
this.toPointHints.size() == this.toPoints.size() && !toPoints.isEmpty();
125127
}
126128

127-
public GHMRequest addToPoint(GHPoint point) {
128-
toPoints.add(point);
129-
identicalLists = false;
129+
public GHRequest addFromPointHint(String pointHint) {
130+
this.fromPointHints.add(pointHint);
130131
return this;
131132
}
132133

133-
public GHMRequest setToPoints(List<GHPoint> points) {
134-
toPoints = points;
135-
identicalLists = false;
134+
public GHRequest setFromPointHints(List<String> pointHints) {
135+
// create new array as we modify pointHints in compactPointHints
136+
this.fromPointHints = new ArrayList<>(pointHints);
136137
return this;
137138
}
138139

140+
public List<String> getFromPointHints() {
141+
return fromPointHints;
142+
}
143+
139144
public GHRequest addToPointHint(String pointHint) {
140145
this.toPointHints.add(pointHint);
141146
return this;
142147
}
143148

144149
public GHRequest setToPointHints(List<String> pointHints) {
145-
this.toPointHints = pointHints;
150+
// create new array as we modify pointHints in compactPointHints
151+
this.toPointHints = new ArrayList<>(pointHints);
146152
return this;
147153
}
148154

149155
public List<String> getToPointHints() {
150156
return toPointHints;
151157
}
152158

153-
public GHMRequest addToCurbside(String curbside) {
154-
toCurbsides.add(curbside);
159+
public GHMRequest addFromCurbside(String curbside) {
160+
fromCurbsides.add(curbside);
155161
return this;
156162
}
157163

158-
public GHMRequest setToCurbsides(List<String> curbsides) {
159-
toCurbsides = curbsides;
164+
public GHMRequest setFromCurbsides(List<String> curbsides) {
165+
fromCurbsides = curbsides;
160166
return this;
161167
}
162168

163-
public List<String> getToCurbsides() {
164-
return toCurbsides;
169+
public List<String> getFromCurbsides() {
170+
return fromCurbsides;
165171
}
166172

167-
@Override
168-
public GHRequest setPointHints(List<String> pointHints) {
169-
this.fromPointHints = pointHints;
170-
this.toPointHints = pointHints;
173+
public GHMRequest addToCurbside(String curbside) {
174+
toCurbsides.add(curbside);
171175
return this;
172176
}
173177

174-
@Override
175-
public List<String> getPointHints() {
176-
throw new IllegalStateException("Use getFromPointHints or getToPointHints");
178+
public GHMRequest setToCurbsides(List<String> curbsides) {
179+
toCurbsides = curbsides;
180+
return this;
177181
}
178182

179-
@Override
180-
public boolean hasPointHints() {
181-
return this.fromPointHints.size() == this.fromPoints.size() && !fromPoints.isEmpty() &&
182-
this.toPointHints.size() == this.toPoints.size() && !toPoints.isEmpty();
183+
public List<String> getToCurbsides() {
184+
return toCurbsides;
183185
}
184186

185187
@Override

0 commit comments

Comments
 (0)