Class SyntacticNode

  • All Implemented Interfaces:
    java.lang.Cloneable, SyntacticTerm, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class SyntacticNode
    extends ComponentEntity
    implements SyntacticTerm
    Represent nodes in the context of SyntacticGraphs. Existing and generated elements of models are represented and their ports are represented syntactically as enumerated lists of input and output ports. This enumeration is used for combinatorial composition in syntaxes with unnamed ports.

    Inheriting classes should use protected methods for constructing representation from existing elements.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Chris Shaver
    Pt.AcceptedRating:
    red
    Pt.ProposedRating:
    red (shaver)
    • Field Detail

      • _inputs

        protected java.util.LinkedList<SyntacticPort> _inputs
        List of references to ports syntactically marked as inputs.
      • _outputs

        protected java.util.LinkedList<SyntacticPort> _outputs
        List of references to ports syntactically marked as outputs.
    • Constructor Detail

      • SyntacticNode

        public SyntacticNode()
        Create new instance of SyntacticNode with no connections.
      • SyntacticNode

        public SyntacticNode​(Workspace workspace)
        Create new instance of SyntacticNode with no connections.
        Parameters:
        workspace - Workspace in which to create the node.
      • SyntacticNode

        public SyntacticNode​(CompositeEntity container,
                             java.lang.String name)
                      throws IllegalActionException,
                             NameDuplicationException
        Construct an entity with the given name contained by the specified entity. The container argument must not be null, or a NullPointerException will be thrown. This entity will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace. This constructor write-synchronizes on the workspace.
        Parameters:
        container - The container entity.
        name - The name of the entity.
        Throws:
        IllegalActionException - If the entity cannot be contained by the proposed container.
        NameDuplicationException - If the name coincides with an entity already in the container.
    • Method Detail

      • representEntity

        public boolean representEntity​(Entity entity)
                                throws IllegalActionException,
                                       NameDuplicationException
        Represent an Entity and its ports for use in a SyntacticGraph.
        Parameters:
        entity - The Entity to be represented with the SyntacticNode
        Returns:
        if the representation is total.
        Throws:
        IllegalActionException - If the entity is already represented, if there is a problem getting the width or creating a port or attribute.
        NameDuplicationException - If there is a problem creating a port or attribute.
      • addPorts

        public int addPorts​(Port port,
                            boolean isin)
                     throws IllegalActionException,
                            NameDuplicationException
        Add a port node with a directionality. Given port is represented by constructed SyntacticPorts then added to the node in this form. The number of ports added from the given port is the width of the given port. Each channel is represented by a SyntacticPort and pointed back to the given Port.
        Parameters:
        port - Port to add
        isin - True if input, False if output.
        Returns:
        number of SyntacticPorts added (= width).
        Throws:
        IllegalActionException - If thrown while getting the port width, creating a new port, creating a new StringAttribute or setting the expression.
        NameDuplicationException - If thrown while creating a new port.
      • representExteriorPort

        public void representExteriorPort​(Port port)
                                   throws IllegalActionException,
                                          NameDuplicationException
        Represent an exterior port with a purely syntactic Node.
        Parameters:
        port - The port to represent on the node.
        Throws:
        IllegalActionException - If thrown while creating a new port, creating a new cardinal attribute or setting the cardinal expression.
        NameDuplicationException - If thrown while creating a new port or creating a new cardinal attribute.
      • setSyntactic

        public void setSyntactic​(int inputs,
                                 int outputs)
                          throws IllegalActionException,
                                 NameDuplicationException
        Set node as purely syntactic, not representing any Entity.
        Parameters:
        inputs - Number of inputs.
        outputs - Number of outputs.
        Throws:
        IllegalActionException - If thrown while creating a new port, creating a new cardinal attribute or setting the cardinality.
        NameDuplicationException - If thrown while creating a new port or creating a new cardinal attribute.
      • setFeedback

        public void setFeedback​(boolean direction)
                         throws IllegalActionException,
                                NameDuplicationException
        Set node as a feedback node in specified direction, true being feed out.
        Parameters:
        direction - The direction to make the feedback node.
        Throws:
        IllegalActionException - If thrown while setting the node as purely syntactic, not representing any Entity.
        NameDuplicationException - If thrown while setting the node as purely syntactic, not representing any Entity.
      • setMediator

        public void setMediator​(boolean direction,
                                int valence)
                         throws IllegalActionException,
                                NameDuplicationException
        Set node as a mediator node in specified direction. The true direction splits, the false merges.
        Parameters:
        direction - The direction to make the mediator node.
        valence - The amount of endpoints on the opposite side.
        Throws:
        IllegalActionException - If thrown while setting the node as purely syntactic, not representing any Entity.
        NameDuplicationException - If thrown while setting the node as purely syntactic, not representing any Entity.
      • setCap

        public void setCap​(boolean direction)
                    throws IllegalActionException,
                           NameDuplicationException
        Set node as a initial or terminal node in specified direction, true being out.
        Parameters:
        direction - The direction to make the cap node.
        Throws:
        IllegalActionException - If thrown while setting the node as purely syntactic, not representing any Entity.
        NameDuplicationException - If thrown while setting the node as purely syntactic, not representing any Entity.
      • setPermutation

        public void setPermutation​(int[] permutation)
                            throws IllegalActionException,
                                   NameDuplicationException
        Set node as a bijective permutation node with a specified permutation.
        Parameters:
        permutation - The permutation to represent as the node.
        Throws:
        IllegalActionException - If thrown while setting the node as purely syntactic, not representing any Entity.
        NameDuplicationException - If thrown while setting the node as purely syntactic, not representing any Entity.
      • getConnectedNode

        public SyntacticNode getConnectedNode​(SyntacticPort port)
        Get the connected node from a given port. If the graph is not made bijective this gives the first.
        Parameters:
        port - The port to look out from.
        Returns:
        An immediately connected node.
      • getConnectedNode

        public java.util.List<SyntacticNode> getConnectedNode​(java.util.List<SyntacticPort> ports)
        Get a unique list of connected nodes from a given list of ports.
        Parameters:
        ports - The list of ports to look out from.
        Returns:
        A set list of immediately connected nodes.
      • getDownstreamNodes

        public java.util.List<SyntacticNode> getDownstreamNodes()
        Get a list of nodes immediately downstream from outgoing connections.
        Returns:
        A list of immediately downstream nodes.
      • getUpstreamNodes

        public java.util.List<SyntacticNode> getUpstreamNodes()
        Get a list of nodes immediately upstream from outgoing connections.
        Returns:
        A list of immediately upstream nodes.
      • remark

        public void remark()
        Recalculate properties of node.
      • setVisited

        public void setVisited​(boolean b)
        Set the visited marker. This marker is used for algorithms that visit nodes.
        Parameters:
        b - State of the visited flag.
      • setMarked

        public void setMarked​(boolean b)
        Set the marked marker. This marker is used for algorithms that traverse nodes.
        Parameters:
        b - State of the marked flag.
      • setLabel

        public void setLabel​(java.lang.String label)
        Set the label used to lexically represent the node.
        Parameters:
        label - Label to set for node.
        See Also:
        getLabel()
      • getLayoutVerticalSpace

        public double getLayoutVerticalSpace()
        Get the vertical offset for visually representing node.
        Returns:
        vertical offset down from baseline.
      • getIdentifier

        public java.lang.String getIdentifier()
        Get string identifier (non-unique) for node.
        Returns:
        identifier string.
      • isVisited

        public boolean isVisited()
        Get whether the node has been visited.
        Returns:
        value of the visited flag.
      • isMarked

        public boolean isMarked()
        Get whether the node has been marked.
        Returns:
        value of the marked flag.
      • outputPortIndex

        public java.lang.Integer outputPortIndex​(Port port)
        Get index represented by the first channel of given port.
        Parameters:
        port - The Port represented in the node.
        Returns:
        base index object or null if not found.
      • inputPortIndex

        public java.lang.Integer inputPortIndex​(Port port)
        Get index represented by the first channel of given port.
        Parameters:
        port - The Port represented in the node.
        Returns:
        base index object or null if not found.
      • outputIndex

        public java.lang.Integer outputIndex​(SyntacticPort port)
        Get index represented by the first channel of given port.
        Specified by:
        outputIndex in interface SyntacticTerm
        Parameters:
        port - The Port represented in the node.
        Returns:
        base index object or null if not found.
      • inputIndex

        public java.lang.Integer inputIndex​(SyntacticPort port)
        Get index represented by the first channel of given port.
        Specified by:
        inputIndex in interface SyntacticTerm
        Parameters:
        port - The Port represented in the node.
        Returns:
        base index object or null if not found.
      • getInputs

        public java.util.List<SyntacticPort> getInputs()
        Get the list of ordered inputs.
        Specified by:
        getInputs in interface SyntacticTerm
        Returns:
        The list of inputs.
      • getOutputs

        public java.util.List<SyntacticPort> getOutputs()
        Get the list of ordered outputs.
        Specified by:
        getOutputs in interface SyntacticTerm
        Returns:
        The list of outputs.
      • sizeInputs

        public int sizeInputs()
        Get the number of inputs to the node. For input nodes this returns 1 for the input it represents to the downstream node.
        Specified by:
        sizeInputs in interface SyntacticTerm
        Returns:
        number of inputs.
      • sizeOutputs

        public int sizeOutputs()
        Get the number of outputs to the node. For output nodes this returns 1 for the output it represents to the upstream node.
        Specified by:
        sizeOutputs in interface SyntacticTerm
        Returns:
        number of outputs.
      • boundaryCode

        public java.lang.String boundaryCode()
        Generate a string signifying the boundary of a node. The boundary is the number of inputs and outputs.
        Returns:
        string representing boundary of node.
      • getFirstInput

        public SyntacticPort getFirstInput()
        Get the first input or return null.
        Returns:
        first input or null.
      • getFirstOutput

        public SyntacticPort getFirstOutput()
        Get the first output or return null.
        Returns:
        first output or null.
      • getOrder

        public int getOrder()
        Get the relative order of the node by types. ... which order?
        Specified by:
        getOrder in interface SyntacticTerm
        Returns:
        the order of the node.
      • isFeedback

        public boolean isFeedback()
        Determine whether node represents feedback.
        Returns:
        Whether node is a feedback node
      • isIdentity

        public boolean isIdentity()
        Determine whether node represents an identity.
        Returns:
        Whether node is identity
      • isExterior

        public boolean isExterior()
        Determine whether node represents an exterior port.
        Returns:
        Whether node is exterior
      • isMediator

        public boolean isMediator()
        Determine whether node represents a mediator.
        Returns:
        Whether node is a mediator
      • isInitial

        public boolean isInitial()
        Determine whether node is initial, having no inputs.
        Returns:
        Whether node is initial
      • isTerminal

        public boolean isTerminal()
        Determine whether node is terminal, having no outputs.
        Returns:
        Whether node is terminal
      • isIsolated

        public boolean isIsolated()
        Determine whether node is isolated from the network.
        Returns:
        Whether node is isolated
      • isCap

        public boolean isCap()
        Determine whether node is a cap.
        Returns:
        Whether node is a cap
      • isPermutation

        public boolean isPermutation()
        Determine whether node is a permutation.
        Returns:
        Whether node is a permutation
      • isIncoming

        public boolean isIncoming()
        Determine whether node is incoming to the expression.
        Returns:
        Whether node is incoming
      • isOutgoing

        public boolean isOutgoing()
        Determine whether node is outgoing to the expression.
        Returns:
        Whether node is outgoing
      • hasCode

        public boolean hasCode()
        Determine whether or not code should be generated. If false, code should be suppressed such is the case for identity nodes.
        Specified by:
        hasCode in interface SyntacticTerm
        Returns:
        whether code should be generated.
      • getRepresented

        public Entity getRepresented()
        Get the Entity syntactically represented by the node.
        Returns:
        Represented Entity.
      • getExteriorPort

        public Port getExteriorPort()
        Get the exterior Port syntactically represented by the node.
        Returns:
        Represented Port.
      • getLabel

        public java.lang.String getLabel()
        Get the label of the node.
        Returns:
        label of the node.
        See Also:
        setLabel(java.lang.String)
      • isRepresentative

        public boolean isRepresentative()
        Determine whether node represents an Entity or is purely syntactic. A purely syntactic node represents a relationship in the Ptolemy network as a SyntacticNode that can be expressed in syntax as an special atomic element rather than as a combinator.
        Returns:
        Whether node is a representation.
      • generateCode

        public java.lang.String generateCode()
        Generate code for node.
        Specified by:
        generateCode in interface SyntacticTerm
        Returns:
        code representation of node.
      • description

        public java.lang.String description​(java.lang.String prefix,
                                            java.lang.String suffix)
        Print description of Node.
        Parameters:
        prefix - Line prefix for embedding description
        suffix - Line suffix for embedding description
        Returns:
        Description of Node.
      • _mapInputPort

        protected SyntacticPort _mapInputPort​(Port port,
                                              int offset)
        Get the SyntacticPort corresponding to a channel of a represented input port.
        Parameters:
        port - Port represented.
        offset - Offset channel of port, 0 if single port.
        Returns:
        corresponding SyntacticPort in node.
      • _mapOutputPort

        protected SyntacticPort _mapOutputPort​(Port port,
                                               int offset)
        Get the SyntacticPort corresponding to a channel of a represented output port.
        Parameters:
        port - Port represented.
        offset - Offset channel of port, 0 if single port.
        Returns:
        corresponding SyntacticPort in node.
      • _makePermutationIcon

        protected java.lang.String _makePermutationIcon​(int[] permutation)
                                                 throws IllegalActionException,
                                                        NameDuplicationException
        Generate icon for permutation node.
        Parameters:
        permutation - Array of permutation values.
        Returns:
        svg code for generated icon.
        Throws:
        IllegalActionException - If thrown while creating a new variable with the name "_portSpread".
        NameDuplicationException - If thrown while creating a new variable with the name "_portSpread".*sh
      • _makeMediatorIcon

        protected java.lang.String _makeMediatorIcon()
        Generate icon for mediator node.
        Returns:
        svg code for generated icon.