org.jscience.architecture.traffic.infrastructure
Class Drivelane

java.lang.Object
  extended by org.jscience.architecture.traffic.infrastructure.Drivelane
All Implemented Interfaces:
Selectable, SelectionStarter, TwoStageLoader, XMLSerializable

public class Drivelane
extends java.lang.Object
implements XMLSerializable, TwoStageLoader, Selectable

The basic lane.


Field Summary
protected  java.awt.Shape[] bounds
          A Shape array holding this drivelane's boundaries
protected  int cycleAsked
          The last cycle this Drivelane was asked if it had moved its Roadusers yet
protected  int cycleMoved
          The last cycle this Drivelane moved its Roadusers
protected  int Id
          The Id of this drivelane.
protected  org.jscience.architecture.traffic.infrastructure.Drivelane.TwoStageLoaderData loadData
          Data for loading the second stage
protected  java.lang.String parentName
          DOCUMENT ME!
protected  java.util.LinkedList queue
          The roadusers currently on this Drivelane
protected  Road road
          The Road this Drivelane is part of
protected  Sign sign
          The Sign at the end of this Drivelane
protected  boolean[] targets
          The directions Roadusers switch lanes to: left, straight ahead and right.
protected  int type
          The type of drivelane.
 
Constructor Summary
Drivelane()
          Empty constructor for loading
Drivelane(Road _road)
          Creates a new Drivelane object.
 
Method Summary
 void addCurveBounds(java.awt.Shape s)
          Adds new bounds to the bounds of this drivelane
 void addRoaduser(Roaduser ru, int pos)
          Adds a Roaduser at a given position to the lane
 void addRoaduserAtEnd(Roaduser ru)
          Adds a Roaduser at the end of this lane
 void addRoaduserAtEnd(Roaduser ru, int pos)
          Adds a Roaduser at the end of this lane
 void clearCurveBounds()
          Clears the bounds of this drivelane
 boolean contains(java.awt.Point p)
           
 java.awt.Rectangle getBounds()
          Returns the bounding box of this Selectable
 java.awt.Point getCenterPoint()
          DOCUMENT ME!
 java.util.Enumeration getChildren()
          DOCUMENT ME!
 int getCompleteLength()
          Returns the length of this Drivelane including tail
 java.util.LinkedList getCompleteQueue()
          DOCUMENT ME!
 java.awt.Shape getComplexBounds()
          DOCUMENT ME!
 int getCycleAsked()
          Return the last cycle this Drivelane was last asked about the movements of its Roadusers
 int getCycleMoved()
          Return the last cycle this Drivelane has moved its Roadusers
 int getDistance(java.awt.Point p)
          DOCUMENT ME!
 Roaduser getFirstRoaduser()
          Returns the first Roaduser on this Drivelane
 int getFreeUnitsInFront(Roaduser ru)
          DOCUMENT ME!
 int getId()
          Returns the Id of this drivelane.
 int getLength()
          Returns the length of the Road of this Drivelane
 java.lang.String getName()
          Returns the name of this drivelane.
 Node getNodeComesFrom()
          Returns the Node that this Drivelane comes from
 Node getNodeLeadsTo()
          Returns Node that this Drivelane leads to
 int getNumBlocksTaken()
          Returns the number of blocks taken by Roadusers on this Drivelane
 int getNumBlocksWaiting()
          Returns the number of blocks taken by Roadusers that are waiting for the Sign of this Drivelane
 int getNumPassengersWaiting()
          Returns the number of Passengers in the Roadusers that are waiting for the Sign of this Drivelane
 int getNumRoadusersWaiting()
          Returns the number of Roadusers that are waiting for the Sign of this Drivelane
 int getPosFree(java.util.ListIterator li, int position, int length, int speed_left, Roaduser ru)
          Returns the best reacheable position for the supplied Roaduser on the Queue given in the ListIterator
 java.util.LinkedList getQueue()
          Returns the queue of this Drivelane
 Road getRoad()
          Returns the Road that this Drivelane belongs to
 java.awt.Point getSelectionPoint()
          DOCUMENT ME!
 java.awt.Point[] getSelectionPoints()
          DOCUMENT ME!
 Sign getSign()
          Returns the Sign that regulates the traffic on this Drivelane
 int getTailLength()
          Returns the length of the tail of this Drivelane
 boolean getTarget(int target)
          Returns the state of given target
 boolean[] getTargets()
          Returns the roads users can move to when crossing the Node this lane leads to
 int getType()
          Returns the type of this Drivelane
 int[] getTypes()
          Returns an array of primitive Roaduser types that may roam this Drivelane
 java.lang.String getXMLName()
          DOCUMENT ME!
 boolean hasChildren()
          DOCUMENT ME!
 boolean isFull()
          Returns true when this drivelane is completely full @ author Chaim Z
 boolean isLastPosFree(int length)
          DOCUMENT ME!
 boolean isPosFree(int position, int length)
          Checks whether length blocks from the given position are free.
 boolean isPosFree(int position, int length, Roaduser me)
          Checks whether length blocks from the given position, before the given roaduser, are free.
 boolean isSelectable()
          DOCUMENT ME!
 boolean isTailFree()
          Returns whether or not the 'tail' of this Drivelane has any Roadusers on it.
 void load(XMLElement myElement, XMLLoader loader)
          Load this XMLSerializable
 void loadSecondStage(java.util.Dictionary dictionaries)
          DOCUMENT ME!
 boolean mayUse(int ruType)
          Returns if a Roaduser of type ruType may use this Drivelane
 Roaduser remRoaduserAtStart()
          Removes Roaduser at start of this lane
 void reset()
          Resets this Drivelane.
 void saveChilds(XMLSaver saver)
          DOCUMENT ME!
 XMLElement saveSelf()
          DOCUMENT ME!
 void setCycleAsked(int cycle)
          Sets the last cycle this Drivelane was last asked about the movements of its Roadusers
 void setCycleMoved(int cycle)
          Sets the last cycle this Drivelane has moved its Roadusers
 void setId(int newid)
          Sets the Id of this drivelane.
 void setParentName(java.lang.String parentName)
          DOCUMENT ME!
 void setQueue(java.util.LinkedList q)
          Sets the queue of this Drivelane
 void setRoad(Road r)
          Sets the Road that this Drivelane belongs to
 void setSign(Sign s)
          Sets the Sign that regulates the traffic on this Drivelane
 void setTarget(int target, boolean state)
          Sets the state of given target
 void setTargets(boolean[] r)
          Sets the roads users can move to when crossing the Node this lane leads to
 void setType(int t)
          Sets the type of this Drivelane
 boolean updateWaitingPosition(Roaduser current_ru)
          Returns if this ru is waiting, if so it will update the waiting position of this RoadUser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Id

protected int Id
The Id of this drivelane.


type

protected int type
The type of drivelane. This is a combination of Roaduser types that may use this drivelane


road

protected Road road
The Road this Drivelane is part of


queue

protected java.util.LinkedList queue
The roadusers currently on this Drivelane


sign

protected Sign sign
The Sign at the end of this Drivelane


targets

protected boolean[] targets
The directions Roadusers switch lanes to: left, straight ahead and right.


cycleAsked

protected int cycleAsked
The last cycle this Drivelane was asked if it had moved its Roadusers yet


cycleMoved

protected int cycleMoved
The last cycle this Drivelane moved its Roadusers


loadData

protected org.jscience.architecture.traffic.infrastructure.Drivelane.TwoStageLoaderData loadData
Data for loading the second stage


parentName

protected java.lang.String parentName
DOCUMENT ME!


bounds

protected java.awt.Shape[] bounds
A Shape array holding this drivelane's boundaries

Constructor Detail

Drivelane

public Drivelane(Road _road)
Creates a new Drivelane object.

Parameters:
_road - DOCUMENT ME!

Drivelane

public Drivelane()
Empty constructor for loading

Method Detail

getId

public int getId()
Returns the Id of this drivelane.

