package org.opentrafficsim.draw.graphs; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.djunits.value.vdouble.scalar.Length; import org.djutils.immutablecollections.Immutable; import org.djutils.immutablecollections.ImmutableArrayList; import org.opentrafficsim.draw.graphs.GraphPath.Section; /** * A {@code GraphCrossSection} defines the location of graphs. It has one section having one or more source objects depending on * the number of series. For example, a 3-lane road may result in a section with 3 series. Graphs can aggregate the series, or * show multiple series. *

* Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* @version $Revision$, $LastChangedDate$, by $Author$, initial version 22 okt. 2018
* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel * @param underlying type of path sections */ public class GraphCrossSection extends AbstractGraphSpace { /** Section. */ private final Section section; /** Position on the section. */ private final List positions; /** * Constructor for a one-series cross section. * @param seriesName String; name of series * @param section Section<S>; section * @param position Length; position on the section */ public GraphCrossSection(final String seriesName, final Section section, final Length position) { this(new ArrayList() { /** */ private static final long serialVersionUID = 20181022L; { add(seriesName); } }, section, new ArrayList() { /** */ private static final long serialVersionUID = 20181022L; { add(position); } }); } /** * Constructor. * @param seriesNames List<String>; names of series * @param section Section<S>; section * @param positions List<Length>; position on the section */ public GraphCrossSection(final List seriesNames, final Section section, final List positions) { super(seriesNames); this.section = section; this.positions = positions; } /** * Returns the underlying source of the series. * @param series int; series number * @return S; underlying source of the series */ public S getSource(final int series) { return this.section.getSource(series); } /** {@inheritDoc} */ @Override public Iterator iterator(final int series) { List list = new ArrayList<>(); list.add(this.section.getSource(series)); return new ImmutableArrayList<>(list, Immutable.WRAP).iterator(); } /** * Returns the position on the underlying source of the series. * @param series int; series number * @return Length; position on the underlying source of the series */ public Length position(final int series) { return this.positions.get(series); } /** {@inheritDoc} */ @Override public Iterator iterator() { return this.section.iterator(); } /** {@inheritDoc} */ @Override public String toString() { return "GraphCrossSection [section=" + this.section + ", positions=" + this.positions + "]"; } }