Class AbstractPerceptionReiterable<H extends Headway,​U>

  • Type Parameters:
    H - headway type
    U - underlying object type
    All Implemented Interfaces:
    Iterable<H>, PerceptionCollectable<H,​U>, PerceptionIterable<H>
    Direct Known Subclasses:
    AbstractPerceptionIterable, MultiLanePerceptionIterable

    public abstract class AbstractPerceptionReiterable<H extends Headway,​U>
    extends Object
    implements PerceptionCollectable<H,​U>
    This class uses a single primary iterator which a subclass defines, and makes sure that all elements are only looked up and created once. It does so by storing the elements in a linked list. All calls to iterator() return an iterator which iterates over the linked list. If an iterator runs to the end of the linked list, the primary iterator is requested to add an element if it has one.

    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 20 feb. 2018
    Author:
    Alexander Verbraeck, Peter Knoppers, Wouter Schakel
    • Constructor Detail

      • AbstractPerceptionReiterable

        protected AbstractPerceptionReiterable​(LaneBasedGTU perceivingGtu)
        Constructor.
        Parameters:
        perceivingGtu - LaneBasedGTU; perceiving GTU
    • Method Detail

      • getGtu

        protected LaneBasedGTU getGtu()
        Returns the GTU.
        Returns:
        LaneBasedGTU; GTU
      • perceive

        protected abstract H perceive​(LaneBasedGTU perceivingGtu,
                                      U object,
                                      Length distance)
                               throws GTUException,
                                      org.opentrafficsim.base.parameters.ParameterException
        Returns a perceived version of the underlying object.
        Parameters:
        perceivingGtu - LaneBasedGTU; perceiving GTU
        object - U; underlying object
        distance - Length; distance to the object
        Returns:
        H; perceived version of the underlying object
        Throws:
        GTUException - on exception
        org.opentrafficsim.base.parameters.ParameterException - on invalid parameter value or missing parameter
      • isEmpty

        public final boolean isEmpty()
        Returns whether this iterable is empty.
        Specified by:
        isEmpty in interface PerceptionIterable<H extends Headway>
        Returns:
        whether this iterable is empty
      • collect

        public final <C,​I> C collect​(Supplier<I> identity,
                                           PerceptionCollectable.PerceptionAccumulator<? super U,​I> accumulator,
                                           PerceptionCollectable.PerceptionFinalizer<C,​I> finalizer)
        Collect the underlying objects in to a perceived result. This methodology is loosely based on Stream.collect().
        Specified by:
        collect in interface PerceptionCollectable<H extends Headway,​U>
        Type Parameters:
        C - collection result type
        I - intermediate type
        Parameters:
        identity - Supplier<I>; the initial intermediate result value
        accumulator - PerceptionAccumulator<? super U, I>; accumulator
        finalizer - PerceptionFinalizer<C, I>; finalizer
        Returns:
        C; collection result
      • assureNext

        org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionReiterable.SecondaryIteratorEntry assureNext​(org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionReiterable.SecondaryIteratorEntry next,
                                                                                                                   org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionReiterable.SecondaryIteratorEntry lastReturned)
        Helper method that assures that a next entry is available, if the primary iterator has a next value. This method may be used by any process that derives from the primary iterator.
        Parameters:
        next - SecondaryIteratorEntry; currently known next entry
        lastReturned - SecondaryIteratorEntry; entry of last returned object or value
        Returns:
        IteratorEntry; next entry