|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object vanetsim.scenario.LaneContainer
public class LaneContainer
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 |
---|
public LaneContainer(boolean direction)
direction
- true
if this lane is from startNode to endNode of the street, else false
Method Detail |
---|
public void addSorted(LaneObject object)
object
- the object to addpublic void updatePosition(LaneObject object, double newPosition)
object
- the object to checknewPosition
- the new position of the objectpublic void remove(LaneObject object)
object
- the object to removepublic LaneObject getHead()
public LaneObject getTail()
public int size()
public void clear()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |