Class AgentGraphArcImpl
java.lang.Object
com.amalgamasimulation.graphagent.AgentGraphArcImpl
- All Implemented Interfaces:
AgentGraphArc,GeometricGraphArc
- Direct Known Subclasses:
LongAgentGraphArcImpl
Simple implementation of
AgentGraphArc interface that is suitable in
most simple cases. Contains the generic implementations of all methods of
this interface.- Author:
- Andrey Malykhanov
-
Constructor Summary
ConstructorsConstructorDescriptionAgentGraphArcImpl(Polyline polyline) Creates a new instance ofAgentGraphArcImplwith the specifiedPolyline.AgentGraphArcImpl(Polyline polyline, AgentGraphArcImpl reverseArc) Creates a new instance ofAgentGraphArcImplwith the specifiedPolylineand reverse arc. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAgent(GraphAgent<?, ?> graphAgent) Adds the specified agent to this arc, e.g.voidaddCallbackPosition(GeometricGraphPosition<?, ?> position) Adds the specified callback position to this arc.voidafterAgentEntered(GraphAgent<?, ?> graphAgent) Callback method called after an agent enters this arc.voidbeforeAgentExited(GraphAgent<?, ?> graphAgent) Callback method called before an agent exits this arc.voidRemoves all callback positions from this arc, if any.booleancontainsAgent(GraphAgent<?, ?> graphAgent) Checks whether the specified agent is currently on this arc.List<GraphAgent<?, ?>> Returns an unmodifiable list of agents that are currently on this arc.List<GeometricGraphPosition<?, ?>> Returns an unmodifiable list of all callback positions belonging to this arc.Returns thePolylinecorresponding to this arc.Returns the arc that is a reverse to this one, ornullif this is a one-way arc.doublegetReverseOffset(double offset) Returns the absolute offset of this point on the reverse arc, if there is a reverse arc.voidonAgentReachedPosition(GraphAgent<?, ?> graphAgent, GeometricGraphPosition<?, ?> position) Callback method called when an agent reaches the specified callback position belonging to this arc.voidonAgentVelocityChanged(GraphAgent<?, ?> graphAgent) Callback method called immediately after velocity of the specified agent located on this arc changes.voidrecalculateAgents(GraphAgent<?, ?> exceptAgent, boolean recalculateReverseArc) Recalculates the internal events (specifically, events of reaching other agents) for all agents on this arc, except for the specified one.voidremoveAgent(GraphAgent<?, ?> graphAgent) Removes the specified agent from this arc, e.g.voidremoveCallbackPosition(GeometricGraphPosition<?, ?> position) Removes the specified callback position previously added byAgentGraphArc.addCallbackPosition(GeometricGraphPosition)method from this arc.voidsetPolyline(Polyline polyline) Sets the specified polyline to this arc.voidsetReverseArc(GeometricGraphArc reverseArc) Sets the reverse arc to this one.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.amalgamasimulation.graphagent.GeometricGraphArc
getLength
-
Constructor Details
-
AgentGraphArcImpl
Creates a new instance ofAgentGraphArcImplwith the specifiedPolyline.- Parameters:
polyline- specified polyline
-
AgentGraphArcImpl
Creates a new instance ofAgentGraphArcImplwith the specifiedPolylineand reverse arc.- Parameters:
polyline- specified polylinereverseArc- specified reverse arc
-
-
Method Details
-
addAgent
Description copied from interface:AgentGraphArcAdds the specified agent to this arc, e.g. when the agent enters this arc or jumps to it.- Specified by:
addAgentin interfaceAgentGraphArc- Parameters:
graphAgent- agent being added
-
removeAgent
Description copied from interface:AgentGraphArcRemoves the specified agent from this arc, e.g. when the agent leaves this arc or is completely removed from graph environment.- Specified by:
removeAgentin interfaceAgentGraphArc- Parameters:
graphAgent- agent being removed
-
onAgentVelocityChanged
Description copied from interface:AgentGraphArcCallback method called immediately after velocity of the specified agent located on this arc changes.- Specified by:
onAgentVelocityChangedin interfaceAgentGraphArc- Parameters:
graphAgent- agent whose velocity has just been changed
-
recalculateAgents
Description copied from interface:AgentGraphArcRecalculates the internal events (specifically, events of reaching other agents) for all agents on this arc, except for the specified one.- Specified by:
recalculateAgentsin interfaceAgentGraphArc- Parameters:
exceptAgent- agent for which the recalculation is not performedrecalculateReverseArc- whether or not to recalculate agents on the reverse arc, if any
-
getAgents
Description copied from interface:AgentGraphArcReturns an unmodifiable list of agents that are currently on this arc.- Specified by:
getAgentsin interfaceAgentGraphArc- Returns:
- unmodifiable list of agents that are currently on this arc
-
containsAgent
Description copied from interface:AgentGraphArcChecks whether the specified agent is currently on this arc.- Specified by:
containsAgentin interfaceAgentGraphArc- Parameters:
graphAgent- specified agent- Returns:
trueif the specified agent is currently on this arc,falseotherwise- See Also:
-
setPolyline
Sets the specified polyline to this arc. This is a mutating method that must be used with caution only for initialization purposes.- Parameters:
polyline- specified polyline
-
getPolyline
Description copied from interface:GeometricGraphArcReturns thePolylinecorresponding to this arc.- Specified by:
getPolylinein interfaceGeometricGraphArc- Returns:
Polylinecorresponding to this arc
-
getReverseArc
Description copied from interface:GeometricGraphArcReturns the arc that is a reverse to this one, ornullif this is a one-way arc.- Specified by:
getReverseArcin interfaceAgentGraphArc- Specified by:
getReverseArcin interfaceGeometricGraphArc- Returns:
- reverse arc, or
null
-
setReverseArc
Description copied from interface:GeometricGraphArcSets the reverse arc to this one. Normally used only when constructing the graph.- Specified by:
setReverseArcin interfaceGeometricGraphArc- Parameters:
reverseArc- reverse arc to this one- See Also:
-
getReverseOffset
public double getReverseOffset(double offset) Description copied from interface:GeometricGraphArcReturns the absolute offset of this point on the reverse arc, if there is a reverse arc. Otherwise, returnsDouble.NaN.- Specified by:
getReverseOffsetin interfaceGeometricGraphArc- Parameters:
offset- absolute offset of the point on this arc- Returns:
- absolute offset of the same point on the reverse arc, or
Double.NaN
-
addCallbackPosition
Description copied from interface:AgentGraphArcAdds the specified callback position to this arc. The callback methodAgentGraphArc.onAgentReachedPosition(GraphAgent, GeometricGraphPosition)will be called every time anGraphAgentreaches the specified position.- Specified by:
addCallbackPositionin interfaceAgentGraphArc- Parameters:
position- specified callback position- See Also:
-
removeCallbackPosition
Description copied from interface:AgentGraphArcRemoves the specified callback position previously added byAgentGraphArc.addCallbackPosition(GeometricGraphPosition)method from this arc. Does nothing if there is no specified callback position on this arc.- Specified by:
removeCallbackPositionin interfaceAgentGraphArc- Parameters:
position- specified callback position- See Also:
-
clearCallbackPositions
public void clearCallbackPositions()Description copied from interface:AgentGraphArcRemoves all callback positions from this arc, if any.- Specified by:
clearCallbackPositionsin interfaceAgentGraphArc- See Also:
-
getCallbackPositions
Description copied from interface:AgentGraphArcReturns an unmodifiable list of all callback positions belonging to this arc.- Specified by:
getCallbackPositionsin interfaceAgentGraphArc- Returns:
- unmodifiable list of all callback positions belonging to this arc
-
afterAgentEntered
Description copied from interface:AgentGraphArcCallback method called after an agent enters this arc.- Specified by:
afterAgentEnteredin interfaceAgentGraphArc- Parameters:
graphAgent- agent that have just entered this arc- See Also:
-
beforeAgentExited
Description copied from interface:AgentGraphArcCallback method called before an agent exits this arc.- Specified by:
beforeAgentExitedin interfaceAgentGraphArc- Parameters:
graphAgent- agent that is about to exit this arc- See Also:
-
onAgentReachedPosition
public void onAgentReachedPosition(GraphAgent<?, ?> graphAgent, GeometricGraphPosition<?, ?> position) Description copied from interface:AgentGraphArcCallback method called when an agent reaches the specified callback position belonging to this arc.- Specified by:
onAgentReachedPositionin interfaceAgentGraphArc- Parameters:
graphAgent- agent that have reached the specified callback positionposition- specified callback position
-
toString
-