package org.opentrafficsim.road.gtu.lane.perception; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; import java.util.SortedSet; import org.opentrafficsim.road.gtu.lane.perception.headway.Headway; /** * Simple implementation of {@code PerceptionIterable} which wraps a set. Constructors are available for an empty set, a * single-valued set, or a sorted set. *

* Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License. *

* @version $Revision$, $LastChangedDate$, by $Author$, initial version 26 feb. 2018
* @author Alexander Verbraeck * @author Peter Knoppers * @author Wouter Schakel * @param headway type */ public class PerceptionIterableSet implements PerceptionIterable { /** Internal set. */ private Set set; /** * Creates an empty iterable. */ public PerceptionIterableSet() { this.set = new LinkedHashSet<>(); } /** * Creates a single-value iterable. * @param headway H; headway */ public PerceptionIterableSet(final H headway) { this.set = new LinkedHashSet<>(); this.set.add(headway); } /** * Creates an iterable from a sorted set. * @param headways SortedSet<H>; set of headway */ public PerceptionIterableSet(final SortedSet headways) { this.set = headways; } /** {@inheritDoc} */ @Override public Iterator iterator() { return this.set.iterator(); } /** {@inheritDoc} */ @Override public H first() { return this.set.iterator().next(); } /** {@inheritDoc} */ @Override public boolean isEmpty() { return this.set.isEmpty(); } }