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