6
6
import com .graphhopper .routing .util .TransportationMode ;
7
7
import org .junit .jupiter .api .Test ;
8
8
9
- import java .util .Arrays ;
10
- import java .util .HashMap ;
11
- import java .util .List ;
12
- import java .util .Map ;
9
+ import java .util .*;
13
10
14
11
import static org .junit .jupiter .api .Assertions .assertFalse ;
15
12
import static org .junit .jupiter .api .Assertions .assertTrue ;
16
13
17
14
class ModeAccessParserTest {
18
15
19
16
private final EncodingManager em = new EncodingManager .Builder ().add (Roundabout .create ()).add (BusAccess .create ()).build ();
20
- private final ModeAccessParser parser = new ModeAccessParser (TransportationMode .BUS , em .getBooleanEncodedValue (BusAccess .KEY ), em .getBooleanEncodedValue (Roundabout .KEY ), List .of ());
17
+ private final ModeAccessParser parser = new ModeAccessParser (TransportationMode .BUS ,
18
+ em .getBooleanEncodedValue (BusAccess .KEY ), true ,
19
+ em .getBooleanEncodedValue (Roundabout .KEY ), Set .of (), Set .of ());
21
20
private final BooleanEncodedValue busAccessEnc = em .getBooleanEncodedValue (BusAccess .KEY );
22
21
23
22
@ Test
@@ -140,33 +139,58 @@ public void testBusNodeAccess() {
140
139
way .setTag ("highway" , "secondary" );
141
140
way .setTag ("gh:barrier_edge" , true );
142
141
143
- Map <String , Object > nodeTags = new HashMap <>();
144
- nodeTags .put ("access" , "no" );
145
- nodeTags .put ("bus" , "yes" );
146
- way .setTag ("node_tags" , Arrays .asList (nodeTags , new HashMap <>()));
142
+ way .setTag ("node_tags" , List .of (Map .of ("access" , "no" , "bus" , "yes" ), Map .of ()));
147
143
EdgeIntAccess access = new ArrayEdgeIntAccess (1 );
148
144
int edgeId = 0 ;
149
145
parser .handleWayTags (edgeId , access , way , null );
150
146
assertTrue (busAccessEnc .getBool (false , edgeId , access ));
151
147
152
- nodeTags = new HashMap <>();
153
- nodeTags .put ("access" , "yes" );
154
- nodeTags .put ("bus" , "no" );
155
- way .setTag ("node_tags" , Arrays .asList (nodeTags ));
148
+ way .setTag ("node_tags" , List .of (Map .of ("access" , "yes" , "bus" , "no" )));
156
149
access = new ArrayEdgeIntAccess (1 );
157
150
parser .handleWayTags (edgeId , access , way , null );
158
151
assertFalse (busAccessEnc .getBool (false , edgeId , access ));
159
152
160
153
// ensure that allowing node tags (bus=yes) do not unblock the inaccessible way
161
154
way .setTag ("access" , "no" );
162
- nodeTags = new HashMap <>();
163
- nodeTags .put ("bus" , "yes" );
164
- way .setTag ("node_tags" , Arrays .asList (nodeTags , new HashMap <>()));
155
+ way .setTag ("node_tags" , List .of (Map .of ("bus" , "yes" ), Map .of ()));
165
156
access = new ArrayEdgeIntAccess (1 );
166
157
parser .handleWayTags (edgeId , access , way , null );
167
158
assertFalse (busAccessEnc .getBool (false , edgeId , access ));
168
159
}
169
160
161
+ @ Test
162
+ public void testBarrier () {
163
+ ReaderWay way = new ReaderWay (1 );
164
+ way .setTag ("highway" , "secondary" );
165
+ way .setTag ("gh:barrier_edge" , true );
166
+
167
+ way .setTag ("node_tags" , Arrays .asList (Map .of ("barrier" , "bollard" ), Map .of ()));
168
+ EdgeIntAccess access = new ArrayEdgeIntAccess (1 );
169
+ int edgeId = 0 ;
170
+ parser .handleWayTags (edgeId , access , way , null );
171
+ assertFalse (busAccessEnc .getBool (false , edgeId , access ));
172
+
173
+ way .setTag ("node_tags" , Arrays .asList (Map .of ("barrier" , "gate" ), Map .of ()));
174
+ access = new ArrayEdgeIntAccess (1 );
175
+ parser .handleWayTags (edgeId , access , way , null );
176
+ assertTrue (busAccessEnc .getBool (false , edgeId , access ));
177
+
178
+ // this special mode ignores all barriers except kissing_gate
179
+ BooleanEncodedValue tmpAccessEnc = new SimpleBooleanEncodedValue ("tmp_access" , true );
180
+ EncodingManager tmpEM = new EncodingManager .Builder ().add (tmpAccessEnc ).add (Roundabout .create ()).build ();
181
+ ModeAccessParser tmpParser = new ModeAccessParser (TransportationMode .CAR , tmpAccessEnc , true ,
182
+ tmpEM .getBooleanEncodedValue (Roundabout .KEY ), Set .of (), Set .of ("kissing_gate" ));
183
+
184
+ way = new ReaderWay (1 );
185
+ way .setTag ("highway" , "secondary" );
186
+ way .setTag ("gh:barrier_edge" , true );
187
+
188
+ way .setTag ("node_tags" , List .of (Map .of ("barrier" , "bollard" ), Map .of ()));
189
+ access = new ArrayEdgeIntAccess (1 );
190
+ tmpParser .handleWayTags (edgeId , access , way , null );
191
+ assertTrue (tmpAccessEnc .getBool (false , edgeId , access ));
192
+ }
193
+
170
194
@ Test
171
195
public void testPsvYes () {
172
196
EdgeIntAccess access = new ArrayEdgeIntAccess (1 );
@@ -192,7 +216,8 @@ public void testPsvYes() {
192
216
public void testMotorcycleYes () {
193
217
BooleanEncodedValue mcAccessEnc = new SimpleBooleanEncodedValue ("motorcycle_access" , true );
194
218
EncodingManager mcEM = new EncodingManager .Builder ().add (mcAccessEnc ).add (Roundabout .create ()).build ();
195
- ModeAccessParser mcParser = new ModeAccessParser (TransportationMode .MOTORCYCLE , mcAccessEnc , mcEM .getBooleanEncodedValue (Roundabout .KEY ), List .of ());
219
+ ModeAccessParser mcParser = new ModeAccessParser (TransportationMode .MOTORCYCLE , mcAccessEnc , true ,
220
+ mcEM .getBooleanEncodedValue (Roundabout .KEY ), Set .of (), Set .of ());
196
221
197
222
int edgeId = 0 ;
198
223
EdgeIntAccess access = new ArrayEdgeIntAccess (1 );
0 commit comments