Skip to content

Commit

Permalink
Remove PointList#getSize (use size instead)
Browse files Browse the repository at this point in the history
  • Loading branch information
easbar committed May 17, 2021
1 parent f6d483e commit 8243cf2
Show file tree
Hide file tree
Showing 33 changed files with 148 additions and 157 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/com/graphhopper/ResponsePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ public ResponsePath setRouteWeight(double weight) {
public Envelope calcBBox2D() {
check("calcRouteBBox");
Envelope bounds = new Envelope();
for (int i = 0; i < pointList.getSize(); i++) {
for (int i = 0; i < pointList.size(); i++) {
bounds.expandToInclude(pointList.getLon(i), pointList.getLat(i));
}
return bounds;
}

@Override
public String toString() {
String str = "nodes:" + pointList.getSize() + "; " + pointList.toString();
String str = "nodes:" + pointList.size() + "; " + pointList.toString();
if (instructions != null && !instructions.isEmpty())
str += ", " + instructions.toString();

Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/com/graphhopper/util/Instruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public String toString() {
* See #1216 and #1138
*/
public int getLength() {
return points.getSize();
return points.size();
}

public String getTurnDescription(Translation tr) {
Expand Down
41 changes: 16 additions & 25 deletions api/src/main/java/com/graphhopper/util/PointList.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ public void reverse() {
throw new UnsupportedOperationException("cannot change EMPTY PointList");
}

@Override
public int getSize() {
return 0;
}

@Override
public int size() {
return 0;
Expand Down Expand Up @@ -236,9 +231,9 @@ public void add(GHPoint point) {

public void add(PointList points) {
ensureMutability();
int newSize = size + points.getSize();
int newSize = size + points.size();
incCap(newSize);
for (int i = 0; i < points.getSize(); i++) {
for (int i = 0; i < points.size(); i++) {
int tmp = size + i;
latitudes[tmp] = points.getLat(i);
longitudes[tmp] = points.getLon(i);
Expand All @@ -258,10 +253,6 @@ public int size() {
return size;
}

public int getSize() {
return size();
}

public boolean isEmpty() {
return size() == 0;
}
Expand Down Expand Up @@ -339,7 +330,7 @@ public void trimToSize(int newSize) {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < getSize(); i++) {
for (int i = 0; i < size(); i++) {
if (i > 0)
sb.append(", ");

Expand All @@ -365,8 +356,8 @@ public static PointList fromLineString(LineString lineString) {
}

public LineString toLineString(boolean includeElevation) {
Coordinate[] coordinates = new Coordinate[getSize() == 1 ? 2 : getSize()];
for (int i = 0; i < getSize(); i++) {
Coordinate[] coordinates = new Coordinate[size() == 1 ? 2 : size()];
for (int i = 0; i < size(); i++) {
coordinates[i] = includeElevation ?
new Coordinate(
round6(this.getLon(i)),
Expand All @@ -378,7 +369,7 @@ public LineString toLineString(boolean includeElevation) {
}

// special case as just 1 point is not supported in the specification #1412
if (getSize() == 1)
if (size() == 1)
coordinates[1] = coordinates[0];
return factory.createLineString(new PackedCoordinateSequence.Double(coordinates, includeElevation ? 3 : 2));
}
Expand All @@ -400,7 +391,7 @@ public boolean equals(Object obj) {
if (this.isEmpty() && other.isEmpty())
return true;

if (this.getSize() != other.getSize() || this.is3D() != other.is3D())
if (size() != other.size() || this.is3D() != other.is3D())
return false;

for (int i = 0; i < size(); i++) {
Expand Down Expand Up @@ -431,13 +422,13 @@ public static boolean equalsEps(double d1, double d2, double epsilon) {
* {@link ShallowImmutablePointList}, the cloned PointList will be a regular PointList.
*/
public PointList clone(boolean reverse) {
PointList clonePL = new PointList(getSize(), is3D());
PointList clonePL = new PointList(size(), is3D());
if (is3D())
for (int i = 0; i < getSize(); i++) {
for (int i = 0; i < size(); i++) {
clonePL.add(this.getLat(i), this.getLon(i), this.getEle(i));
}
else
for (int i = 0; i < getSize(); i++) {
for (int i = 0; i < size(); i++) {
clonePL.add(this.getLat(i), this.getLon(i));
}
if (reverse)
Expand All @@ -454,8 +445,8 @@ public PointList clone(boolean reverse) {
public PointList copy(int from, int end) {
if (from > end)
throw new IllegalArgumentException("from must be smaller or equal to end");
if (from < 0 || end > getSize())
throw new IllegalArgumentException("Illegal interval: " + from + ", " + end + ", size:" + getSize());
if (from < 0 || end > size())
throw new IllegalArgumentException("Illegal interval: " + from + ", " + end + ", size:" + size());


PointList thisPL = this;
Expand Down Expand Up @@ -492,11 +483,11 @@ public PointList shallowCopy(final int from, final int end, boolean makeImmutabl
@Override
public int hashCode() {
int hash = 5;
for (int i = 0; i < getSize(); i++) {
for (int i = 0; i < size(); i++) {
hash = 73 * hash + (int) Math.round(this.getLat(i) * 1000000);
hash = 73 * hash + (int) Math.round(this.getLon(i) * 1000000);
}
hash = 73 * hash + this.getSize();
hash = 73 * hash + size();
return hash;
}

Expand Down Expand Up @@ -530,12 +521,12 @@ public Iterator<GHPoint3D> iterator() {

@Override
public boolean hasNext() {
return counter < getSize();
return counter < size();
}

@Override
public GHPoint3D next() {
if (counter >= getSize())
if (counter >= size())
throw new NoSuchElementException();

GHPoint3D point = PointList.this.get(counter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class ShallowImmutablePointList extends PointList {
public ShallowImmutablePointList(int fromOffset, int toOffset, PointList wrappedPointList) {
if (fromOffset > toOffset)
throw new IllegalArgumentException("from must be smaller or equal to end");
if (fromOffset < 0 || toOffset > wrappedPointList.getSize())
if (fromOffset < 0 || toOffset > wrappedPointList.size())
throw new IllegalArgumentException("Illegal interval: " + fromOffset + ", " + toOffset);
this.fromOffset = fromOffset;
this.toOffset = toOffset;
Expand All @@ -47,7 +47,6 @@ public int size() {
return toOffset - fromOffset;
}

@Override
public int getSize() {
return size();
}
Expand All @@ -63,22 +62,22 @@ public String getIntervalString() {

@Override
public double getLat(int index) {
if (index > getSize())
throw new ArrayIndexOutOfBoundsException(ERR_MSG + " index:" + index + ", size:" + getSize());
if (index > size())
throw new ArrayIndexOutOfBoundsException(ERR_MSG + " index:" + index + ", size:" + size());
return wrappedPointList.getLat(fromOffset + index);
}

@Override
public double getLon(int index) {
if (index > getSize())
throw new ArrayIndexOutOfBoundsException(ERR_MSG + " index:" + index + ", size:" + getSize());
if (index > size())
throw new ArrayIndexOutOfBoundsException(ERR_MSG + " index:" + index + ", size:" + size());
return wrappedPointList.getLon(fromOffset + index);
}

@Override
public double getEle(int index) {
if (index > getSize())
throw new ArrayIndexOutOfBoundsException(ERR_MSG + " index:" + index + ", size:" + getSize());
if (index > size())
throw new ArrayIndexOutOfBoundsException(ERR_MSG + " index:" + index + ", size:" + size());
return wrappedPointList.getEle(fromOffset + index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public Result triangulate(Snap snap, QueryGraph queryGraph, ShortestPathTree sho
if (label.parent != null) {
EdgeIteratorState edge = queryGraph.getEdgeIteratorState(label.edge, label.node);
PointList innerPoints = edge.fetchWayGeometry(FetchMode.PILLAR_ONLY);
if (innerPoints.getSize() > 0) {
int midIndex = innerPoints.getSize() / 2;
if (innerPoints.size() > 0) {
int midIndex = innerPoints.size() / 2;
double lat2 = innerPoints.getLat(midIndex);
double lon2 = innerPoints.getLon(midIndex);
Coordinate site2 = new Coordinate(lon2, lat2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public class EdgeSampling {
private EdgeSampling() {}

public static PointList sample(PointList input, double maxDistance, DistanceCalc distCalc, ElevationProvider elevation) {
PointList output = new PointList(input.getSize() * 2, input.is3D());
PointList output = new PointList(input.size() * 2, input.is3D());
if (input.isEmpty()) return output;
int nodes = input.getSize();
int nodes = input.size();
double lastLat = input.getLat(0), lastLon = input.getLon(0), lastEle = input.getEle(0),
thisLat, thisLon, thisEle;
for (int i = 0; i < nodes; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ Collection<EdgeIteratorState> addOSMWay(final LongIndexedContainer osmNodeIds, f
tmpNode = lastInBoundsPillarNode;
tmpNode = handlePillarNode(tmpNode, osmNodeId, null, true);
tmpNode = -tmpNode - 3;
if (pointList.getSize() > 1 && firstNode >= 0) {
if (pointList.size() > 1 && firstNode >= 0) {
// TOWER node
newEdges.add(addEdge(firstNode, tmpNode, pointList, flags, wayOsmId));
pointList.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void next(EdgeIteratorState edge, int index, int prevEdgeId) {
PointList wayGeo = edge.fetchWayGeometry(FetchMode.ALL);
boolean isRoundabout = edge.get(roundaboutEnc);

if (wayGeo.getSize() <= 2) {
if (wayGeo.size() <= 2) {
latitude = adjLat;
longitude = adjLon;
} else {
Expand Down Expand Up @@ -290,11 +290,11 @@ public void next(EdgeIteratorState edge, int index, int prevEdgeId) {

updatePointsAndInstruction(edge, wayGeo);

if (wayGeo.getSize() <= 2) {
if (wayGeo.size() <= 2) {
doublePrevLat = prevLat;
doublePrevLon = prevLon;
} else {
int beforeLast = wayGeo.getSize() - 2;
int beforeLast = wayGeo.size() - 2;
doublePrevLat = wayGeo.getLat(beforeLast);
doublePrevLon = wayGeo.getLon(beforeLast);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static GHPoint getPointForOrientationCalculation(EdgeIteratorState edgeIteratorS
double tmpLat;
double tmpLon;
PointList tmpWayGeo = edgeIteratorState.fetchWayGeometry(FetchMode.ALL);
if (tmpWayGeo.getSize() <= 2) {
if (tmpWayGeo.size() <= 2) {
tmpLat = nodeAccess.getLat(edgeIteratorState.getAdjNode());
tmpLon = nodeAccess.getLon(edgeIteratorState.getAdjNode());
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/graphhopper/routing/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public PointList calcPoints() {
@Override
public void next(EdgeIteratorState eb, int index, int prevEdgeId) {
PointList pl = eb.fetchWayGeometry(FetchMode.PILLAR_AND_ADJ);
for (int j = 0; j < pl.getSize(); j++) {
for (int j = 0; j < pl.size(); j++) {
points.add(pl, j);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void clearUnfavoredStatus() {

@Override
public int getNodes() {
return queryOverlay.getVirtualNodes().getSize() + baseNodes;
return queryOverlay.getVirtualNodes().size() + baseNodes;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ private void buildVirtualEdges(List<Snap> snaps) {
snap.setClosestEdge(closestEdge);
if (snap.getSnappedPosition() == Snap.Position.PILLAR)
// ON pillar node
snap.setWayIndex(fullPL.getSize() - snap.getWayIndex() - 1);
snap.setWayIndex(fullPL.size() - snap.getWayIndex() - 1);
else
// for case "OFF pillar node"
snap.setWayIndex(fullPL.getSize() - snap.getWayIndex() - 2);
snap.setWayIndex(fullPL.size() - snap.getWayIndex() - 2);

if (snap.getWayIndex() < 0)
throw new IllegalStateException("Problem with wayIndex while reversing closest edge:" + closestEdge + ", " + snap);
Expand Down Expand Up @@ -150,7 +150,7 @@ private double distanceOfSnappedPointToPillarNode(Snap o) {
int origRevEdgeKey = GHUtility.reverseEdgeKey(origEdgeKey);
int prevWayIndex = 1;
int prevNodeId = baseNode;
int virtNodeId = queryOverlay.getVirtualNodes().getSize() + firstVirtualNodeId;
int virtNodeId = queryOverlay.getVirtualNodes().size() + firstVirtualNodeId;
boolean addedEdges = false;

// Create base and adjacent PointLists for all non-equal virtual nodes.
Expand Down Expand Up @@ -195,7 +195,7 @@ private double distanceOfSnappedPointToPillarNode(Snap o) {
if (addedEdges)
createEdges(origEdgeKey, origRevEdgeKey,
prevPoint, prevWayIndex, false,
fullPL.get(fullPL.getSize() - 1), fullPL.getSize() - 2,
fullPL.get(fullPL.size() - 1), fullPL.size() - 2,
fullPL, closestEdge, virtNodeId - 1, adjNode);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
*/
package com.graphhopper.routing.querygraph;

import com.graphhopper.routing.ev.BooleanEncodedValue;
import com.graphhopper.routing.ev.DecimalEncodedValue;
import com.graphhopper.routing.ev.EnumEncodedValue;
import com.graphhopper.routing.ev.IntEncodedValue;
import com.graphhopper.routing.ev.StringEncodedValue;
import com.graphhopper.routing.ev.*;
import com.graphhopper.storage.IntsRef;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.FetchMode;
Expand Down Expand Up @@ -93,26 +89,26 @@ public int getAdjNode() {

@Override
public PointList fetchWayGeometry(FetchMode mode) {
if (pointList.getSize() == 0)
if (pointList.size() == 0)
return PointList.EMPTY;
// due to API we need to create a new instance per call!
if (mode == FetchMode.TOWER_ONLY) {
if (pointList.getSize() < 3)
if (pointList.size() < 3)
return pointList.clone(false);
PointList towerNodes = new PointList(2, pointList.is3D());
towerNodes.add(pointList, 0);
towerNodes.add(pointList, pointList.getSize() - 1);
towerNodes.add(pointList, pointList.size() - 1);
return towerNodes;
} else if (mode == FetchMode.ALL)
return pointList.clone(false);
else if (mode == FetchMode.BASE_AND_PILLAR)
return pointList.copy(0, pointList.getSize() - 1);
return pointList.copy(0, pointList.size() - 1);
else if (mode == FetchMode.PILLAR_AND_ADJ)
return pointList.copy(1, pointList.getSize());
return pointList.copy(1, pointList.size());
else if (mode == FetchMode.PILLAR_ONLY) {
if (pointList.getSize() == 1)
if (pointList.size() == 1)
return PointList.EMPTY;
return pointList.copy(1, pointList.getSize() - 1);
return pointList.copy(1, pointList.size() - 1);
}
throw new UnsupportedOperationException("Illegal mode:" + mode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private static BBox createBBox(EdgeIteratorState edgeState) {
// we should include the entire geometry, see #2319
PointList geometry = edgeState.fetchWayGeometry(FetchMode.ALL);
BBox bbox = new BBox(180, -180, 90, -90);
for (int i = 0; i < geometry.getSize(); i++)
for (int i = 0; i < geometry.size(); i++)
bbox.update(geometry.getLat(i), geometry.getLon(i));
return bbox;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/graphhopper/storage/BaseGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ private void setWayGeometry_(PointList pillarNodes, long edgePointer, boolean re

long existingGeoRef = Helper.toUnsignedLong(edges.getInt(edgePointer + E_GEO));

int len = pillarNodes.getSize();
int len = pillarNodes.size();
int dim = nodeAccess.getDimension();
if (existingGeoRef > 0) {
final int count = wayGeometry.getInt(existingGeoRef * 4L);
Expand All @@ -773,7 +773,7 @@ private void setWayGeometry_(PointList pillarNodes, long edgePointer, boolean re
}

private void setWayGeometryAtGeoRef(PointList pillarNodes, long edgePointer, boolean reverse, long geoRef) {
int len = pillarNodes.getSize();
int len = pillarNodes.size();
int dim = nodeAccess.getDimension();
long geoRefPosition = geoRef * 4;
int totalLen = len * dim * 4 + 4;
Expand All @@ -784,7 +784,7 @@ private void setWayGeometryAtGeoRef(PointList pillarNodes, long edgePointer, boo
}

private byte[] createWayGeometryBytes(PointList pillarNodes, boolean reverse) {
int len = pillarNodes.getSize();
int len = pillarNodes.size();
int dim = nodeAccess.getDimension();
int totalLen = len * dim * 4 + 4;
byte[] bytes = new byte[totalLen];
Expand Down
Loading

0 comments on commit 8243cf2

Please sign in to comment.