package org.opentrafficsim.road.gtu.lane.perception; import java.util.Iterator; import java.util.function.Supplier; import org.djunits.value.vdouble.scalar.Length; import org.opentrafficsim.road.gtu.lane.perception.headway.Headway; /** * Iterable that additionally provides support for PerceptionCollectors. These gather raw data, to only 'perceive' the result. *
* Copyright (c) 2013-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* Copyright (c) 2013-2021 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 28 feb. 2018
* Copyright (c) 2013-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version 28 feb. 2018
* Copyright (c) 2013-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version 28 feb. 2018
* Copyright (c) 2013-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version 3 apr. 2018
* Copyright (c) 2013-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version Aug 6, 2019
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param underlying object type
* @param intermediate result type
*/
public interface PerceptionAccumulator
{
/**
* Accumulate the next object to intermediate result.
* @param intermediate Intermediate<I>; intermediate result before accumulation of object
* @param object U; next object to include
* @param distance Length; distance to the considered object
* @return I; intermediate result after accumulation of object
*/
Intermediate accumulate(Intermediate intermediate, U object, Length distance);
}
/**
* Translates the last intermediate result of an accumulator in to the collection output.
*
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel]
* @param intermediate result type
*/
class Intermediate
{
/** Number of underlying object being iterated. */
private int number = 0;
/** Intermediate object. */
private I object;
/** Whether to stop accumulating. */
private boolean stop = false;
/**
* Constructor.
* @param object I; identity value
*/
public Intermediate(final I object)
{
this.object = object;
}
/**
* Get intermediate object.
* @return I; intermediate object
*/
public I getObject()
{
return this.object;
}
/**
* Set intermediate object.
* @param object I; intermediate object
*/
public void setObject(final I object)
{
this.object = object;
}
/**
* Returns the number of the underlying object currently being accumulated, starts at 0 for the first.
* @return int; number of the underlying object currently being accumulated
*/
public int getNumber()
{
return this.number;
}
/**
* Method for the iterator to increase the underlying object number.
*/
public void step()
{
this.number++;
}
/**
* Method for the accumulator to indicate the iterator can stop.
*/
public void stop()
{
this.stop = true;
}
/**
* Method for the iterator to check if it can stop.
* @return boolean; whether the iterator can stop
*/
public boolean isStop()
{
return this.stop;
}
}
/**
* Wrapper for object and its distance.
*
* BSD-style license. See OpenTrafficSim License.
*
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param underlying object type
*/
class UnderlyingDistance
{
/** Object. */
final U object;
/** Distance. */
final Length distance;
/**
* @param object U; object
* @param distance Length; distance
*/
public UnderlyingDistance(final U object, final Length distance)
{
this.object = object;
this.distance = distance;
}
/**
* @return U; object.
*/
public U getObject()
{
return this.object;
}
/**
* @return Length; distance.
*/
public Length getDistance()
{
return this.distance;
}
}
}