View Javadoc
1   package org.opentrafficsim.kpi.sampling.indicator;
2   
3   import java.util.List;
4   
5   import org.djunits.value.vdouble.scalar.Length;
6   import org.djunits.value.vdouble.scalar.Time;
7   import org.opentrafficsim.kpi.interfaces.GtuDataInterface;
8   import org.opentrafficsim.kpi.sampling.Query;
9   import org.opentrafficsim.kpi.sampling.Trajectory;
10  import org.opentrafficsim.kpi.sampling.TrajectoryGroup;
11  
12  /**
13   * Sum of trajectory lengths.
14   * <p>
15   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision$, $LastChangedDate$, by $Author$, initial version Sep 22, 2016 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
22   */
23  public class TotalTravelDistance extends AbstractIndicator<Length>
24  {
25  
26      /** {@inheritDoc} */
27      @Override
28      protected <G extends GtuDataInterface> Length calculate(final Query<G> query, final Time startTime, final Time endTime,
29              final List<TrajectoryGroup<G>> trajectoryGroups)
30      {
31          Length sum = Length.ZERO;
32          for (TrajectoryGroup<?> trajectoryGroup : trajectoryGroups)
33          {
34              for (Trajectory<?> trajectory : trajectoryGroup.getTrajectories())
35              {
36                  sum = sum.plus(trajectory.getTotalLength());
37              }
38          }
39          return sum;
40      }
41  
42      @SuppressWarnings("checkstyle:designforextension")
43      /** {@inheritDoc} */
44      @Override
45      public String toString()
46      {
47          return "TotalTravelDistance []";
48      }
49  
50  }