View Javadoc
1   package org.opentrafficsim.core.perception.collections;
2   
3   import java.util.Collections;
4   import java.util.Comparator;
5   import java.util.SortedMap;
6   
7   import org.opentrafficsim.core.perception.HistoryManager;
8   
9   /**
10   * SortedMap-valued historical state. The current sorted map is always maintained, and past states of the sorted map are
11   * obtained by applying the events between now and the requested time in reverse.<br>
12   * <br>
13   * The set views and sub-maps returned by this class are unmodifiable.
14   * <p>
15   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 2 feb. 2018 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
22   * @param <K> key type
23   * @param <V> value type
24   * @param <M> sorted map type
25   */
26  public abstract class AbstractHistoricalSortedMap<K, V, M extends SortedMap<K, V>> extends AbstractHistoricalMap<K, V, M>
27          implements HistoricalSortedMap<K, V>
28  {
29  
30      /**
31       * Constructor.
32       * @param historyManager HistoryManager; history manager
33       * @param map M; initial map
34       */
35      protected AbstractHistoricalSortedMap(final HistoryManager historyManager, final M map)
36      {
37          super(historyManager, map);
38      }
39  
40      // Non-altering SortedMap methods
41  
42      /** {@inheritDoc} */
43      @Override
44      public Comparator<? super K> comparator()
45      {
46          return getMap().comparator();
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public SortedMap<K, V> subMap(final K fromKey, final K toKey)
52      {
53          return Collections.unmodifiableSortedMap(getMap().subMap(fromKey, toKey));
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public SortedMap<K, V> headMap(final K toKey)
59      {
60          return Collections.unmodifiableSortedMap(getMap().headMap(toKey));
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public SortedMap<K, V> tailMap(final K fromKey)
66      {
67          return Collections.unmodifiableSortedMap(getMap().tailMap(fromKey));
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public K firstKey()
73      {
74          return getMap().firstKey();
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public K lastKey()
80      {
81          return getMap().lastKey();
82      }
83  
84  }