Class AbstractPerceptionReiterable<H extends Headway,​U>

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

    public abstract class AbstractPerceptionReiterable<H extends Headway,​U>
    extends java.lang.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-2020 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
      • primaryIterator

        protected abstract java.util.Iterator<AbstractPerceptionReiterable.PrimaryIteratorEntry> primaryIterator()
        Returns the primary iterator. This method is called once by AbstractPerceptionReiterable.
        Returns:
        Iterator; primary iterator
      • perceive

        protected abstract H perceive​(LaneBasedGTU perceivingGtu,
                                      U object,
                                      Length distance)
                               throws GTUException,
                                      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
        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
      • iterator

        public final java.util.Iterator<H> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<H extends Headway>
      • collect

        public final <C,​I> C collect​(java.util.function.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
      • underlying

        public java.util.Iterator<U> underlying()
        Returns an iterator over the underlying objects.
        Specified by:
        underlying in interface PerceptionCollectable<H extends Headway,​U>
        Returns:
        Iterator<U>; iterator