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