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 @Override
83 public Iterator<S> iterator(final int series)
84 {
85 List<S> list = new ArrayList<>();
86 list.add(this.section.getSource(series));
87 return new ImmutableArrayList<>(list, Immutable.WRAP).iterator();
88 }
89
90
91
92
93
94
95 public Length position(final int series)
96 {
97 return this.positions.get(series);
98 }
99
100 @Override
101 public Iterator<S> iterator()
102 {
103 return this.section.iterator();
104 }
105
106 @Override
107 public String toString()
108 {
109 return "GraphCrossSection [section=" + this.section + ", positions=" + this.positions + "]";
110 }
111
112 }