clazz, LaneBasedGtu gtu,
RelativePosition.TYPE pos) throws GtuException;
/**
* Wrapper to hold lane-based object and it's distance.
*
* 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 Sep 15, 2016
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param class of lane based object contained
*/
class Entry implements Comparable>
{
/** Distance to lane based object. */
private final Length distance;
/** Lane based object. */
private final T laneBasedObject;
/**
* @param distance Length; distance to lane based object
* @param laneBasedObject T; lane based object
*/
public Entry(final Length distance, final T laneBasedObject)
{
this.distance = distance;
this.laneBasedObject = laneBasedObject;
}
/**
* @return distance.
*/
public final Length getDistance()
{
return this.distance;
}
/**
* @return laneBasedObject.
*/
public final T getLaneBasedObject()
{
return this.laneBasedObject;
}
/** {@inheritDoc} */
@Override
public final int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((this.distance == null) ? 0 : this.distance.hashCode());
result = prime * result + ((this.laneBasedObject == null) ? 0 : this.laneBasedObject.hashCode());
return result;
}
/** {@inheritDoc} */
@Override
public final boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
Entry> other = (Entry>) obj;
if (this.distance == null)
{
if (other.distance != null)
{
return false;
}
}
else if (!this.distance.equals(other.distance))
{
return false;
}
if (this.laneBasedObject == null)
{
if (other.laneBasedObject != null)
{
return false;
}
}
// laneBasedObject does not implement equals...
else if (!this.laneBasedObject.equals(other.laneBasedObject))
{
return false;
}
return true;
}
/** {@inheritDoc} */
@Override
public final int compareTo(final Entry arg)
{
int d = this.distance.compareTo(arg.distance);
if (d != 0 || this.laneBasedObject.equals(arg.laneBasedObject))
{
return d; // different distance (-1 or 1), or same distance but also equal lane based object (0)
}
return 1; // same distance, unequal lane based object (1)
}
/** {@inheritDoc} */
@Override
public final String toString()
{
return "LaneStructure.Entry [distance=" + this.distance + ", laneBasedObject=" + this.laneBasedObject + "]";
}
}
}