1 package org.opentrafficsim.road.gtu.perception.mental.sdm;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.djunits.value.vdouble.scalar.Duration;
7 import org.djunits.value.vdouble.scalar.Frequency;
8
9 import nl.tudelft.simulation.jstats.streams.StreamInterface;
10
11 /**
12 * Utility to create a list of default distractions as derived by the research of Manuel Lindorfer.
13 * <p>
14 * Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16 * </p>
17 * @author Alexander Verbraeck
18 * @author Peter Knoppers
19 * @author Wouter Schakel
20 */
21 public class DistractionFactory
22 {
23
24 /** Random number stream. */
25 private final StreamInterface stream;
26
27 /** List of distractions. */
28 private List<Distraction> list = new ArrayList<>();
29
30 /**
31 * Constructor.
32 * @param stream random number stream
33 */
34 public DistractionFactory(final StreamInterface stream)
35 {
36 this.stream = stream;
37 }
38
39 /**
40 * Adds a default distraction.
41 * @param defaultDistraction default distraction
42 * @param taskDemand task demand
43 * @return this factory for method chaining
44 */
45 public DistractionFactory addDistraction(final DefaultDistraction defaultDistraction, final double taskDemand)
46 {
47 return addDistraction(defaultDistraction.getId(), defaultDistraction.getDescription(),
48 defaultDistraction.getFrequency(), defaultDistraction.getExposure(), defaultDistraction.getAverageDuration(),
49 defaultDistraction.getStdDuration(), taskDemand);
50 }
51
52 /**
53 * Helper method to create a distraction.
54 * @param id id
55 * @param description description
56 * @param frequency frequency per exposed driver
57 * @param exposure exposure (value in range [0...1])
58 * @param averageDuration average duration
59 * @param stdDuration standard deviation of duration
60 * @param taskDemand task demand
61 * @return this factory for method chaining
62 */
63 public DistractionFactory addDistraction(final String id, final String description, final Frequency frequency,
64 final double exposure, final Duration averageDuration, final Duration stdDuration, final double taskDemand)
65 {
66 this.list.add(
67 new Distraction(id, description, frequency, exposure, averageDuration, stdDuration, taskDemand, this.stream));
68 return this;
69 }
70
71 /**
72 * Returns the list of distractions.
73 * @return list of distractions
74 */
75 public List<Distraction> build()
76 {
77 return this.list;
78 }
79
80 }