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-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  14.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  15.  * </p>
  16.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  17.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  18.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  19.  * @param <E> element type
  20.  */
  21. public class HistoricalTreeSet<E> extends AbstractHistoricalNavigableSet<E, TreeSet<E>>
  22. {

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

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

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

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

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

  62. }