VANET Simulator
 All Classes Functions Variables
Public Member Functions | Protected Attributes | List of all members
vanetsim.scenario.LaneContainer Class Reference

Public Member Functions

 LaneContainer (boolean direction)
 
synchronized void addSorted (LaneObject object)
 
synchronized void updatePosition (LaneObject object, double newPosition)
 
synchronized void remove (LaneObject object)
 
LaneObject getHead ()
 
LaneObject getTail ()
 
int size ()
 
void clear ()
 

Protected Attributes

final boolean direction_
 
LaneObject head_
 
LaneObject tail_
 
int size_ = 0
 

Detailed Description

A LaneContainer contains all LaneObjects in one direction of a street. The objects may be on different lanes. but they must all be in the same direction!
It's basically a kind of a queue implemented as a LinkedList. The references to the previous and next elements are stored in the LaneObjects which makes the implementation quite efficient as no search is necessary for removal. Thus, it always takes O(1) to remove an object. Adding is O(n) in worst case but in most cases, insertion is made in O(1) as the object is added at the head. In order to update positions (for example when an overhaul occurs) you don't need to remove and re-add (which could be quite costly) but rather just call updatePosition(). Checking for the next or previous LaneObject is O(1) and no lookup is necessary (directly stored within the object).
Insertion, removal and update is synchronized. As iterating through the objects needs to be done externally (by calling getNext() or getPrevious()), it is not synchronized!

Constructor & Destructor Documentation

vanetsim.scenario.LaneContainer.LaneContainer ( boolean  direction)
inline

Instantiates a new lane container.

Parameters
directiontrue if this lane is from startNode to endNode of the street, else false

Member Function Documentation

synchronized void vanetsim.scenario.LaneContainer.addSorted ( LaneObject  object)
inline

Add an element so that it's correctly ordered inside the lane container.

Parameters
objectthe object to add
void vanetsim.scenario.LaneContainer.clear ( )
inline

Removes all elements from this container.

LaneObject vanetsim.scenario.LaneContainer.getHead ( )
inline

Gets the head.

Returns
the first object
LaneObject vanetsim.scenario.LaneContainer.getTail ( )
inline

Gets the tail.

Returns
the last object
synchronized void vanetsim.scenario.LaneContainer.remove ( LaneObject  object)
inline

Removes an object. You must make sure that the object is really in this lane container. Otherwise this function might do very bad things (the size variable is decreased)!

Parameters
objectthe object to remove
int vanetsim.scenario.LaneContainer.size ( )
inline

Gets the current amount of objects on this lane container.

Returns
the size
synchronized void vanetsim.scenario.LaneContainer.updatePosition ( LaneObject  object,
double  newPosition 
)
inline

Updates position of a LaneObject and changes the order in this LaneContainer to guarantee a consistent state.

Parameters
objectthe object to check
newPositionthe new position of the object

Member Data Documentation

final boolean vanetsim.scenario.LaneContainer.direction_
protected

The direction of this container.
true = going from startNode to endNode
false = going from endNode to startNode

LaneObject vanetsim.scenario.LaneContainer.head_
protected

The head of the lane container.

int vanetsim.scenario.LaneContainer.size_ = 0
protected

The number of elements in this lane container.

LaneObject vanetsim.scenario.LaneContainer.tail_
protected

The tail of the lane container.


The documentation for this class was generated from the following file: