1 package org.opentrafficsim.draw.graphs;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djutils.immutablecollections.Immutable;
9 import org.djutils.immutablecollections.ImmutableArrayList;
10 import org.opentrafficsim.draw.graphs.GraphPath.Section;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class GraphCrossSection<S> extends AbstractGraphSpace<S>
27 {
28
29
30 private final Section<S> section;
31
32
33 private final List<Length> positions;
34
35
36
37
38
39
40
41 public GraphCrossSection(final String seriesName, final Section<S> section, final Length position)
42 {
43 this(new ArrayList<String>()
44 {
45
46 private static final long serialVersionUID = 20181022L;
47 {
48 add(seriesName);
49 }
50 }, section, new ArrayList<Length>()
51 {
52
53 private static final long serialVersionUID = 20181022L;
54 {
55 add(position);
56 }
57 });
58 }
59
60
61
62
63
64
65
66 public GraphCrossSection(final List<String> seriesNames, final Section<S> section, final List<Length> positions)
67 {
68 super(seriesNames);
69 this.section = section;
70 this.positions = positions;
71 }
72
73
74
75
76
77
78 public S getSource(final int series)
79 {
80 return this.section.getSource(series);
81 }
82
83
84 @Override
85 public Iterator<S> iterator(final int series)
86 {
87 List<S> list = new ArrayList<>();
88 list.add(this.section.getSource(series));
89 return new ImmutableArrayList<>(list, Immutable.WRAP).iterator();
90 }
91
92
93
94
95
96
97 public Length position(final int series)
98 {
99 return this.positions.get(series);
100 }
101
102
103 @Override
104 public Iterator<S> iterator()
105 {
106 return this.section.iterator();
107 }
108
109
110 @Override
111 public String toString()
112 {
113 return "GraphCrossSection [section=" + this.section + ", positions=" + this.positions + "]";
114 }
115
116 }