Returns:
DOCUMENT ME!

setId

public void setId(int newid)
Sets the Id of this drivelane.

Parameters:
newid - DOCUMENT ME!

getQueue

public java.util.LinkedList getQueue()
Returns the queue of this Drivelane

Returns:
DOCUMENT ME!

setQueue

public void setQueue(java.util.LinkedList q)
Sets the queue of this Drivelane

Parameters:
q - DOCUMENT ME!

getType

public int getType()
Returns the type of this Drivelane

Returns:
DOCUMENT ME!

setType

public void setType(int t)
Sets the type of this Drivelane

Parameters:
t - DOCUMENT ME!

getRoad

public Road getRoad()
Returns the Road that this Drivelane belongs to

Returns:
DOCUMENT ME!

setRoad

public void setRoad(Road r)
Sets the Road that this Drivelane belongs to

Parameters:
r - DOCUMENT ME!

getSign

public Sign getSign()
Returns the Sign that regulates the traffic on this Drivelane

Returns:
DOCUMENT ME!

setSign

public void setSign(Sign s)
Sets the Sign that regulates the traffic on this Drivelane

Parameters:
s - DOCUMENT ME!

getTargets

public boolean[] getTargets()
Returns the roads users can move to when crossing the Node this lane leads to

Returns:
DOCUMENT ME!

setTargets

public void setTargets(boolean[] r)
Sets the roads users can move to when crossing the Node this lane leads to

Parameters:
r - DOCUMENT ME!

getCycleMoved

public int getCycleMoved()
Return the last cycle this Drivelane has moved its Roadusers

Returns:
DOCUMENT ME!

setCycleMoved

public void setCycleMoved(int cycle)
Sets the last cycle this Drivelane has moved its Roadusers

Parameters:
cycle - DOCUMENT ME!

getCycleAsked

public int getCycleAsked()
Return the last cycle this Drivelane was last asked about the movements of its Roadusers

Returns:
DOCUMENT ME!

setCycleAsked

public void setCycleAsked(int cycle)
Sets the last cycle this Drivelane was last asked about the movements of its Roadusers

Parameters:
cycle - DOCUMENT ME!

getTailLength

public int getTailLength()
Returns the length of the tail of this Drivelane

Returns:
DOCUMENT ME!

getName

public java.lang.String getName()
Returns the name of this drivelane. It is unique, and only used by the GUI for decoration.

Returns:
DOCUMENT ME!

getCompleteLength

public int getCompleteLength()
Returns the length of this Drivelane including tail

Returns:
DOCUMENT ME!

getFreeUnitsInFront

public int getFreeUnitsInFront(Roaduser ru)
DOCUMENT ME!

Parameters:
ru - DOCUMENT ME!
Returns:
DOCUMENT ME!

getBounds

public java.awt.Rectangle getBounds()
Description copied from interface: Selectable
Returns the bounding box of this Selectable

Specified by:
getBounds in interface Selectable
Returns:
DOCUMENT ME!

getComplexBounds

public java.awt.Shape getComplexBounds()
DOCUMENT ME!

Specified by:
getComplexBounds in interface Selectable
Returns:
DOCUMENT ME!

getDistance

public int getDistance(java.awt.Point p)
DOCUMENT ME!

Specified by:
getDistance in interface Selectable
Parameters:
p - DOCUMENT ME!
Returns:
DOCUMENT ME!

getSelectionPoint

public java.awt.Point getSelectionPoint()
DOCUMENT ME!

Specified by:
getSelectionPoint in interface Selectable
Returns:
DOCUMENT ME!

getSelectionPoints

public java.awt.Point[] getSelectionPoints()
DOCUMENT ME!

Specified by:
getSelectionPoints in interface Selectable
Returns:
DOCUMENT ME!

getCenterPoint

public java.awt.Point getCenterPoint()
DOCUMENT ME!

Specified by:
getCenterPoint in interface Selectable
Returns:
DOCUMENT ME!

isSelectable

public boolean isSelectable()
DOCUMENT ME!

