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