Class SyntacticContraction

  • All Implemented Interfaces:
    SyntacticTerm

    public class SyntacticContraction
    extends java.lang.Object
    implements SyntacticTerm
    This class represents a contraction operator in the SyntacticTerm language. It represents the operation of contracting a SyntacticTerm with m inputs and n outputs along the first k of each, where k is a parameter of the operator called degree in the class. The result is a term (as an interface) with m-k inputs and n-k outputs. The operand term being contracted is the kernel of the operator and is referred to by the class as such. The initial object, without a kernel, can be understood to be an operator. Once the kernel is set, the object can be reasonably treated as a syntactic term representing the operator acting on the kernel.
    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Chris Shaver
    Pt.AcceptedRating:
    Red
    Pt.ProposedRating:
    Red (shaver)
    • Constructor Summary

      Constructors 
      Constructor Description
      SyntacticContraction​(int degree)
      Makes a new contraction operator with a given constant degree.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int degree()
      Get the degree of the term.
      java.lang.String generateCode()
      Generate the lexical representation of the contraction.
      java.util.List<SyntacticPort> getInputs()
      Get a list of the input ports to the operator.
      int getOrder()
      Get the sort order of the term.
      java.util.List<SyntacticPort> getOutputs()
      Get a list of output ports to the operator.
      boolean hasCode()
      Decide whether code can be generated from this term.
      java.lang.Integer inputIndex​(SyntacticPort port)
      Get the index of an input port given a reference to it.
      SyntacticTerm kernel()
      Get the reference to the kernel of the operator.
      java.lang.Integer outputIndex​(SyntacticPort port)
      Get the index of an output port given a reference to it.
      SyntacticRank rank()
      Get the rank of the term.
      boolean setKernel​(SyntacticTerm term)
      Set the kernel of the operator, effectively making it a term.
      int sizeInputs()
      Get the number of inputs to the term.
      int sizeOutputs()
      Get the number of outputs from the term.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SyntacticContraction

        public SyntacticContraction​(int degree)
        Makes a new contraction operator with a given constant degree. The degree is the number of outputs of the kernel that will be connected (enumerated ascending) to corresponding inputs.
        Parameters:
        degree - Degree of the operator.
    • Method Detail

      • getInputs

        public java.util.List<SyntacticPort> getInputs()
        Get a list of the input ports to the operator. If there is no kernel null is returned.
        Specified by:
        getInputs in interface SyntacticTerm
        Returns:
        list of input ports.
      • getOutputs

        public java.util.List<SyntacticPort> getOutputs()
        Get a list of output ports to the operator. If there is no kernel null is returned.
        Specified by:
        getOutputs in interface SyntacticTerm
        Returns:
        list of output ports.
      • sizeInputs

        public int sizeInputs()
        Get the number of inputs to the term.
        Specified by:
        sizeInputs in interface SyntacticTerm
        Returns:
        number of inputs or zero if no kernel.
      • sizeOutputs

        public int sizeOutputs()
        Get the number of outputs from the term.
        Specified by:
        sizeOutputs in interface SyntacticTerm
        Returns:
        number of outputs or zero if no kernel.
      • inputIndex

        public java.lang.Integer inputIndex​(SyntacticPort port)
        Get the index of an input port given a reference to it. null is returned if the port does not exist in the term or the kernel is absent.
        Specified by:
        inputIndex in interface SyntacticTerm
        Parameters:
        port - Port to find the index of.
        Returns:
        the index of the port or null if none.
      • outputIndex

        public java.lang.Integer outputIndex​(SyntacticPort port)
        Get the index of an output port given a reference to it. null is returned if the port does not exist in the term or the kernel is absent.
        Specified by:
        outputIndex in interface SyntacticTerm
        Parameters:
        port - Port to find the index of.
        Returns:
        the index of the port or null if none.
      • setKernel

        public boolean setKernel​(SyntacticTerm term)
        Set the kernel of the operator, effectively making it a term. Once the kernel is set, the class can be understood via the SyntacticTerm interface to be the term constituted of the kernel operated on by the contraction. If the rank is larger than the number of contractions that can happen on the kernel, it is not set and false is returned.
        Parameters:
        term - Term to contract with operator.
        Returns:
        whether kernel was set.
      • generateCode

        public java.lang.String generateCode()
        Generate the lexical representation of the contraction. The generation of code recursively descends to generate the code corresponding to the kernel. The operator is notated: { degree : kernel code }
        Specified by:
        generateCode in interface SyntacticTerm
        Returns:
        lexical representation of term.
      • getOrder

        public int getOrder()
        Get the sort order of the term.
        Specified by:
        getOrder in interface SyntacticTerm
        Returns:
        sort order of the term.
      • hasCode

        public boolean hasCode()
        Decide whether code can be generated from this term.
        Specified by:
        hasCode in interface SyntacticTerm
        Returns:
        whether code can be generated.
      • kernel

        public SyntacticTerm kernel()
        Get the reference to the kernel of the operator.
        Returns:
        kernel of the operator.
      • degree

        public int degree()
        Get the degree of the term.
        Returns:
        degree of term.