Package xdevs.core.modeling
Class Component
- java.lang.Object
-
- xdevs.core.modeling.Component
-
public abstract class Component extends Object
Abstract class for all components in the DEVS formalism. A component is a model that can be connected to other components to form a hierarchical model. It has input and output ports to communicate with other components. The component has a parent component, which is the component that contains this component. The parent component is null if this component is the root component of the model. The component has a list of input ports and a list of output ports. The input ports are used to receive input from other components, and the output ports are used to send output to other components.
-
-
Field Summary
Fields Modifier and Type Field Description protected Boolean
chained
The chained attribute is used to indicate if the component is chained to another component.protected ArrayList<Port<?>>
inPorts
The list of input ports of the component.protected String
name
The name of the component.protected ArrayList<Port<?>>
outPorts
The list of output ports of the component.protected Component
parent
The parent component of this component.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addInPort(Port<?> port)
This function has been designed to add an input port to the component.void
addOutPort(Port<?> port)
This function has been designed to add an output port to the component.abstract void
exit()
Exit function.Port<?>
getInPort(String portName)
This function has been designed to obtain an input port of the component.Collection<Port<?>>
getInPorts()
This function has been designed to obtain the list of input ports of the component.String
getName()
Get the name of the component.Port<?>
getOutPort(String portName)
This function has been designed to obtain an output port of the component.Collection<Port<?>>
getOutPorts()
This function has been designed to obtain the list of output ports of the component.Component
getParent()
This function has been designed to obtain the parent component of the component.abstract void
initialize()
Initialize the component.boolean
isInputEmpty()
This function checks if the input ports of the component are empty.void
setParent(Component parent)
This function has been designed to set the parent component of the component.String
toString()
This function builds the string representation of the component.abstract String
toXml()
This function has been designed to obtain the XML representation of the component.
-
-
-
Field Detail
-
parent
protected Component parent
The parent component of this component. The parent component is the component that contains this component. The parent component is null if this component is the root component of the model.
-
name
protected String name
The name of the component. The name is used to identify the component in the model.
-
inPorts
protected ArrayList<Port<?>> inPorts
The list of input ports of the component. The input ports are used to receive input from other components.
-
outPorts
protected ArrayList<Port<?>> outPorts
The list of output ports of the component. The output ports are used to send output to other components.
-
chained
protected Boolean chained
The chained attribute is used to indicate if the component is chained to another component. A component is chained to another component if the output ports of the first component are connected to the input ports of the second component.
-
-
Constructor Detail
-
Component
public Component(String name)
The constructor of the component. The constructor receives the name of the component. The name is used to identify the component in the model.- Parameters:
name
- The name of the component.
-
Component
public Component()
The default constructor of the component. The default constructor creates a component with the name "Component".
-
-
Method Detail
-
getName
public String getName()
Get the name of the component.- Returns:
- The name of the component.
-
initialize
public abstract void initialize()
Initialize the component. The initialize method is called when the simulation starts. The initialize method is used to initialize the component before the simulation starts.
-
exit
public abstract void exit()
Exit function. The exit function is called when the simulation ends. The exit function is used to release resources used by the component.
-
toXml
public abstract String toXml()
This function has been designed to obtain the XML representation of the component. The XML representation of the component is used to save the model to a file.- Returns:
- The XML representation of the component.
-
isInputEmpty
public boolean isInputEmpty()
This function checks if the input ports of the component are empty. The input ports are empty if they do not have any input.- Returns:
- True if the input ports of the component are empty, false otherwise.
-
addInPort
public void addInPort(Port<?> port)
This function has been designed to add an input port to the component. The input port is added to the list of input ports of the component.- Parameters:
port
- The input port to be added to the component.
-
getInPort
public Port<?> getInPort(String portName)
This function has been designed to obtain an input port of the component.- Parameters:
portName
- The name of the input port to be obtained.- Returns:
- The input port with the specified name. If the input port does not exist, the function returns null.
-
getInPorts
public Collection<Port<?>> getInPorts()
This function has been designed to obtain the list of input ports of the component.- Returns:
- The list of input ports of the component.
-
addOutPort
public void addOutPort(Port<?> port)
This function has been designed to add an output port to the component. The output port is added to the list of output ports of the component.- Parameters:
port
- The output port to be added to the component.
-
getOutPort
public Port<?> getOutPort(String portName)
This function has been designed to obtain an output port of the component.- Parameters:
portName
- The name of the output port to be obtained.- Returns:
- The output port with the specified name. If the output port does not exist, the function returns null.
-
getOutPorts
public Collection<Port<?>> getOutPorts()
This function has been designed to obtain the list of output ports of the component.- Returns:
- The list of output ports of the component.
-
getParent
public Component getParent()
This function has been designed to obtain the parent component of the component.- Returns:
- The parent component of the component.
-
setParent
public void setParent(Component parent)
This function has been designed to set the parent component of the component.- Parameters:
parent
- The parent component of the component.
-
-