MATSIM
MainModeIdentifierImpl.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2013 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 
20 package org.matsim.core.router;
21 
22 import java.util.List;
23 
27 
31 public final class MainModeIdentifierImpl implements MainModeIdentifier {
32  @Override
33  public String identifyMainMode( final List<? extends PlanElement> tripElements) {
34  String mode = ((Leg) tripElements.get( 0 )).getMode();
35 // return mode.equals( TransportMode.transit_walk ) ? TransportMode.pt : mode;
36  if ( mode.equals( TransportMode.transit_walk ) ) {
37  return TransportMode.pt ;
38 
39  // (yy not conforming to std transport planning since that would look for mode with the highest "weight"
40  // in the whole trip, but it is what I found and at least one test depends on it. kai, feb'16)
41 
42  // Marcel's SBB raptor returns access/egress_walk to and from pt, and transit_walk only
43  // for direct walk (and presumably in between pt legs, if necessary). kai/gregor, sep'18
44  }
45  if ( mode.endsWith( "_fallback" ) ) {
46  return mode.substring(0, mode.length() - 9) ;
47  }
48 
49  for ( PlanElement pe : tripElements ) {
50  if ( pe instanceof Leg ) {
51  Leg leg = (Leg) pe ;
52  String mode2 = leg.getMode() ;
53  if ( !mode2.contains( TransportMode.non_network_walk ) &&
54  !mode2.contains( TransportMode.transit_walk ) ) {
55  return mode2 ;
56  }
57  }
58  }
59 
60  throw new RuntimeException( "could not identify main mode "+ tripElements) ;
61 
62  }
63 }
String identifyMainMode(final List<? extends PlanElement > tripElements)