Class AbstractPerceptionReiterable<H extends Headway,U>
java.lang.Object
org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionReiterable<H,U>
- Type Parameters:
H
- headway typeU
- 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-2019 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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AbstractPerceptionReiterable.PerceptionIterator
This iterator is returned to callers of theiterator()
method.protected class
AbstractPerceptionReiterable.PrimaryIteratorEntry
Class forprimaryIterator()
to return, implemented in subclasses.Nested classes/interfaces inherited from interface org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable
PerceptionCollectable.Intermediate<I>, PerceptionCollectable.PerceptionAccumulator<U,I>, PerceptionCollectable.PerceptionCollector<C,U,I>, PerceptionCollectable.PerceptionFinalizer<C,I>, PerceptionCollectable.UnderlyingDistance<U>
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractPerceptionReiterable(LaneBasedGTU perceivingGtu)
Constructor. -
Method Summary
Modifier and Type Method Description <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.H
first()
Returns the first element.protected LaneBasedGTU
getGtu()
Returns the GTU.boolean
isEmpty()
Returns whether this iterable is empty.java.util.Iterator<H>
iterator()
protected abstract H
perceive(LaneBasedGTU perceivingGtu, U object, Length distance)
Returns a perceived version of the underlying object.protected abstract java.util.Iterator<AbstractPerceptionReiterable.PrimaryIteratorEntry>
primaryIterator()
Returns the primary iterator.java.util.Iterator<U>
underlying()
Returns an iterator over the underlying objects.java.util.Iterator<PerceptionCollectable.UnderlyingDistance<U>>
underlyingWithDistance()
Returns an iterator over the underlying objects coupled with the distance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opentrafficsim.road.gtu.lane.perception.PerceptionCollectable
collect
-
Constructor Details
-
AbstractPerceptionReiterable
Constructor.- Parameters:
perceivingGtu
- LaneBasedGTU; perceiving GTU
-
-
Method Details
-
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, ParameterExceptionReturns a perceived version of the underlying object.- Parameters:
perceivingGtu
- LaneBasedGTU; perceiving GTUobject
- U; underlying objectdistance
- Length; distance to the object- Returns:
- H; perceived version of the underlying object
- Throws:
GTUException
- on exceptionParameterException
- on invalid parameter value or missing parameter
-
first
Returns the first element.- Specified by:
first
in interfacePerceptionIterable<H extends Headway>
- Returns:
- H; first element
-
isEmpty
public final boolean isEmpty()Returns whether this iterable is empty.- Specified by:
isEmpty
in interfacePerceptionIterable<H extends Headway>
- Returns:
- whether this iterable is empty
-
iterator
-
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 interfacePerceptionCollectable<H extends Headway,U>
- Type Parameters:
C
- collection result typeI
- intermediate type- Parameters:
identity
- Supplier<I>; the initial intermediate result valueaccumulator
- PerceptionAccumulator<? super U, I>; accumulatorfinalizer
- PerceptionFinalizer<C, I>; finalizer- Returns:
- C; collection result
-
underlying
Returns an iterator over the underlying objects.- Specified by:
underlying
in interfacePerceptionCollectable<H extends Headway,U>
- Returns:
- Iterator<U>; iterator
-
underlyingWithDistance
Returns an iterator over the underlying objects coupled with the distance.- Specified by:
underlyingWithDistance
in interfacePerceptionCollectable<H extends Headway,U>
- Returns:
- Iterator<UnderlyingDistance<U>>; iterator
-