29
29
import java .io .Closeable ;
30
30
import java .io .File ;
31
31
import java .util .ArrayList ;
32
- import java .util .Arrays ;
33
- import java .util .Collections ;
34
32
import java .util .List ;
35
33
36
34
import static com .graphhopper .routing .util .EncodingManager .getKey ;
@@ -137,7 +135,7 @@ public void testSetNodes() {
137
135
}
138
136
graph .edge (defaultSize + 1 , defaultSize + 2 , 10 , true );
139
137
graph .edge (defaultSize + 1 , defaultSize + 3 , 10 , true );
140
- assertEquals (2 , GHUtility . count ( carAllExplorer . setBaseNode ( defaultSize + 1 ) ));
138
+ assertEquals (2 , getCountAll ( defaultSize + 1 ));
141
139
}
142
140
143
141
@ Test
@@ -151,22 +149,22 @@ public void testPropertiesWithNoInit() {
151
149
public void testCreateLocation () {
152
150
graph = createGHStorage ();
153
151
graph .edge (3 , 1 , 50 , true );
154
- assertEquals (1 , count ( carOutExplorer . setBaseNode ( 1 ) ));
152
+ assertEquals (1 , getCountOut ( 1 ));
155
153
156
154
graph .edge (1 , 2 , 100 , true );
157
- assertEquals (2 , count ( carOutExplorer . setBaseNode ( 1 ) ));
155
+ assertEquals (2 , getCountOut ( 1 ));
158
156
}
159
157
160
158
@ Test
161
159
public void testEdges () {
162
160
graph = createGHStorage ();
163
161
graph .edge (2 , 1 , 12 , true );
164
- assertEquals (1 , count ( carOutExplorer . setBaseNode ( 2 ) ));
162
+ assertEquals (1 , getCountOut ( 2 ));
165
163
166
164
graph .edge (2 , 3 , 12 , true );
167
- assertEquals (1 , count ( carOutExplorer . setBaseNode ( 1 ) ));
168
- assertEquals (2 , count ( carOutExplorer . setBaseNode ( 2 ) ));
169
- assertEquals (1 , count ( carOutExplorer . setBaseNode ( 3 ) ));
165
+ assertEquals (1 , getCountOut ( 1 ));
166
+ assertEquals (2 , getCountOut ( 2 ));
167
+ assertEquals (1 , getCountOut ( 3 ));
170
168
}
171
169
172
170
@ Test
@@ -181,13 +179,13 @@ public void testUnidirectional() {
181
179
EdgeIterator i = carOutExplorer .setBaseNode (2 );
182
180
assertFalse (i .next ());
183
181
184
- assertEquals (1 , GHUtility . count ( carInExplorer . setBaseNode ( 1 ) ));
185
- assertEquals (2 , GHUtility . count ( carInExplorer . setBaseNode ( 2 ) ));
186
- assertEquals (0 , GHUtility . count ( carInExplorer . setBaseNode ( 3 ) ));
182
+ assertEquals (1 , getCountIn ( 1 ));
183
+ assertEquals (2 , getCountIn ( 2 ));
184
+ assertEquals (0 , getCountIn ( 3 ));
187
185
188
- assertEquals (3 , GHUtility . count ( carOutExplorer . setBaseNode ( 1 ) ));
189
- assertEquals (0 , GHUtility . count ( carOutExplorer . setBaseNode ( 2 ) ));
190
- assertEquals (1 , GHUtility . count ( carOutExplorer . setBaseNode ( 3 ) ));
186
+ assertEquals (3 , getCountOut ( 1 ));
187
+ assertEquals (0 , getCountOut ( 2 ));
188
+ assertEquals (1 , getCountOut ( 3 ));
191
189
i = carOutExplorer .setBaseNode (3 );
192
190
i .next ();
193
191
assertEquals (2 , i .getAdjNode ());
@@ -214,15 +212,15 @@ public void testUnidirectionalEdgeFilter() {
214
212
EdgeIterator i = carOutExplorer .setBaseNode (2 );
215
213
assertFalse (i .next ());
216
214
217
- assertEquals (4 , GHUtility . count ( carAllExplorer . setBaseNode ( 1 ) ));
215
+ assertEquals (4 , getCountAll ( 1 ));
218
216
219
- assertEquals (1 , GHUtility . count ( carInExplorer . setBaseNode ( 1 ) ));
220
- assertEquals (2 , GHUtility . count ( carInExplorer . setBaseNode ( 2 ) ));
221
- assertEquals (0 , GHUtility . count ( carInExplorer . setBaseNode ( 3 ) ));
217
+ assertEquals (1 , getCountIn ( 1 ));
218
+ assertEquals (2 , getCountIn ( 2 ));
219
+ assertEquals (0 , getCountIn ( 3 ));
222
220
223
- assertEquals (3 , GHUtility . count ( carOutExplorer . setBaseNode ( 1 ) ));
224
- assertEquals (0 , GHUtility . count ( carOutExplorer . setBaseNode ( 2 ) ));
225
- assertEquals (1 , GHUtility . count ( carOutExplorer . setBaseNode ( 3 ) ));
221
+ assertEquals (3 , getCountOut ( 1 ));
222
+ assertEquals (0 , getCountOut ( 2 ));
223
+ assertEquals (1 , getCountOut ( 3 ));
226
224
i = carOutExplorer .setBaseNode (3 );
227
225
i .next ();
228
226
assertEquals (2 , i .getAdjNode ());
@@ -273,7 +271,7 @@ public void testClone() {
273
271
274
272
Graph cloneGraph = graph .copyTo (AbstractGraphStorageTester .this .createGHStorage (locationParent + "/clone" , false ));
275
273
assertEquals (graph .getNodes (), cloneGraph .getNodes ());
276
- assertEquals (count ( carOutExplorer . setBaseNode ( 1 ) ), count (cloneGraph .createEdgeExplorer (carOutFilter ).setBaseNode (1 )));
274
+ assertEquals (getCountOut ( 1 ), count (cloneGraph .createEdgeExplorer (carOutFilter ).setBaseNode (1 )));
277
275
cloneGraph .edge (1 , 4 , 10 , true );
278
276
assertEquals (3 , count (cloneGraph .createEdgeExplorer (carOutFilter ).setBaseNode (1 )));
279
277
assertEquals (graph .getBounds (), cloneGraph .getBounds ());
@@ -306,7 +304,7 @@ public void testGetLocations() {
306
304
307
305
graph .edge (0 , 2 , 10 , true );
308
306
assertEquals (3 , graph .getNodes ());
309
- Helper .close (( Closeable ) graph );
307
+ Helper .close (graph );
310
308
311
309
graph = createGHStorage ();
312
310
assertEquals (0 , graph .getNodes ());
@@ -366,7 +364,7 @@ private void checkExampleGraph(Graph graph) {
366
364
assertEquals (GHUtility .asSet (0 ), GHUtility .getNeighbors (carOutExplorer .setBaseNode ((1 ))));
367
365
assertEquals (GHUtility .asSet (5 , 4 , 3 , 2 , 1 ), GHUtility .getNeighbors (carOutExplorer .setBaseNode (0 )));
368
366
try {
369
- assertEquals (0 , count ( carOutExplorer . setBaseNode ( 6 ) ));
367
+ assertEquals (0 , getCountOut ( 6 ));
370
368
// for now return empty iterator
371
369
// assertFalse(true);
372
370
} catch (Exception ex ) {
@@ -382,66 +380,67 @@ public void testDirectional() {
382
380
graph .edge (3 , 5 , 12 , true );
383
381
graph .edge (6 , 3 , 12 , false );
384
382
385
- assertEquals (1 , count ( carAllExplorer . setBaseNode ( 1 ) ));
386
- assertEquals (1 , count ( carInExplorer . setBaseNode ( 1 ) ));
387
- assertEquals (1 , count ( carOutExplorer . setBaseNode ( 1 ) ));
383
+ assertEquals (1 , getCountAll ( 1 ));
384
+ assertEquals (1 , getCountIn ( 1 ));
385
+ assertEquals (1 , getCountOut ( 1 ));
388
386
389
- assertEquals (2 , count ( carAllExplorer . setBaseNode ( 2 ) ));
390
- assertEquals (1 , count ( carInExplorer . setBaseNode ( 2 ) ));
391
- assertEquals (2 , count ( carOutExplorer . setBaseNode ( 2 ) ));
387
+ assertEquals (2 , getCountAll ( 2 ));
388
+ assertEquals (1 , getCountIn ( 2 ));
389
+ assertEquals (2 , getCountOut ( 2 ));
392
390
393
- assertEquals (4 , count ( carAllExplorer . setBaseNode ( 3 ) ));
394
- assertEquals (3 , count ( carInExplorer . setBaseNode ( 3 ) ));
395
- assertEquals (2 , count ( carOutExplorer . setBaseNode ( 3 ) ));
391
+ assertEquals (4 , getCountAll ( 3 ));
392
+ assertEquals (3 , getCountIn ( 3 ));
393
+ assertEquals (2 , getCountOut ( 3 ));
396
394
397
- assertEquals (1 , count ( carAllExplorer . setBaseNode ( 4 ) ));
398
- assertEquals (1 , count ( carInExplorer . setBaseNode ( 4 ) ));
399
- assertEquals (0 , count ( carOutExplorer . setBaseNode ( 4 ) ));
395
+ assertEquals (1 , getCountAll ( 4 ));
396
+ assertEquals (1 , getCountIn ( 4 ));
397
+ assertEquals (0 , getCountOut ( 4 ));
400
398
401
- assertEquals (1 , count ( carAllExplorer . setBaseNode ( 5 ) ));
402
- assertEquals (1 , count ( carInExplorer . setBaseNode ( 5 ) ));
403
- assertEquals (1 , count ( carOutExplorer . setBaseNode ( 5 ) ));
399
+ assertEquals (1 , getCountAll ( 5 ));
400
+ assertEquals (1 , getCountIn ( 5 ));
401
+ assertEquals (1 , getCountOut ( 5 ));
404
402
}
405
403
406
404
@ Test
407
405
public void testDozendEdges () {
408
406
graph = createGHStorage ();
409
407
graph .edge (1 , 2 , 12 , true );
410
- assertEquals (1 , count (carAllExplorer .setBaseNode (1 )));
408
+ int nn = 1 ;
409
+ assertEquals (1 , getCountAll (nn ));
411
410
412
411
graph .edge (1 , 3 , 13 , false );
413
- assertEquals (2 , count ( carAllExplorer . setBaseNode ( 1 ) ));
412
+ assertEquals (2 , getCountAll ( 1 ));
414
413
415
414
graph .edge (1 , 4 , 14 , false );
416
- assertEquals (3 , count ( carAllExplorer . setBaseNode ( 1 ) ));
415
+ assertEquals (3 , getCountAll ( 1 ));
417
416
418
417
graph .edge (1 , 5 , 15 , false );
419
- assertEquals (4 , count ( carAllExplorer . setBaseNode ( 1 ) ));
418
+ assertEquals (4 , getCountAll ( 1 ));
420
419
421
420
graph .edge (1 , 6 , 16 , false );
422
- assertEquals (5 , count ( carAllExplorer . setBaseNode ( 1 ) ));
421
+ assertEquals (5 , getCountAll ( 1 ));
423
422
424
423
graph .edge (1 , 7 , 16 , false );
425
- assertEquals (6 , count ( carAllExplorer . setBaseNode ( 1 ) ));
424
+ assertEquals (6 , getCountAll ( 1 ));
426
425
427
426
graph .edge (1 , 8 , 16 , false );
428
- assertEquals (7 , count ( carAllExplorer . setBaseNode ( 1 ) ));
427
+ assertEquals (7 , getCountAll ( 1 ));
429
428
430
429
graph .edge (1 , 9 , 16 , false );
431
- assertEquals (8 , count ( carAllExplorer . setBaseNode ( 1 ) ));
432
- assertEquals (8 , count ( carOutExplorer . setBaseNode ( 1 ) ));
430
+ assertEquals (8 , getCountAll ( 1 ));
431
+ assertEquals (8 , getCountOut ( 1 ));
433
432
434
- assertEquals (1 , count ( carInExplorer . setBaseNode ( 1 ) ));
435
- assertEquals (1 , count ( carInExplorer . setBaseNode ( 2 ) ));
433
+ assertEquals (1 , getCountIn ( 1 ));
434
+ assertEquals (1 , getCountIn ( 2 ));
436
435
}
437
436
438
437
@ Test
439
438
public void testCheckFirstNode () {
440
439
graph = createGHStorage ();
441
440
442
- assertEquals (0 , count ( carAllExplorer . setBaseNode ( 1 ) ));
441
+ assertEquals (0 , getCountAll ( 1 ));
443
442
graph .edge (0 , 1 , 12 , true );
444
- assertEquals (1 , count ( carAllExplorer . setBaseNode ( 1 ) ));
443
+ assertEquals (1 , getCountAll ( 1 ));
445
444
}
446
445
447
446
@ Test
@@ -462,17 +461,17 @@ public void testDeleteNodeForUnidir() {
462
461
graph .optimize ();
463
462
assertEquals (20 , graph .getNodes ());
464
463
465
- assertEquals (1 , GHUtility . count ( carInExplorer . setBaseNode ( getIdOf (graph , 20 ) )));
466
- assertEquals (0 , GHUtility . count ( carOutExplorer . setBaseNode ( getIdOf (graph , 20 ) )));
464
+ assertEquals (1 , getCountIn ( getIdOf (graph , 20 )));
465
+ assertEquals (0 , getCountOut ( getIdOf (graph , 20 )));
467
466
468
- assertEquals (1 , GHUtility . count ( carOutExplorer . setBaseNode ( getIdOf (graph , 10 ) )));
469
- assertEquals (0 , GHUtility . count ( carInExplorer . setBaseNode ( getIdOf (graph , 10 ) )));
467
+ assertEquals (1 , getCountOut ( getIdOf (graph , 10 )));
468
+ assertEquals (0 , getCountIn ( getIdOf (graph , 10 )));
470
469
471
- assertEquals (1 , GHUtility . count ( carInExplorer . setBaseNode ( getIdOf (graph , 6 ) )));
472
- assertEquals (0 , GHUtility . count ( carOutExplorer . setBaseNode ( getIdOf (graph , 6 ) )));
470
+ assertEquals (1 , getCountIn ( getIdOf (graph , 6 )));
471
+ assertEquals (0 , getCountOut ( getIdOf (graph , 6 )));
473
472
474
- assertEquals (1 , GHUtility . count ( carOutExplorer . setBaseNode ( getIdOf (graph , 21 ) )));
475
- assertEquals (0 , GHUtility . count ( carInExplorer . setBaseNode ( getIdOf (graph , 21 ) )));
473
+ assertEquals (1 , getCountOut ( getIdOf (graph , 21 )));
474
+ assertEquals (0 , getCountIn ( getIdOf (graph , 21 )));
476
475
}
477
476
478
477
@ Test
@@ -522,12 +521,12 @@ public void testDeleteNodes(int fillToSize) {
522
521
// no deletion happend
523
522
assertEquals (fillToSize , graph .getNodes ());
524
523
525
- assertEquals ( Collections .< String > emptyList (), GHUtility .getProblems (graph ));
524
+ assertTrue ( GHUtility .getProblems (graph ). isEmpty ( ));
526
525
527
526
// now actually perform deletion
528
527
graph .optimize ();
529
528
530
- assertEquals ( Collections .< String > emptyList (), GHUtility .getProblems (graph ));
529
+ assertTrue ( GHUtility .getProblems (graph ). isEmpty ( ));
531
530
532
531
assertEquals (fillToSize - deleted , graph .getNodes ());
533
532
int id1 = getIdOf (graph , 38.33f );
@@ -567,17 +566,17 @@ public void testSimpleDelete() {
567
566
graph .markNodeRemoved (3 );
568
567
569
568
assertEquals (6 , graph .getNodes ());
570
- assertEquals ( Collections .< String > emptyList (), GHUtility .getProblems (graph ));
569
+ assertTrue ( GHUtility .getProblems (graph ). isEmpty ( ));
571
570
572
571
// now actually perform deletion
573
572
graph .optimize ();
574
573
575
574
assertEquals (4 , graph .getNodes ());
576
- assertEquals ( Collections .< String > emptyList (), GHUtility .getProblems (graph ));
575
+ assertTrue ( GHUtility .getProblems (graph ). isEmpty ( ));
577
576
// shouldn't change anything
578
577
graph .optimize ();
579
578
assertEquals (4 , graph .getNodes ());
580
- assertEquals ( Collections .< String > emptyList (), GHUtility .getProblems (graph ));
579
+ assertTrue ( GHUtility .getProblems (graph ). isEmpty ( ));
581
580
}
582
581
583
582
@ Test
@@ -603,13 +602,13 @@ public void testSimpleDelete2() {
603
602
graph .edge (9 , 12 , 912 , true ).setWayGeometry (pl );
604
603
605
604
assertEquals (13 , graph .getNodes ());
606
- assertEquals ( Collections .< String > emptyList (), GHUtility .getProblems (graph ));
605
+ assertTrue ( GHUtility .getProblems (graph ). isEmpty ( ));
607
606
608
607
// perform deletion
609
608
graph .optimize ();
610
609
611
610
assertEquals (11 , graph .getNodes ());
612
- assertEquals ( Collections .< String > emptyList (), GHUtility .getProblems (graph ));
611
+ assertTrue ( GHUtility .getProblems (graph ). isEmpty ( ));
613
612
614
613
int id11 = getIdOf (graph , 11 ); // is now 10
615
614
int id12 = getIdOf (graph , 12 ); // is now 5
@@ -651,12 +650,12 @@ public void testSimpleDelete3() {
651
650
// perform deletion
652
651
graph .optimize ();
653
652
654
- assertEquals ( Arrays .< String > asList (), GHUtility .getProblems (graph ));
653
+ assertTrue ( GHUtility .getProblems (graph ). isEmpty ( ));
655
654
656
- assertEquals (3 , GHUtility . count ( carAllExplorer . setBaseNode ( getIdOf (graph , 9 ) )));
657
- assertEquals (1 , GHUtility . count ( carAllExplorer . setBaseNode ( getIdOf (graph , 7 ) )));
658
- assertEquals (1 , GHUtility . count ( carAllExplorer . setBaseNode ( getIdOf (graph , 8 ) )));
659
- assertEquals (1 , GHUtility . count ( carAllExplorer . setBaseNode ( getIdOf (graph , 11 ) )));
655
+ assertEquals (3 , getCountAll ( getIdOf (graph , 9 )));
656
+ assertEquals (1 , getCountAll ( getIdOf (graph , 7 )));
657
+ assertEquals (1 , getCountAll ( getIdOf (graph , 8 )));
658
+ assertEquals (1 , getCountAll ( getIdOf (graph , 11 )));
660
659
}
661
660
662
661
@ Test
@@ -759,7 +758,7 @@ public void testCreateDuplicateEdges() {
759
758
graph .edge (2 , 1 , 12 , true );
760
759
graph .edge (2 , 3 , 12 , true );
761
760
graph .edge (2 , 3 , 13 , false );
762
- assertEquals (3 , GHUtility . count ( carOutExplorer . setBaseNode ( 2 ) ));
761
+ assertEquals (3 , getCountOut ( 2 ));
763
762
764
763
// no exception
765
764
graph .getEdgeIteratorState (1 , 3 );
@@ -791,22 +790,22 @@ public void testCreateDuplicateEdges() {
791
790
assertTrue (oneIter .getReverse (carAccessEnc ));
792
791
793
792
graph .edge (3 , 2 , 14 , true );
794
- assertEquals (4 , GHUtility . count ( carOutExplorer . setBaseNode ( 2 ) ));
793
+ assertEquals (4 , getCountOut ( 2 ));
795
794
}
796
795
797
796
@ Test
798
797
public void testIdenticalNodes () {
799
798
graph = createGHStorage ();
800
799
graph .edge (0 , 0 , 100 , true );
801
- assertEquals (1 , GHUtility . count ( carAllExplorer . setBaseNode ( 0 ) ));
800
+ assertEquals (1 , getCountAll ( 0 ));
802
801
}
803
802
804
803
@ Test
805
804
public void testIdenticalNodes2 () {
806
805
graph = createGHStorage ();
807
806
graph .edge (0 , 0 , 100 , false );
808
807
graph .edge (0 , 0 , 100 , false );
809
- assertEquals (2 , GHUtility . count ( carAllExplorer . setBaseNode ( 0 ) ));
808
+ assertEquals (2 , getCountAll ( 0 ));
810
809
}
811
810
812
811
@ Test
@@ -1123,6 +1122,18 @@ public void testDetachEdge() {
1123
1122
assertEquals (edgeState20 .getFlags (), edgeState33 .detach (true ).getFlags ());
1124
1123
}
1125
1124
1125
+ private int getCountOut (int node ) {
1126
+ return GHUtility .count (carOutExplorer .setBaseNode (node ));
1127
+ }
1128
+
1129
+ private int getCountIn (int node ) {
1130
+ return GHUtility .count (carInExplorer .setBaseNode (node ));
1131
+ }
1132
+
1133
+ private int getCountAll (int node ) {
1134
+ return GHUtility .count (carAllExplorer .setBaseNode (node ));
1135
+ }
1136
+
1126
1137
static class TmpCarFlagEncoder extends CarFlagEncoder {
1127
1138
public TmpCarFlagEncoder (int speedBits , double speedFactor , int maxTurnCosts ) {
1128
1139
super (speedBits , speedFactor , maxTurnCosts );
0 commit comments