Skip to content

Commit e1bb87d

Browse files
PeterKarl Hübner
Peter
authored and
Karl Hübner
committed
minor cleanup
1 parent 5ae9b7f commit e1bb87d

File tree

8 files changed

+30
-44
lines changed

8 files changed

+30
-44
lines changed

core/src/main/java/com/graphhopper/reader/OSMElement.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public boolean hasInternalTag( String key )
229229
return iProperties.containsKey(key);
230230
}
231231

232+
@SuppressWarnings("unchecked")
232233
public <T> T getInternalTag( String key, T defaultValue )
233234
{
234235
if (iProperties == null)

core/src/main/java/com/graphhopper/reader/OSMReader.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public class OSMReader
110110
protected DataAccess pillarLats;
111111
protected DataAccess pillarLons;
112112
protected DataAccess edgeOsmIds;
113-
protected DataAccess nodeOsmIds;
114113
private final DistanceCalc distCalc = new DistanceCalcEarth();
115114
private final DouglasPeucker simplifyAlgo = new DouglasPeucker();
116115
private int nextTowerId = 0;
@@ -120,6 +119,7 @@ public class OSMReader
120119
private boolean exitOnlyPillarNodeException = true;
121120
//relation factory specifies an arbitrary osm relation
122121
private OSMRelationFactory relationFactory = new OSMRelationFactory();
122+
private final BitUtil bitUtil;
123123

124124
public OSMReader( GraphStorage storage, long expectedCap )
125125
{
@@ -134,13 +134,12 @@ public OSMReader( GraphStorage storage, long expectedCap )
134134
pillarLats = dir.find("tmpLatitudes");
135135
pillarLons = dir.find("tmpLongitudes");
136136
edgeOsmIds = dir.find("tmpEdgeOsmIds");
137-
nodeOsmIds = dir.find("tmpNodeOsmIds");
138137
pillarLats.create(Math.max(expectedCap, 100));
139138
pillarLons.create(Math.max(expectedCap, 100));
140139
edgeOsmIds.create(Math.max(expectedCap, 100));
141-
nodeOsmIds.create(Math.max(expectedCap, 100));
142140

143141
relationFactory = new OSMRelationFactory();
142+
bitUtil = BitUtil.get(dir.getByteOrder());
144143
}
145144

146145
public void doOSM2Graph( File osmFile ) throws IOException
@@ -454,21 +453,17 @@ public void processRelation( OSMRelation relation ) throws XMLStreamException
454453

455454
public long getOsmIdOfInternalEdge( int edgeId )
456455
{
457-
BitUtil bitUtil = BitUtil.get(dir.getByteOrder());
458-
459456
byte[] bytesOsmWayId = new byte[8];
460457
edgeOsmIds.getBytes(edgeId * 8, bytesOsmWayId, 8);
461-
462458
return bitUtil.toLong(bytesOsmWayId);
463459
}
464460

465461
public int getInternalNodeIdOfOsmNode( long nodeOsmId )
466462
{
467463
int id = getNodeMap().get(nodeOsmId);
468464
if (id < TOWER_NODE)
469-
{
470465
return -id - 3;
471-
}
466+
472467
return EMPTY;
473468
}
474469

@@ -741,9 +736,6 @@ EdgeIteratorState addEdge( int fromIndex, int toIndex, PointList pointList, long
741736
private void storeOSMWayID( int edgeId, long osmWayID )
742737
{
743738
long ptr = (long) edgeId * 8;
744-
745-
BitUtil bitUtil = BitUtil.get(dir.getByteOrder());
746-
747739
edgeOsmIds.incCapacity(ptr + 8);
748740
edgeOsmIds.setBytes(ptr, bitUtil.fromLong(osmWayID), 8);
749741
}
@@ -785,11 +777,9 @@ void finishedReading()
785777
dir.remove(pillarLats);
786778
dir.remove(pillarLons);
787779
dir.remove(edgeOsmIds);
788-
dir.remove(nodeOsmIds);
789780
pillarLons = null;
790781
pillarLats = null;
791782
edgeOsmIds = null;
792-
nodeOsmIds = null;
793783
osmNodeIdToInternalNodeMap = null;
794784
osmNodeIdToNodeFlagsMap = null;
795785
osmWayIdToRouteWeightMap = null;

core/src/main/java/com/graphhopper/reader/OSMTurnRelation.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
import java.util.HashSet;
55
import java.util.Set;
66

7-
import org.slf4j.LoggerFactory;
8-
97
import com.graphhopper.reader.OSMRelationFactory.OSMRelationFactoryEngine;
108
import com.graphhopper.routing.util.TurnCostEncoder;
119
import com.graphhopper.util.EdgeExplorer;
1210
import com.graphhopper.util.EdgeIterator;
1311

1412
/**
1513
* Helper object which gives node cost entries for a given OSM-relation of type "restriction"
16-
*
14+
* <p>
1715
* @author Karl Hübner
1816
*/
1917
public class OSMTurnRelation extends OSMRelation
@@ -28,10 +26,10 @@ public class OSMTurnRelation extends OSMRelation
2826
public static final int TYPE_ONLY_STRAIGHT_ON = 6;
2927
public static final int TYPE_NO_U_TURN = 7;
3028

31-
protected long fromOsm;
32-
protected long viaOsm;
33-
protected long toOsm;
34-
protected int restriction;
29+
private long fromOsm;
30+
private long viaOsm;
31+
private long toOsm;
32+
private int restriction;
3533

3634
private OSMTurnRelation( OSMRelation parent )
3735
{
@@ -46,9 +44,9 @@ private boolean isValid()
4644

4745
/**
4846
* transforms this relation into a collection of node cost entries
49-
*
50-
* @param edgeOutFilter an edge filter which only allows outgoing edges
51-
* @param edgeInFilter an edge filter which only allows incoming edges
47+
* <p>
48+
* @param edgeOutExplorer an edge filter which only allows outgoing edges
49+
* @param edgeInExplorer an edge filter which only allows incoming edges
5250
* @return a collection of node cost entries which can be added to the graph later
5351
*/
5452
public Collection<TurnCostTableEntry> getRestrictionAsEntries( TurnCostEncoder encoder,
@@ -64,7 +62,7 @@ public Collection<TurnCostTableEntry> getRestrictionAsEntries( TurnCostEncoder e
6462
{
6563
throw new IllegalArgumentException("Unknown node osm id");
6664
}
67-
65+
6866
int edgeIdFrom = EdgeIterator.NO_EDGE;
6967

7068
// get all incoming edges and receive the edge which is defined by fromOsm
@@ -83,8 +81,8 @@ public Collection<TurnCostTableEntry> getRestrictionAsEntries( TurnCostEncoder e
8381
iter = edgeOutExplorer.setBaseNode(viaNodeId);
8482
if (edgeIdFrom != EdgeIterator.NO_EDGE)
8583
{
86-
if (this.restriction == TYPE_NO_U_TURN || this.restriction == TYPE_NO_LEFT_TURN || this.restriction == TYPE_NO_RIGHT_TURN
87-
|| this.restriction == TYPE_NO_STRAIGHT_ON)
84+
if (this.restriction == TYPE_NO_U_TURN || this.restriction == TYPE_NO_LEFT_TURN
85+
|| this.restriction == TYPE_NO_RIGHT_TURN || this.restriction == TYPE_NO_STRAIGHT_ON)
8886
{
8987
// if we have a restriction of TYPE_NO_* we add restriction only to
9088
// the given turn (from, via, to)
@@ -122,14 +120,13 @@ public Collection<TurnCostTableEntry> getRestrictionAsEntries( TurnCostEncoder e
122120
}
123121
} catch (Exception e)
124122
{
125-
LoggerFactory.getLogger(OSMTurnRelation.class).warn(
126-
"Could not built node costs table for relation of node [osmId:" + this.viaOsm + "].", e);
123+
throw new IllegalStateException("Could not built node costs table for relation of node [osmId:" + this.viaOsm + "].", e);
127124
}
128125
return entries;
129126
}
130127

131128
/**
132-
* Helper class to processing porpuses only
129+
* Helper class to processing purposes only
133130
*/
134131
public static class TurnCostTableEntry
135132
{
@@ -143,13 +140,13 @@ public static class TurnCostTableEntry
143140
*/
144141
public long getItemId()
145142
{
146-
return ((long)edgeFrom) << 32 | ((long)edgeTo);
143+
return ((long) edgeFrom) << 32 | ((long) edgeTo);
147144
}
148145
}
149146

150147
/**
151-
* Creates an OSM turn relation out of an unspecified OSM relation
152-
*
148+
* Creates an OSM turn relation out of an unspecified OSM relation
149+
* <p>
153150
* @author karl.huebner
154151
*/
155152
static class FactoryEngine implements OSMRelationFactoryEngine<OSMTurnRelation>

core/src/main/java/com/graphhopper/routing/util/AbstractFlagEncoder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
package com.graphhopper.routing.util;
1919

20-
import java.util.ArrayList;
2120
import java.util.Collection;
2221
import java.util.HashSet;
2322

@@ -33,6 +32,7 @@
3332
import com.graphhopper.util.DistanceCalcEarth;
3433
import com.graphhopper.util.EdgeExplorer;
3534
import com.graphhopper.util.Helper;
35+
import java.util.Collections;
3636

3737
/**
3838
* Abstract class which handles flag decoding and encoding. Every encoder should be registered to a
@@ -520,7 +520,6 @@ public long getTurnFlags( boolean restricted, int costs )
520520

521521
public Collection<TurnCostTableEntry> analyzeTurnRelation( OSMTurnRelation turnRelation, OSMReader osmReader )
522522
{
523-
return new ArrayList<OSMTurnRelation.TurnCostTableEntry>();
523+
return Collections.emptyList();
524524
}
525-
526525
}

core/src/main/java/com/graphhopper/routing/util/EncodingManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
import java.util.Arrays;
2525
import java.util.Collection;
2626
import java.util.HashMap;
27-
import java.util.HashSet;
2827
import java.util.List;
2928
import java.util.Map;
30-
import java.util.Set;
3129

3230
import com.graphhopper.reader.OSMNode;
3331
import com.graphhopper.reader.OSMReader;
@@ -410,13 +408,15 @@ public Collection<TurnCostTableEntry> analyzeTurnRelation( OSMTurnRelation turnR
410408
for (TurnCostTableEntry entry : encoder.analyzeTurnRelation(turnRelation, osmReader))
411409
{
412410
TurnCostTableEntry oldEntry = entries.get(entry.getItemId());
413-
if(oldEntry != null){
411+
if (oldEntry != null)
412+
{
413+
// merging different encoders
414414
oldEntry.flags |= entry.flags;
415-
}else{
415+
} else
416+
{
416417
entries.put(entry.getItemId(), entry);
417418
}
418419
}
419-
420420
}
421421

422422
return entries.valueCollection();

core/src/main/java/com/graphhopper/util/InstructionList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public String toString()
252252
public List<GPXEntry> createGPXList()
253253
{
254254
if (isEmpty())
255-
return Collections.EMPTY_LIST;
255+
return Collections.emptyList();
256256

257257
List<GPXEntry> gpxList = new ArrayList<GPXEntry>();
258258
long timeOffset = 0;

core/src/test/java/com/graphhopper/reader/OSMReaderTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,8 @@ Collection<EdgeIteratorState> addOSMWay( TLongList osmNodeIds, long wayFlags, lo
630630
// reduced speed due to node tags
631631
increased.incrementAndGet();
632632
assertEquals(100 - 5, encoder.getSpeed(wayFlags));
633-
return Collections.EMPTY_SET;
633+
return Collections.emptyList();
634634
}
635-
636635
};
637636
osmreader.setEncodingManager(manager);
638637
// save some node tags for first node

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<version>3.1</version>
9090
<configuration>
9191
<!--
92-
<compilerArgument>-Xlint:unchecked</compilerArgument>
92+
<compilerArgument>-Xlint:unchecked</compilerArgument>
9393
-->
9494

9595
<source>1.6</source>

0 commit comments

Comments
 (0)