1 package org.opentrafficsim.core.perception.collections; 2 3 import java.util.LinkedHashMap; 4 import java.util.Map; 5 6 import org.djunits.value.vdouble.scalar.Time; 7 import org.opentrafficsim.core.perception.HistoryManager; 8 9 /** 10 * LinkedHashMap-valued historical state. The current linked hash map is always maintained, and past states of the linked hash 11 * map are obtained by applying the events between now and the requested time in reverse.<br> 12 * <br> 13 * The set views 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 3 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 */ 25 public class HistoricalLinkedHashMap<K, V> extends AbstractHistoricalMap<K, V, LinkedHashMap<K, V>> 26 { 27 28 /** 29 * Constructor. 30 * @param historyManager HistoryManager; history manager 31 */ 32 public HistoricalLinkedHashMap(final HistoryManager historyManager) 33 { 34 super(historyManager, new LinkedHashMap<>()); 35 } 36 37 /** 38 * Constructor. 39 * @param historyManager HistoryManager; history manager 40 * @param m Map<? extends K, ? extends V>; initial map 41 */ 42 public HistoricalLinkedHashMap(final HistoryManager historyManager, final Map<? extends K, ? extends V> m) 43 { 44 super(historyManager, new LinkedHashMap<>(m)); 45 } 46 47 /** {@inheritDoc} */ 48 @Override 49 public LinkedHashMap<K, V> get() 50 { 51 return getMap(); 52 } 53 54 /** {@inheritDoc} */ 55 @Override 56 public LinkedHashMap<K, V> get(final Time time) 57 { 58 if (isLastState(time)) 59 { 60 return getMap(); 61 } 62 return fill(time, new LinkedHashMap<>()); 63 } 64 65 /** {@inheritDoc} */ 66 @Override 67 public String toString() 68 { 69 return "HistoricalLinkedHashMap [current=" + getMap() + "]"; 70 } 71 72 }