1 package org.opentrafficsim.kpi.sampling;
2
3 import java.io.Serializable;
4 import java.util.HashSet;
5 import java.util.Iterator;
6 import java.util.Set;
7
8 import org.opentrafficsim.base.immutablecollections.ImmutableIterator;
9 import org.opentrafficsim.kpi.interfaces.LaneDataInterface;
10 import org.opentrafficsim.kpi.interfaces.LinkDataInterface;
11
12 import nl.tudelft.simulation.language.Throw;
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class CrossSection implements Serializable
27 {
28
29
30 private static final long serialVersionUID = 20160929L;
31
32
33 private final Set<KpiDirectedLanePosition> directedLanePositions;
34
35
36
37
38
39 public CrossSection(final Set<KpiDirectedLanePosition> directedLanePositions)
40 {
41 Throw.whenNull(directedLanePositions, "Directed lane positions may not be null.");
42 this.directedLanePositions = new HashSet<>(directedLanePositions);
43 }
44
45
46
47
48
49
50
51
52 public CrossSection(final LinkDataInterface link, final KpiGtuDirectionality direction, final double fraction) throws SamplingException
53 {
54 Throw.whenNull(link, "Link lane positions may not be null.");
55 Throw.whenNull(direction, "Direction may not be null.");
56 this.directedLanePositions = new HashSet<>();
57 for (LaneDataInterface lane : link.getLaneDatas())
58 {
59 KpiDirectedLanePosition directedLanePosition =
60 new KpiDirectedLanePosition(lane, lane.getLength().multiplyBy(fraction), direction);
61 this.directedLanePositions.add(directedLanePosition);
62 }
63 }
64
65
66
67
68 public final int size()
69 {
70 return this.directedLanePositions.size();
71 }
72
73
74
75
76 public final Set<KpiDirectedLanePosition> getDirectedLanePositions()
77 {
78 return new HashSet<>(this.directedLanePositions);
79 }
80
81
82
83
84 public final Iterator<KpiDirectedLanePosition> getIterator()
85 {
86 return new ImmutableIterator<>(this.directedLanePositions.iterator());
87 }
88
89
90 @Override
91 @SuppressWarnings("checkstyle:designforextension")
92 public String toString()
93 {
94 return "CrossSection [directedLanePositions=" + this.directedLanePositions + "]";
95 }
96
97 }