Class AbstractPerceptionIterable<H extends Headway,U,C>
java.lang.Object
org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionReiterable<H,U>
org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionIterable<H,U,C>
- Type Parameters:
H
- headway typeU
- underlying object typeC
- counter type
- All Implemented Interfaces:
java.lang.Iterable<H>
,PerceptionCollectable<H,U>
,PerceptionIterable<H>
- Direct Known Subclasses:
DownstreamNeighborsIterable
,LaneBasedObjectIterable
,UpstreamNeighborsIterable
public abstract class AbstractPerceptionIterable<H extends Headway,U,C> extends AbstractPerceptionReiterable<H,U>
Abstract iterable that figures out how to find the next nearest object, including splits.
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 16 feb. 2018
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractPerceptionIterable.Entry
Class of objects for subclasses to return.Nested classes/interfaces inherited from class org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionReiterable
AbstractPerceptionReiterable.PerceptionIterator, AbstractPerceptionReiterable.PrimaryIteratorEntry
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 Constructor Description AbstractPerceptionIterable(LaneBasedGTU perceivingGtu, LaneRecord<?> root, Length initialPosition, boolean downstream, Length maxDistance, RelativePosition relativePosition, Route route)
Constructor. -
Method Summary
Modifier and Type Method Description protected abstract Length
getDistance(U object, LaneRecord<?> record, Length position)
Returns the distance to the object.protected Length
getDx()
Returns the longitudinal length of the relevant relative position such that distances to this points can be calculated.protected abstract AbstractPerceptionIterable.Entry
getNext(LaneRecord<?> record, Length position, C counter)
Returns the next object(s) on the lane represented by the record.boolean
isDownstream()
Whether the iterable searches downstream.java.util.Iterator<AbstractPerceptionReiterable.PrimaryIteratorEntry>
primaryIterator()
Returns the primary iterator.Methods inherited from class org.opentrafficsim.road.gtu.lane.perception.AbstractPerceptionReiterable
collect, first, getGtu, isEmpty, iterator, perceive, underlying, underlyingWithDistance
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
-
AbstractPerceptionIterable
public AbstractPerceptionIterable(LaneBasedGTU perceivingGtu, LaneRecord<?> root, Length initialPosition, boolean downstream, Length maxDistance, RelativePosition relativePosition, Route route)Constructor.- Parameters:
perceivingGtu
- LaneBasedGTU; perceiving GTUroot
- LaneRecord<?>; root recordinitialPosition
- Length; initial positiondownstream
- boolean; search downstream (or upstream)maxDistance
- Length; max distance to searchrelativePosition
- RelativePosition; position to which distance are calculated by subclassesroute
- Route; route of the GTU, may benull
-
-
Method Details
-
isDownstream
public boolean isDownstream()Whether the iterable searches downstream.- Returns:
- boolean; whether the iterable searches downstream
-
primaryIterator
Returns the primary iterator. This method is called once by AbstractPerceptionReiterable.- Specified by:
primaryIterator
in classAbstractPerceptionReiterable<H extends Headway,U>
- Returns:
- Iterator; primary iterator
-
getNext
protected abstract AbstractPerceptionIterable.Entry getNext(LaneRecord<?> record, Length position, C counter) throws GTUExceptionReturns the next object(s) on the lane represented by the record. This should only consider objects on the given lane. This method should not check the distance towards objects with the maximum distance. The counter will benull
for the first object(s). For following object(s) it is whatever value is given with the previous outputEntry
. Hence, this method maintains its own counting system.- Parameters:
record
- LaneRecord<?>; record representing the lane and directionposition
- Length; position to look beyondcounter
- C; counter- Returns:
- next object(s) on the lane or
null
if none - Throws:
GTUException
- on any exception in the process
-
getDistance
Returns the distance to the object. The position fed in to this method is directly taken from anEntry
returned bygetNext
. The two methods need to be consistent with each other.- Parameters:
object
- U; underlying objectrecord
- LaneRecord<?>; record representing the lane and directionposition
- Length; position of the object on the lane- Returns:
- Length; distance to the object
-
getDx
Returns the longitudinal length of the relevant relative position such that distances to this points can be calculated.- Returns:
- Length; the longitudinal length of the relevant relative position such that distances to this points can be calculated
-