vanetsim.scenario
Class KnownRSUsList

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

public class KnownRSUsList
extends java.lang.Object

A list of all known Road-Side-Units which was discovered through beacons. In contrast to the KnownPenalties- class, an own class is used for storing the information about the RSUs. Although this means slightly more overhead, it should not be a big case and allows better extensibility.
A simple hash algorithm based on the RSU ID is used to get better performance. The hash determines the corresponding linked list(beginnings of linked lists are found in head_). Known RSUs with the same hash are connected together through their next_ and previous_ values (see KnownRSU-class).


Constructor Summary
KnownRSUsList()
          Empty constructor.
 
Method Summary
 void checkOutdatedRSUs()
          Checks if a RSU is too old so that it can be removed.
 void clear()
          Clears everything from this data structure.
 RSU findNearestRSU(int rsuX, int rsuY, int destX, int destY, int maxDistance)
          Finds the nearest known RSU to a destination.
 KnownRSU[] getFirstKnownRSU()
          Gets an hashed array with known RSUs (array length depends on the HASH_SIZE).
 int getSize()
          Gets the amount of known RSUs stored.
static void setTimePassed(int time)
          Sets the time passed since simulation start.
 void updateRSU(RSU rsu, long ID, int x, int y, boolean isEncrypted)
          Update a RSU or add it if it doesn't exist yet.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KnownRSUsList

public KnownRSUsList()
Empty constructor.

Method Detail

updateRSU

public void updateRSU(RSU rsu,
                      long ID,
                      int x,
                      int y,
                      boolean isEncrypted)
Update a RSU or add it if it doesn't exist yet.

Parameters:
rsu - a reference to the RSU
ID - the ID of the RSU
x - the x coordinate
y - the y coordinate
isEncrypted - if Beacon was encrypted

checkOutdatedRSUs

public void checkOutdatedRSUs()
Checks if a RSU is too old so that it can be removed. Note that this function is not synchronized! You need to make sure that no other thread uses any function on this object at the same time!


findNearestRSU

public RSU findNearestRSU(int rsuX,
                          int rsuY,
                          int destX,
                          int destY,
                          int maxDistance)
Finds the nearest known RSU to a destination. Only searches for non encrypted RSUs

Parameters:
rsuX - the x coordinate of the calling RSU
rsuY - the y coordinate of the calling RSU
destX - the x coordinate of the destination
destY - the y coordinate of the destination
maxDistance - the maximum distance the nearest RSU max have from the calling RSU
Returns:
the nearest RSU or null if the calling RSU is the nearest

getFirstKnownRSU

public KnownRSU[] getFirstKnownRSU()
Gets an hashed array with known RSUs (array length depends on the HASH_SIZE). You can iterate through all known RSUs by using getNext() until you get to a null element on all elements of this array

Returns:
the array with known RSUs

getSize

public int getSize()
Gets the amount of known RSUs stored.

Returns:
the size

setTimePassed

public static void setTimePassed(int time)
Sets the time passed since simulation start.

Parameters:
time - the new time in milliseconds

clear

public void clear()
Clears everything from this data structure.