Specified by:
isSelectable in interface Selectable
Returns:
DOCUMENT ME!

hasChildren

public boolean hasChildren()
DOCUMENT ME!

Specified by:
hasChildren in interface SelectionStarter
Returns:
DOCUMENT ME!

getChildren

public java.util.Enumeration getChildren()
DOCUMENT ME!

Specified by:
getChildren in interface SelectionStarter
Returns:
DOCUMENT ME!

load

public void load(XMLElement myElement,
                 XMLLoader loader)
          throws XMLTreeException,
                 java.io.IOException,
                 XMLInvalidInputException
Description copied from interface: XMLSerializable
Load this XMLSerializable

Specified by:
load in interface XMLSerializable
Parameters:
myElement - The XMLElement which represents this object in the XML tree. It can contain attributes which hold information about the object.
loader - The XMLLoader which this XMLSerializable can use to load child objects.
Throws:
XMLTreeException - The parser can throw this exception if it is called by the XMLSerializable. The XMLSerializable should NOT throw this exception by itself and preferrably not catch it too.
java.io.IOException - Thrown in case of an read error in the XML file.
XMLInvalidInputException - The XMLSerializable can throw this exception if it cannot load itself or one of its child objects for whatever reason.

saveSelf

public XMLElement saveSelf()
                    throws XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveSelf in interface XMLSerializable
Returns:
DOCUMENT ME!
Throws:
XMLCannotSaveException - DOCUMENT ME!

saveChilds

public void saveChilds(XMLSaver saver)
                throws XMLTreeException,
                       java.io.IOException,
                       XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveChilds in interface XMLSerializable
Parameters:
saver - DOCUMENT ME!
Throws:
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
XMLCannotSaveException - DOCUMENT ME!

getXMLName

public java.lang.String getXMLName()
DOCUMENT ME!

Specified by:
getXMLName in interface XMLSerializable
Returns:
DOCUMENT ME!

setParentName

public void setParentName(java.lang.String parentName)
DOCUMENT ME!

Specified by:
setParentName in interface XMLSerializable
Parameters:
parentName - DOCUMENT ME!

loadSecondStage

public void loadSecondStage(java.util.Dictionary dictionaries)
                     throws XMLInvalidInputException,
                            XMLTreeException
DOCUMENT ME!

Specified by:
loadSecondStage in interface TwoStageLoader
Parameters:
dictionaries - DOCUMENT ME!
Throws:
XMLInvalidInputException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!

reset

public void reset()
Resets this Drivelane. This will remove all Roadusers on this lane, reset the cycleMoved and cycleAsked counters, and reset the sign.

See Also:
Sign.reset()

addRoaduserAtEnd

public void addRoaduserAtEnd(Roaduser ru)
                      throws InfraException
Adds a Roaduser at the end of this lane

Parameters:
ru - The roaduser to add
Throws:
InfraException - if the roaduser could not be added

addRoaduserAtEnd

public void addRoaduserAtEnd(Roaduser ru,
                             int pos)
                      throws InfraException
Adds a Roaduser at the end of this lane

Parameters:
ru - The roaduser to add
pos - The position where the roadusers should be added
Throws:
InfraException - if the roaduser could not be added

addRoaduser

public void addRoaduser(Roaduser ru,
                        int pos)
                 throws InfraException
Adds a Roaduser at a given position to the lane

Parameters:
ru - The roaduser to add
pos - The position at which to add the roaduser
Throws:
InfraException - if the position is taken by another roaduser

remRoaduserAtStart

public Roaduser remRoaduserAtStart()
                            throws InfraException
Removes Roaduser at start of this lane

Returns:
The roaduser removed from the queue
Throws:
InfraException - if there are no roadusers on this lane

getTypes

public int[] getTypes()
Returns an array of primitive Roaduser types that may roam this Drivelane

Returns:
DOCUMENT ME!

mayUse

public boolean mayUse(int ruType)
Returns if a Roaduser of type ruType may use this Drivelane

