Skip to content

Commit

Permalink
ensure we use separate point hints list internally, as we modify it
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Dec 9, 2019
1 parent 982f837 commit 1e1469d
Showing 1 changed file with 52 additions and 50 deletions.
102 changes: 52 additions & 50 deletions client-hc/src/main/java/com/graphhopper/api/GHMRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,6 @@ public GHMRequest addAllPoints(List<GHPoint> points) {
return this;
}

@Override
public List<GHPoint> getPoints() {
throw new IllegalStateException("use getFromPoints or getToPoints");
}

public List<GHPoint> getFromPoints() {
return fromPoints;
}

public List<GHPoint> getToPoints() {
return toPoints;
}

/**
* This methods adds the coordinate as 'from' and 'to' to the request.
*/
Expand All @@ -84,6 +71,11 @@ public GHMRequest addPoint(GHPoint point) {
return this;
}

@Override
public List<GHPoint> getPoints() {
throw new IllegalStateException("use getFromPoints or getToPoints");
}

public GHMRequest addFromPoint(GHPoint point) {
fromPoints.add(point);
identicalLists = false;
Expand All @@ -96,90 +88,100 @@ public GHMRequest setFromPoints(List<GHPoint> points) {
return this;
}

public GHRequest addFromPointHint(String pointHint) {
this.fromPointHints.add(pointHint);
public List<GHPoint> getFromPoints() {
return fromPoints;
}

public GHMRequest addToPoint(GHPoint point) {
toPoints.add(point);
identicalLists = false;
return this;
}

public GHRequest setFromPointHints(List<String> pointHints) {
this.fromPointHints = pointHints;
public GHMRequest setToPoints(List<GHPoint> points) {
toPoints = points;
identicalLists = false;
return this;
}

public List<String> getFromPointHints() {
return fromPointHints;
public List<GHPoint> getToPoints() {
return toPoints;
}

public GHMRequest addFromCurbside(String curbside) {
fromCurbsides.add(curbside);
@Override
public GHRequest setPointHints(List<String> pointHints) {
setToPointHints(pointHints);
this.fromPointHints = this.toPointHints;
return this;
}

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

public List<String> getFromCurbsides() {
return fromCurbsides;
@Override
public boolean hasPointHints() {
return this.fromPointHints.size() == this.fromPoints.size() && !fromPoints.isEmpty() &&
this.toPointHints.size() == this.toPoints.size() && !toPoints.isEmpty();
}

public GHMRequest addToPoint(GHPoint point) {
toPoints.add(point);
identicalLists = false;
public GHRequest addFromPointHint(String pointHint) {
this.fromPointHints.add(pointHint);
return this;
}

public GHMRequest setToPoints(List<GHPoint> points) {
toPoints = points;
identicalLists = false;
public GHRequest setFromPointHints(List<String> pointHints) {
// create new array as we modify pointHints in compactPointHints
this.fromPointHints = new ArrayList<>(pointHints);
return this;
}

public List<String> getFromPointHints() {
return fromPointHints;
}

public GHRequest addToPointHint(String pointHint) {
this.toPointHints.add(pointHint);
return this;
}

public GHRequest setToPointHints(List<String> pointHints) {
this.toPointHints = pointHints;
// create new array as we modify pointHints in compactPointHints
this.toPointHints = new ArrayList<>(pointHints);
return this;
}

public List<String> getToPointHints() {
return toPointHints;
}

public GHMRequest addToCurbside(String curbside) {
toCurbsides.add(curbside);
public GHMRequest addFromCurbside(String curbside) {
fromCurbsides.add(curbside);
return this;
}

public GHMRequest setToCurbsides(List<String> curbsides) {
toCurbsides = curbsides;
public GHMRequest setFromCurbsides(List<String> curbsides) {
fromCurbsides = curbsides;
return this;
}

public List<String> getToCurbsides() {
return toCurbsides;
public List<String> getFromCurbsides() {
return fromCurbsides;
}

@Override
public GHRequest setPointHints(List<String> pointHints) {
this.fromPointHints = pointHints;
this.toPointHints = pointHints;
public GHMRequest addToCurbside(String curbside) {
toCurbsides.add(curbside);
return this;
}

@Override
public List<String> getPointHints() {
throw new IllegalStateException("Use getFromPointHints or getToPointHints");
public GHMRequest setToCurbsides(List<String> curbsides) {
toCurbsides = curbsides;
return this;
}

@Override
public boolean hasPointHints() {
return this.fromPointHints.size() == this.fromPoints.size() && !fromPoints.isEmpty() &&
this.toPointHints.size() == this.toPoints.size() && !toPoints.isEmpty();
public List<String> getToCurbsides() {
return toCurbsides;
}

@Override
Expand Down

0 comments on commit 1e1469d

Please sign in to comment.