MATSIM
TimeTracker.java
Go to the documentation of this file.
1 package org.matsim.core.utils.timing;
2 
3 import java.util.List;
4 
9 
17 public class TimeTracker {
20 
21  public TimeTracker(TimeInterpretation timeInterpretation) {
22  this.timeInterpretation = timeInterpretation;
23  this.currentTime = OptionalTime.defined(timeInterpretation.getSimulationStartTime());
24  }
25 
26  public OptionalTime setTime(double time) {
27  currentTime = OptionalTime.defined(time);
28  return currentTime;
29  }
30 
31  public OptionalTime addDuration(double duration) {
32  if (currentTime.isUndefined()) {
33  throw new IllegalStateException("Cannot add element as current time is undefined");
34  }
35 
36  currentTime = OptionalTime.defined(currentTime.seconds() + duration);
37  return currentTime;
38  }
39 
40  public OptionalTime getTime() {
41  return currentTime;
42  }
43 
45  if (currentTime.isUndefined()) {
46  throw new IllegalStateException("Cannot add element as current time is undefined");
47  }
48 
49  currentTime = timeInterpretation.decideOnElementEndTime(element, currentTime.seconds());
50  return currentTime;
51  }
52 
53  public OptionalTime addElements(List<? extends PlanElement> elements) {
54  for (PlanElement element : elements) {
55  addElement(element);
56  }
57 
58  return currentTime;
59  }
60 
61  public OptionalTime addActivity(Activity activity) {
62  return addElement(activity);
63  }
64 
65  public OptionalTime addLeg(Leg leg) {
66  return addElement(leg);
67  }
68 }
OptionalTime setTime(double time)
OptionalTime addDuration(double duration)
TimeTracker(TimeInterpretation timeInterpretation)
static OptionalTime defined(double seconds)
OptionalTime decideOnElementEndTime(PlanElement element, double startTime)
final TimeInterpretation timeInterpretation
OptionalTime addActivity(Activity activity)
OptionalTime addElements(List<? extends PlanElement > elements)
OptionalTime addElement(PlanElement element)