vanetsim.scenario
Class LaneContainer

java.lang.Object
  extended by vanetsim.scenario.LaneContainer

public class LaneContainer
extends java.lang.Object

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 Summary
LaneContainer(boolean direction)
          Instantiates a new lane container.
 
Method Summary
 void addSorted(LaneObject object)
          Add an element so that it's correctly ordered inside the lane container.
 void clear()
          Removes all elements from this container.
 LaneObject getHead()
          Gets the head.
 LaneObject getTail()
          Gets the tail.
 void remove(LaneObject object)
          Removes an object.
 int size()
          Gets the current amount of objects on this lane container.
 void updatePosition(LaneObject object, double newPosition)
          Updates position of a LaneObject and changes the order in this LaneContainer to guarantee a consistent state.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LaneContainer

public LaneContainer(boolean direction)
Instantiates a new lane container.

Parameters:
direction - true if this lane is from startNode to endNode of the street, else false
Method Detail

addSorted

public void addSorted(LaneObject object)
Add an element so that it's correctly ordered inside the lane container.

Parameters:
object - the object to add

updatePosition

public void updatePosition(LaneObject object,
                           double newPosition)
Updates position of a LaneObject and changes the order in this LaneContainer to guarantee a consistent state.

Parameters:
object - the object to check
newPosition - the new position of the object

remove

public void remove(LaneObject object)
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:
object - the object to remove

getHead

public LaneObject getHead()
Gets the head.

Returns:
the first object

getTail

public LaneObject getTail()
Gets the tail.

Returns:
the last object

size

public int size()
Gets the current amount of objects on this lane container.

Returns:
the size

clear

public void clear()
Removes all elements from this container.