/**
* Copyright (C) 2011 Brian Ferris <bdferris@onebusaway.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onebusaway.transit_data_federation.impl.otp.graph;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import org.onebusaway.gtfs.model.AgencyAndId;
import org.onebusaway.transit_data_federation.impl.otp.GraphContext;
import org.onebusaway.transit_data_federation.services.transit_graph.StopEntry;
import org.opentripplanner.routing.core.Edge;
import org.opentripplanner.routing.core.HasEdges;
import org.opentripplanner.routing.core.Vertex;
public final class ArrivalVertex extends AbstractVertexWithEdges implements
HasStopTransitVertex {
private static DateFormat _format = DateFormat.getDateTimeInstance(
DateFormat.SHORT, DateFormat.SHORT);
private final StopEntry _stop;
private final long _time;
public ArrivalVertex(GraphContext context, StopEntry stop, long time) {
super(context);
_stop = stop;
_time = time;
}
@Override
public StopEntry getStop() {
return _stop;
}
/****
* {@link Vertex} Interface
****/
@Override
public String getLabel() {
return "stop_arrival_" + getStopId() + "_wait_" + _time;
}
@Override
public AgencyAndId getStopId() {
return _stop.getId();
}
@Override
public double getX() {
return _stop.getStopLon();
}
@Override
public double getY() {
return _stop.getStopLat();
}
/****
* {@link HasEdges} Interface
****/
@Override
public Collection<Edge> getIncoming() {
List<Edge> edges = new ArrayList<Edge>(1);
// We could come from a different bus (arrival)
edges.add(new ArrivalReverseEdge(_context, _stop));
return edges;
}
@Override
public Collection<Edge> getOutgoing() {
List<Edge> edges = new ArrayList<Edge>(1);
// We stop waiting and move back to the street
edges.add(new WaitingEndsAtStopEdge(_context, _stop, false));
return edges;
}
/****
* {@link Object} Interface
****/
@Override
public String toString() {
return "ArrivalVertex(stop=" + _stop.getId() + " time="
+ _format.format(new Date(_time)) + ")";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((_stop == null) ? 0 : _stop.hashCode());
result = prime * result + (int) (_time ^ (_time >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ArrivalVertex other = (ArrivalVertex) obj;
return _stop.equals(other._stop) && _time == other._time;
}
}