HistoricalTreeSet.java

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

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

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

  6. /**
  7.  * TreeSet-valued historical state. The current tree set is always maintained, and past states of the tree set are obtained by
  8.  * applying the events between now and the requested time in reverse.<br>
  9.  * <br>
  10.  * The {@code Iterator} returned by this class does not support the {@code remove()} method. Any returned subset is
  11.  * unmodifiable.
  12.  * <p>
  13.  * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  14.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  15.  * <p>
  16.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 3 feb. 2018 <br>
  17.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  18.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  19.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  20.  * @param <E> element type
  21.  */
  22. public class HistoricalTreeSet<E> extends AbstractHistoricalNavigableSet<E, TreeSet<E>>
  23. {

  24.     /**
  25.      * Constructor.
  26.      * @param historyManager HistoryManager; history manager
  27.      */
  28.     public HistoricalTreeSet(final HistoryManager historyManager)
  29.     {
  30.         super(historyManager, new TreeSet<>());
  31.     }

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

  41.     /** {@inheritDoc} */
  42.     @Override
  43.     public TreeSet<E> get()
  44.     {
  45.         return getCollection();
  46.     }

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

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

  63. }