AbstractGraphSpace.java

  1. package org.opentrafficsim.draw.graphs;

  2. import java.util.Iterator;
  3. import java.util.List;

  4. /**
  5.  * Common functionality between a cross-section and a path.
  6.  * <p>
  7.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  8.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  9.  * <p>
  10.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 23 okt. 2018 <br>
  11.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  12.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  13.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  14.  * @param <S> underlying type of path sections
  15.  */
  16. public abstract class AbstractGraphSpace<S> implements Iterable<S>
  17. {

  18.     /** Series names. */
  19.     private final List<String> seriesNames;

  20.     /**
  21.      * Constructor.
  22.      * @param seriesNames List&lt;String&gt;; names of series
  23.      */
  24.     public AbstractGraphSpace(final List<String> seriesNames)
  25.     {
  26.         this.seriesNames = seriesNames;
  27.     }

  28.     /**
  29.      * Returns the name of the series.
  30.      * @param series int; series
  31.      * @return String; name of the series
  32.      */
  33.     public final String getName(final int series)
  34.     {
  35.         return this.seriesNames.get(series);
  36.     }

  37.     /**
  38.      * Returns the number of series.
  39.      * @return int; number of series
  40.      */
  41.     public final int getNumberOfSeries()
  42.     {
  43.         return this.seriesNames.size();
  44.     }

  45.     /**
  46.      * Returns an iterator over the sources on the given series.
  47.      * @param series int; number of the series
  48.      * @return Iterator&lt;S&gt;; iterator over the sources on the given series
  49.      */
  50.     abstract Iterator<S> iterator(int series);

  51. }