View Javadoc
1   package org.opentrafficsim.core.perception.collections;
2   
3   import java.util.Collection;
4   import java.util.Vector;
5   
6   import org.djunits.value.vdouble.scalar.Time;
7   import org.opentrafficsim.core.perception.HistoryManager;
8   
9   /**
10   * Vector-valued historical state. The current vector is always maintained, and past states of the vector are obtained by
11   * applying the events between now and the requested time in reverse.<br>
12   * <br>
13   * This class does not implement all {@code Vector} methods, but only those shared with {@code List}. The returned argument is
14   * however a {@code List}.<br>
15   * <br>
16   * The {@code Iterator} returned by this class does not support the {@code remove()}, {@code add()} and {@code set()} methods.
17   * Any returned sublist is unmodifiable.
18   * <p>
19   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
21   * <p>
22   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 3 feb. 2018 <br>
23   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
25   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
26   * @param <E> element type
27   */
28  public class HistoricalVector<E> extends AbstractHistoricalList<E, Vector<E>>
29  {
30  
31      /**
32       * Constructor.
33       * @param historyManager HistoryManager; history manager
34       */
35      public HistoricalVector(final HistoryManager historyManager)
36      {
37          super(historyManager, new Vector<>());
38      }
39  
40      /**
41       * Constructor.
42       * @param historyManager HistoryManager; history manager
43       * @param c Collection&lt;? extends E&gt;; initial collection
44       */
45      public HistoricalVector(final HistoryManager historyManager, final Collection<? extends E> c)
46      {
47          super(historyManager, new Vector<>(c));
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      public Vector<E> get()
53      {
54          return getCollection();
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public Vector<E> get(final Time time)
60      {
61          if (isLastState(time))
62          {
63              return getCollection();
64          }
65          return fill(time, new Vector<>());
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public String toString()
71      {
72          return "HistoricalVector [current=" + getCollection() + "]";
73      }
74  
75  }