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 public class GraphCrossSection<S> extends AbstractGraphSpace<S>
26 {
27
28
29 private final Section<S> section;
30
31
32 private final List<Length> positions;
33
34
35
36
37
38
39
40 public GraphCrossSection(final String seriesName, final Section<S> section, final Length position)
41 {
42 this(new ArrayList<String>()
43 {
44
45 private static final long serialVersionUID = 20181022L;
46 {
47 add(seriesName);
48 }
49 }, section, new ArrayList<Length>()
50 {
51
52 private static final long serialVersionUID = 20181022L;
53 {
54 add(position);
55 }
56 });
57 }
58
59
60
61
62
63
64
65 public GraphCrossSection(final List<String> seriesNames, final Section<S> section, final List<Length> positions)
66 {
67 super(seriesNames);
68 this.section = section;
69 this.positions = positions;
70 }
71
72
73
74
75
76
77 public S getSource(final int series)
78 {
79 return this.section.getSource(series);
80 }
81
82
83 @Override
84 public Iterator<S> iterator(final int series)
85 {
86 List<S> list = new ArrayList<>();
87 list.add(this.section.getSource(series));
88 return new ImmutableArrayList<>(list, Immutable.WRAP).iterator();
89 }
90
91
92
93
94
95
96 public Length position(final int series)
97 {
98 return this.positions.get(series);
99 }
100
101
102 @Override
103 public Iterator<S> iterator()
104 {
105 return this.section.iterator();
106 }
107
108
109 @Override
110 public String toString()
111 {
112 return "GraphCrossSection [section=" + this.section + ", positions=" + this.positions + "]";
113 }
114
115 }