HistoricalVector.java

  1. package org.opentrafficsim.core.perception.collections;

  2. import java.util.Collection;
  3. import java.util.Vector;

  4. import org.djunits.value.vdouble.scalar.Time;
  5. import org.opentrafficsim.core.perception.HistoryManager;

  6. /**
  7.  * Vector-valued historical state. The current vector is always maintained, and past states of the vector are obtained by
  8.  * applying the events between now and the requested time in reverse.<br>
  9.  * <br>
  10.  * This class does not implement all {@code Vector} methods, but only those shared with {@code List}. The returned argument is
  11.  * however a {@code List}.<br>
  12.  * <br>
  13.  * The {@code Iterator} returned by this class does not support the {@code remove()}, {@code add()} and {@code set()} methods.
  14.  * Any returned sublist is unmodifiable.
  15.  * <p>
  16.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  17.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  18.  * </p>
  19.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  20.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  21.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  22.  * @param <E> element type
  23.  */
  24. public class HistoricalVector<E> extends AbstractHistoricalList<E, Vector<E>>
  25. {

  26.     /**
  27.      * Constructor.
  28.      * @param historyManager HistoryManager; history manager
  29.      */
  30.     public HistoricalVector(final HistoryManager historyManager)
  31.     {
  32.         super(historyManager, new Vector<>());
  33.     }

  34.     /**
  35.      * Constructor.
  36.      * @param historyManager HistoryManager; history manager
  37.      * @param c Collection&lt;? extends E&gt;; initial collection
  38.      */
  39.     public HistoricalVector(final HistoryManager historyManager, final Collection<? extends E> c)
  40.     {
  41.         super(historyManager, new Vector<>(c));
  42.     }

  43.     /** {@inheritDoc} */
  44.     @Override
  45.     public Vector<E> get()
  46.     {
  47.         return getCollection();
  48.     }

  49.     /** {@inheritDoc} */
  50.     @Override
  51.     public Vector<E> get(final Time time)
  52.     {
  53.         if (isLastState(time))
  54.         {
  55.             return getCollection();
  56.         }
  57.         return fill(time, new Vector<>());
  58.     }

  59.     /** {@inheritDoc} */
  60.     @Override
  61.     public String toString()
  62.     {
  63.         return "HistoricalVector [current=" + getCollection() + "]";
  64.     }

  65. }