Parameters:
ruType - DOCUMENT ME!
Returns:
DOCUMENT ME!

getLength

public int getLength()
Returns the length of the Road of this Drivelane

Returns:
DOCUMENT ME!

getFirstRoaduser

public Roaduser getFirstRoaduser()
Returns the first Roaduser on this Drivelane

Returns:
DOCUMENT ME!

getNumRoadusersWaiting

public int getNumRoadusersWaiting()
Returns the number of Roadusers that are waiting for the Sign of this Drivelane

Returns:
DOCUMENT ME!

updateWaitingPosition

public boolean updateWaitingPosition(Roaduser current_ru)
Returns if this ru is waiting, if so it will update the waiting position of this RoadUser

Parameters:
current_ru - DOCUMENT ME!
Returns:
DOCUMENT ME!

getNumPassengersWaiting

public int getNumPassengersWaiting()
Returns the number of Passengers in the Roadusers that are waiting for the Sign of this Drivelane

Returns:
DOCUMENT ME!

getNumBlocksWaiting

public int getNumBlocksWaiting()
Returns the number of blocks taken by Roadusers that are waiting for the Sign of this Drivelane

Returns:
DOCUMENT ME!

getNumBlocksTaken

public int getNumBlocksTaken()
Returns the number of blocks taken by Roadusers on this Drivelane

Returns:
DOCUMENT ME!

getNodeComesFrom

public Node getNodeComesFrom()
Returns the Node that this Drivelane comes from

Returns:
DOCUMENT ME!

getNodeLeadsTo

public Node getNodeLeadsTo()
Returns Node that this Drivelane leads to

Returns:
DOCUMENT ME!

getTarget

public boolean getTarget(int target)
                  throws InfraException
Returns the state of given target

Parameters:
target - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

setTarget

public void setTarget(int target,
                      boolean state)
               throws InfraException
Sets the state of given target

Parameters:
target - DOCUMENT ME!
state - DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

isPosFree

public boolean isPosFree(int position,
                         int length)
Checks whether length blocks from the given position are free.

Parameters:
position - The position in the Queue of this Drivelane.
length - The amount of blocks that need to be free.
Returns:
DOCUMENT ME!

isPosFree

public boolean isPosFree(int position,
                         int length,
                         Roaduser me)
Checks whether length blocks from the given position, before the given roaduser, are free.

Parameters:
position - The position in the Queue of this Drivelane
length - The amount of blocks that need to be free.
me - The roaduser
Returns:
whether or not the requested position and length blocks are free for the supplied RU

isTailFree

public boolean isTailFree()
Returns whether or not the 'tail' of this Drivelane has any Roadusers on it.

Returns:
DOCUMENT ME!

isLastPosFree

public boolean isLastPosFree(int length)
DOCUMENT ME!

Parameters:
length - DOCUMENT ME!
Returns:
DOCUMENT ME!

isFull

public boolean isFull()
Returns true when this drivelane is completely full @ author Chaim Z

Returns:
DOCUMENT ME!

getPosFree

public int getPosFree(java.util.ListIterator li,
                      int position,
                      int length,
                      int speed_left,
                      Roaduser ru)
Returns the best reacheable position for the supplied Roaduser on the Queue given in the ListIterator

Parameters:
li - The Queue of this Drivelane represented in a ListIterator. li.previous() is the current RoadUser
position - The position on the Drivelane of the Roaduser
length - The amount of blocks that have to be free
speed_left - the number of 'moves' this Roaduser has left in this turn
ru - The Roaduser to be checked
Returns:
the number of blocks the Roaduser can move ahead

getCompleteQueue

public java.util.LinkedList getCompleteQueue()
DOCUMENT ME!

Returns:
DOCUMENT ME!

clearCurveBounds

public void clearCurveBounds()
Clears the bounds of this drivelane


addCurveBounds

public void addCurveBounds(java.awt.Shape s)
Adds new bounds to the bounds of this drivelane

Parameters:
s - DOCUMENT ME!

contains

public boolean contains(java.awt.Point p)