001/* *********************************************************************** * 002 * project: org.matsim.* 003 * ExperimentalTransitRoute.java 004 * * 005 * *********************************************************************** * 006 * * 007 * copyright : (C) 2009 by the members listed in the COPYING, * 008 * LICENSE and WARRANTY file. * 009 * email : info at matsim dot org * 010 * * 011 * *********************************************************************** * 012 * * 013 * This program is free software; you can redistribute it and/or modify * 014 * it under the terms of the GNU General Public License as published by * 015 * the Free Software Foundation; either version 2 of the License, or * 016 * (at your option) any later version. * 017 * See also COPYING, LICENSE and WARRANTY file * 018 * * 019 * *********************************************************************** */ 020 021package org.matsim.pt.routes; 022 023import org.matsim.api.core.v01.Id; 024import org.matsim.api.core.v01.network.Link; 025import org.matsim.core.population.routes.AbstractRoute; 026import org.matsim.core.utils.misc.OptionalTime; 027import org.matsim.pt.transitSchedule.api.TransitLine; 028import org.matsim.pt.transitSchedule.api.TransitRoute; 029import org.matsim.pt.transitSchedule.api.TransitStopFacility; 030 031@Deprecated 032public class ExperimentalTransitRoute extends AbstractRoute implements TransitPassengerRoute { 033 034 private final static String SEPARATOR = "==="; 035 private final static String IDENTIFIER_1 = "PT1" + SEPARATOR; 036 037 /* package */ final static String ROUTE_TYPE = "experimentalPt1"; 038 039 private Id<TransitStopFacility> accessStopId = null; 040 private Id<TransitStopFacility> egressStopId = null; 041 private Id<TransitLine> lineId = null; 042 private Id<TransitRoute> routeId = null; 043 private String description = null; 044 private String routeDescription; 045 046 /* package */ ExperimentalTransitRoute(final Id<Link> startLinkId, final Id<Link> endLinkId) { 047 super(startLinkId, endLinkId); 048 } 049 050 public ExperimentalTransitRoute(final TransitStopFacility accessFacility, final TransitStopFacility egressFacility, final Id<TransitLine> lineId, final Id<TransitRoute> routeId) { 051 this(accessFacility.getLinkId(), egressFacility.getLinkId()); 052 this.accessStopId = accessFacility.getId(); 053 this.lineId = lineId; 054 this.routeId = routeId; 055 this.egressStopId = egressFacility.getId(); 056 } 057 058 /** 059 * Why do we need this constructor, if we only keep the id of the line/route? 060 */ 061 public ExperimentalTransitRoute(final TransitStopFacility accessFacility, final TransitLine line, final TransitRoute route, final TransitStopFacility egressFacility) { 062 this(accessFacility, egressFacility, (line == null ? null : line.getId()), (route == null ? null : route.getId())); 063 } 064 065 @Override 066 public ExperimentalTransitRoute clone() { 067 return (ExperimentalTransitRoute) super.clone(); 068 } 069 070 public Id<TransitStopFacility> getAccessStopId() { 071 return this.accessStopId; 072 } 073 074 public Id<TransitStopFacility> getEgressStopId() { 075 return this.egressStopId; 076 } 077 078 public Id<TransitLine> getLineId() { 079 return this.lineId; 080 } 081 082 public Id<TransitRoute> getRouteId() { 083 return this.routeId; 084 } 085 086 @Override 087 public void setRouteDescription(final String routeDescription) { 088// super.setRouteDescription(routeDescription); 089 this.routeDescription = routeDescription; 090 if (routeDescription.startsWith(IDENTIFIER_1)) { 091 String[] parts = routeDescription.split(SEPARATOR, 6);// StringUtils.explode(routeDescription, '\t', 6); 092 this.accessStopId = Id.create(parts[1], TransitStopFacility.class); 093 this.lineId = Id.create(parts[2], TransitLine.class); 094 this.routeId = Id.create(parts[3], TransitRoute.class); 095 this.egressStopId = Id.create(parts[4], TransitStopFacility.class); 096 if (parts.length > 5) { 097 this.description = parts[5]; 098 } else { 099 this.description = null; 100 } 101 } else { 102 this.accessStopId = null; 103 this.lineId = null; 104 this.egressStopId = null; 105 } 106 } 107 108 @Override 109 public String getRouteDescription() { 110 if (this.accessStopId == null) { 111// return super.getRouteDescription(); 112 return this.routeDescription; 113 } 114 String str = IDENTIFIER_1 + this.accessStopId.toString() + SEPARATOR + this.lineId.toString() + SEPARATOR 115 + this.routeId.toString() + SEPARATOR + this.egressStopId.toString(); 116 if (this.description != null) { 117 str = str + SEPARATOR + this.description; 118 } 119 return str; 120 } 121 122 @Override 123 public String getRouteType() { 124 return ROUTE_TYPE; 125 } 126 127 @Override 128 public String toString() { 129 return "[ExpTransitRoute: access=" + this.accessStopId.toString() + " egress=" + this.egressStopId + " line=" 130 + this.lineId + " route=" + this.routeId + " ]"; 131 } 132 133 @Override 134 public OptionalTime getBoardingTime() { 135 return OptionalTime.undefined(); 136 } 137}