Class Variable
java.lang.Object
org.opentrafficsim.trafficcontrol.trafcod.Variable
- All Implemented Interfaces:
Serializable
,Remote
,EventListener
,org.djutils.event.EventListener
A TrafCOD variable, timer, or detector.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addOutput
(TrafficLight trafficLight) Add a traffic light to this variable.void
Clear the CHANGED flag of this Variable.void
Clear one flag.void
cloneState
(Variable fromVariable, org.opentrafficsim.core.network.Network newNetwork) Copy the state of this variable from another variable.int
Retrieve the rank of the conflict group that this Variable represents.boolean
decrementTimer
(int timeStamp10) Decrement the value of a timer.getColor()
Retrieve the color for an output Variable.Describe the rule that ends this variable.getFlags()
Return a safe copy of the flags.getName()
Retrieve the name of this variable.int
Retrieve the number of rules that refer to this variable.Describe the rule that starts this variable.short
Retrieve the stream to which this variable belongs.int
Retrieve the start value of this timer in units of 0.1 seconds (1 second is represented by the value 10).Retrieve the traffic lights controlled by this variable.int
getValue()
Retrieve the current value of this Variable.void
Increment the reference counter of this variable.void
Initialize this variable if it has the INITED flag set.boolean
Report of this Variable identifies the current conflict group.boolean
Report if this Variable is a detector.boolean
isOutput()
Report whether a change in this variable must be published.boolean
isTimer()
Report whether this Variable is a timer.void
notify
(org.djutils.event.Event event) void
setEndSource
(String endSource) Set the description of the rule that ends this variable.void
Set one flag.void
setOutput
(int colorValue) Make this variable an output variable and set the color value.void
setStartSource
(String startSource) Set the description of the rule that starts this variable.void
setTimerMax
(int value10) Set the maximum time of this timer.boolean
setValue
(int newValue, int timeStamp10, CausePrinter cause, TrafCod trafCODController) void
Link a detector variable to a sensor.toString()
toString
(EnumSet<PrintFlags> printFlags) Convert selected fields to a String.
-
Constructor Details
-
Variable
Construct a new Variable.- Parameters:
name
- String; name of the new variable (without the stream number)stream
- short; stream number to which the new Variable is associatedtrafCOD
- TrafCOD; the TrafCOD engine
-
-
Method Details
-
getRefCount
public int getRefCount()Retrieve the number of rules that refer to this variable.- Returns:
- int; the number of rules that refer to this variable
-
getTrafficLights
Retrieve the traffic lights controlled by this variable.- Returns:
- Set<TrafficLight>; the traffic lights controlled by this variable, or null when this variable has no traffic lights
-
getName
Retrieve the name of this variable.- Returns:
- String; the name (without the stream number) of this Variable
-
subscribeToDetector
Link a detector variable to a sensor.- Parameters:
sensor
- TrafficLightSensor; the sensor- Throws:
TrafficControlException
- when this variable is not a detector
-
initialize
public void initialize()Initialize this variable if it has the INITED flag set. -
decrementTimer
Decrement the value of a timer.- Parameters:
timeStamp10
- int; the current simulator time in tenths of a second- Returns:
- boolean; true if the timer expired due to this call; false if the timer is still running, or expired before this call
- Throws:
TrafficControlException
- when this Variable is not a timer
-
getColor
Retrieve the color for an output Variable.- Returns:
- int; the color code for this Variable
- Throws:
TrafficControlException
- if this Variable is not an output
-
isOutput
public boolean isOutput()Report whether a change in this variable must be published.- Returns:
- boolean; true if this Variable is an output; false if this Variable is not an output
-
isConflictGroup
public boolean isConflictGroup()Report of this Variable identifies the current conflict group.- Returns:
- boolean; true if this Variable identifies the current conflict group; false if it does not.
-
conflictGroupRank
Retrieve the rank of the conflict group that this Variable represents.- Returns:
- int; the rank of the conflict group that this Variable represents
- Throws:
TrafficControlException
- if this Variable is not a conflict group identifier
-
isDetector
public boolean isDetector()Report if this Variable is a detector.- Returns:
- boolean; true if this Variable is a detector; false if this Variable is not a detector
-
setValue
public boolean setValue(int newValue, int timeStamp10, CausePrinter cause, TrafCod trafCODController) - Parameters:
newValue
- int; the new value of this VariabletimeStamp10
- int; the time stamp of this updatecause
- CausePrinter; rule, timer, or detector that caused the changetrafCODController
- TrafCOD; the TrafCOD controller- Returns:
- boolean; true if the value of this variable changed
-
cloneState
public void cloneState(Variable fromVariable, org.opentrafficsim.core.network.Network newNetwork) throws org.opentrafficsim.core.network.NetworkException Copy the state of this variable from another variable. Only used when cloning the TrafCOD engine.- Parameters:
fromVariable
- Variable; the variable whose state is copiednewNetwork
- Network; the Network that contains the new traffic control engine- Throws:
org.opentrafficsim.core.network.NetworkException
- when the clone of a traffic light of fromVariable does not exist in newNetwork
-
getTimerMax
Retrieve the start value of this timer in units of 0.1 seconds (1 second is represented by the value 10).- Returns:
- int; the timerMax10 value
- Throws:
TrafficControlException
- when this class is not a Timer
-
getValue
public int getValue()Retrieve the current value of this Variable.- Returns:
- int; the value of this Variable
-
setFlag
Set one flag.- Parameters:
flag
- Flags; Flags
-
clearFlag
Clear one flag.- Parameters:
flag
- Flags; the flag to clear
-
isTimer
public boolean isTimer()Report whether this Variable is a timer.- Returns:
- boolean; true if this Variable is a timer; false if this variable is not a timer
-
clearChangedFlag
public void clearChangedFlag()Clear the CHANGED flag of this Variable. -
incrementReferenceCount
public void incrementReferenceCount()Increment the reference counter of this variable. The reference counter counts the number of rules where this variable occurs on the right hand side of the assignment operator. -
getFlags
Return a safe copy of the flags.- Returns:
- EnumSet<Flags>
-
setOutput
Make this variable an output variable and set the color value.- Parameters:
colorValue
- int; the output value (as used in the TrafCOD file)- Throws:
TrafficControlException
- when the colorValue is invalid, or this method is called more than once for this variable
-
addOutput
Add a traffic light to this variable.- Parameters:
trafficLight
- TrafficLight; the traffic light to add- Throws:
TrafficControlException
- when this variable is not an output
-
setTimerMax
Set the maximum time of this timer.- Parameters:
value10
- int; the maximum time in 0.1 s- Throws:
TrafficControlException
- when this Variable is not a timer
-
getStartSource
Describe the rule that starts this variable.- Returns:
- String
-
setStartSource
Set the description of the rule that starts this variable.- Parameters:
startSource
- String; description of the rule that starts this variable- Throws:
TrafficControlException
- when a start source has already been set
-
getEndSource
Describe the rule that ends this variable.- Returns:
- String
-
setEndSource
Set the description of the rule that ends this variable.- Parameters:
endSource
- String; description of the rule that ends this variable- Throws:
TrafficControlException
- when an end source has already been set
-
getStream
public short getStream()Retrieve the stream to which this variable belongs.- Returns:
- short; the stream to which this variable belongs
-
toString
-
toString
Convert selected fields to a String.- Parameters:
printFlags
- EnumSet<PrintFlags>; the set of fields to convert- Returns:
- String
-
notify
- Specified by:
notify
in interfaceorg.djutils.event.EventListener
- Throws:
RemoteException
-