View Javadoc
1   package org.opentrafficsim.core.perception.collections;
2   
3   import java.util.Collections;
4   import java.util.Comparator;
5   import java.util.SortedSet;
6   
7   import org.opentrafficsim.core.perception.HistoryManager;
8   
9   /**
10   * SortedSet-valued historical state. The current sorted set is always maintained, and past states of the sorted set 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()} method. Any returned subset is
14   * 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 2 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   * @param <S> sorted set type
25   */
26  public abstract class AbstractHistoricalSortedSet<E, S extends SortedSet<E>> extends AbstractHistoricalCollection<E, S>
27          implements HistoricalSortedSet<E>
28  {
29  
30      /**
31       * Constructor.
32       * @param historyManager HistoryManager; history manager
33       * @param set S; initial set
34       */
35      protected AbstractHistoricalSortedSet(final HistoryManager historyManager, final S set)
36      {
37          super(historyManager, set);
38      }
39  
40      // Non-altering SortedSet methods
41  
42      /** {@inheritDoc} */
43      @Override
44      public Comparator<? super E> comparator()
45      {
46          return getCollection().comparator();
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public SortedSet<E> subSet(final E fromElement, final E toElement)
52      {
53          return Collections.unmodifiableSortedSet(getCollection().subSet(fromElement, toElement));
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public SortedSet<E> headSet(final E toElement)
59      {
60          return Collections.unmodifiableSortedSet(getCollection().headSet(toElement));
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public SortedSet<E> tailSet(final E fromElement)
66      {
67          return Collections.unmodifiableSortedSet(getCollection().tailSet(fromElement));
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public E first()
73      {
74          return getCollection().first();
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public E last()
80      {
81          return getCollection().last();
82      }
83  
84  }