Class GTIngredient

  • Direct Known Subclasses:
    Criterion, Operation

    public abstract class GTIngredient
    extends java.lang.Object
    Superclass of criteria and operations that can be associated with entities in a transformation rule. Each GTIngredient has a number of {\em elements}. An element is essentially an entry that can hold a value and can be disabled if its value is ignored. This superclass provides common methods for defining and accessing those elements.
    Since:
    Ptolemy II 7.1
    Version:
    $Id$
    Author:
    Thomas Huining Feng
    Pt.AcceptedRating:
    Red (tfeng)
    Pt.ProposedRating:
    Yellow (tfeng)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  GTIngredient.FieldIterator
      An iterator to read the fields one by one in a string that describes the values of all the elements.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char FIELD_SEPARATOR
      The string to separate elements in a string that describes their values.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected GTIngredient​(GTIngredientList owner, int elementCount)
      Construct a GTIngredient within the given list as its owner containing a given number of elements.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean _decodeBooleanField​(int index, GTIngredient.FieldIterator iterator)
      Decode a Boolean field and store the value into the index-th element.
      protected java.lang.String _decodeStringField​(int index, GTIngredient.FieldIterator iterator)
      Decode a string field and store the value into the index-th element.
      protected void _encodeBooleanField​(java.lang.StringBuffer buffer, int index, boolean value)
      Encode a Boolean field with the given value using the enablement of the index-th element, and append the encoded string to the end of the buffer.
      protected void _encodeStringField​(java.lang.StringBuffer buffer, int index, java.lang.String value)
      Encode a string field with the given value using the enablement of the index-th element, and append the encoded string to the end of the buffer.
      protected static java.lang.String _escapeElementString​(java.lang.String elementString)
      Escape a string that describes the value of a single element, so that it is enclosed in quotes and between the quotes, there are no quotes (single or double) or backslashes.
      protected static int _findMatchingParen​(java.lang.String s, int startPos)
      Find the closing parenthesis that matches the the open parenthesis at startPos position in string s.
      protected static int _findSeparator​(java.lang.String s, int startPos, char separator)
      Find the separator character in string s starting from position startPos.
      protected static java.lang.String _unescapeElementString​(java.lang.String elementString)
      Unescape a string that has been escaped previously from an original string that describes the value of a single element, and get back the original string.
      void disableAll()
      Disable all elements.
      void enableAll()
      Enable all elements.
      abstract GTIngredientElement[] getElements()
      Get the array of elements defined in this GTIngredient.
      GTIngredientList getOwner()
      Get the list that contains this GTIngredient.
      abstract java.lang.Object getValue​(int index)
      Get the value of the index-th elements.
      abstract java.lang.String getValues()
      Get a string that describes the values of all the elements.
      boolean isApplicable​(NamedObj object)
      Check whether this GTIngredient is applicable to the object.
      boolean isEnabled​(int index)
      Check whether the index-th element is enabled.
      void setEnabled​(int index, boolean isEnabled)
      Set the enablement of the index-th element.
      abstract void setValue​(int index, java.lang.Object value)
      Set the value of the index-th element.
      abstract void setValues​(java.lang.String values)
      Set the values of all the elements with a string that describes them.
      java.lang.String toString()
      Return a readable string about this GTIngredient.
      abstract void validate()
      Validate the enablements and values of all the elements.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • FIELD_SEPARATOR

        public static final char FIELD_SEPARATOR
        The string to separate elements in a string that describes their values.
        See Also:
        Constant Field Values
    • Constructor Detail

      • GTIngredient

        protected GTIngredient​(GTIngredientList owner,
                               int elementCount)
        Construct a GTIngredient within the given list as its owner containing a given number of elements. All elements are enabled at the beginning.
        Parameters:
        owner - The list as the owner of the constructed GTIngredientList.
        elementCount - The number of elements that the GTIngredient has.
    • Method Detail

      • disableAll

        public void disableAll()
        Disable all elements.
      • enableAll

        public void enableAll()
        Enable all elements.
      • getElements

        public abstract GTIngredientElement[] getElements()
        Get the array of elements defined in this GTIngredient.
        Returns:
        The array of elements.
      • getOwner

        public GTIngredientList getOwner()
        Get the list that contains this GTIngredient.
        Returns:
        The list.
      • getValue

        public abstract java.lang.Object getValue​(int index)
        Get the value of the index-th elements.
        Parameters:
        index - The index.
        Returns:
        The value.
        See Also:
        setValue(int, Object)
      • getValues

        public abstract java.lang.String getValues()
        Get a string that describes the values of all the elements.
        Returns:
        A string that describes the values of all the elements.
        See Also:
        setValues(String)
      • isApplicable

        public boolean isApplicable​(NamedObj object)
        Check whether this GTIngredient is applicable to the object.
        Parameters:
        object - The object.
        Returns:
        true if this GTIngredient is applicable; false otherwise.
      • isEnabled

        public boolean isEnabled​(int index)
        Check whether the index-th element is enabled.
        Parameters:
        index - The index.
        Returns:
        true if the index-th element is enabled; false otherwise.
        See Also:
        setEnabled(int, boolean)
      • setEnabled

        public void setEnabled​(int index,
                               boolean isEnabled)
        Set the enablement of the index-th element.
        Parameters:
        index - The index.
        isEnabled - true if the element is set to be enabled; false if it is disabled.
        See Also:
        isEnabled(int)
      • setValue

        public abstract void setValue​(int index,
                                      java.lang.Object value)
        Set the value of the index-th element.
        Parameters:
        index - The index.
        value - The value.
        See Also:
        getValue(int)
      • setValues

        public abstract void setValues​(java.lang.String values)
        Set the values of all the elements with a string that describes them.
        Parameters:
        values - A string that describes the new values of all the elements.
        See Also:
        getValues()
      • toString

        public java.lang.String toString()
        Return a readable string about this GTIngredient.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string.
      • _decodeBooleanField

        protected boolean _decodeBooleanField​(int index,
                                              GTIngredient.FieldIterator iterator)
        Decode a Boolean field and store the value into the index-th element.
        Parameters:
        index - The index.
        iterator - The iterator used to iterate over all fields in a string describing all the values.
        Returns:
        The value of the field.
      • _decodeStringField

        protected java.lang.String _decodeStringField​(int index,
                                                      GTIngredient.FieldIterator iterator)
        Decode a string field and store the value into the index-th element.
        Parameters:
        index - The index.
        iterator - The iterator used to iterate over all fields in a string describing all the values.
        Returns:
        The value of the field.
      • _encodeBooleanField

        protected void _encodeBooleanField​(java.lang.StringBuffer buffer,
                                           int index,
                                           boolean value)
        Encode a Boolean field with the given value using the enablement of the index-th element, and append the encoded string to the end of the buffer.
        Parameters:
        buffer - The buffer.
        index - The index.
        value - The value to be encoded.
      • _encodeStringField

        protected void _encodeStringField​(java.lang.StringBuffer buffer,
                                          int index,
                                          java.lang.String value)
        Encode a string field with the given value using the enablement of the index-th element, and append the encoded string to the end of the buffer.
        Parameters:
        buffer - The buffer.
        index - The index.
        value - The value to be encoded.
      • _escapeElementString

        protected static java.lang.String _escapeElementString​(java.lang.String elementString)
        Escape a string that describes the value of a single element, so that it is enclosed in quotes and between the quotes, there are no quotes (single or double) or backslashes.
        Parameters:
        elementString - The string to be escaped.
        Returns:
        The escaped string.
        See Also:
        _unescapeElementString(String)
      • _findMatchingParen

        protected static int _findMatchingParen​(java.lang.String s,
                                                int startPos)
        Find the closing parenthesis that matches the the open parenthesis at startPos position in string s.
        Parameters:
        s - The string.
        startPos - The position of the open parenthesis to be matched.
        Returns:
        The position of the matching close parenthesis, or -1 if either the character at position startPos is not an open parenthesis or it is an open parenthesis but is not matched.
      • _findSeparator

        protected static int _findSeparator​(java.lang.String s,
                                            int startPos,
                                            char separator)
        Find the separator character in string s starting from position startPos. If the separator is preceded with a backslash, then it is escaped and would not be returned. The string may have quoted substrings, and the contents between the quotes are not search.
        Parameters:
        s - The string.
        startPos - The start position.
        separator - The separator character.
        Returns:
        The position of the separator, if found, or -1 otherwise.
      • _unescapeElementString

        protected static java.lang.String _unescapeElementString​(java.lang.String elementString)
        Unescape a string that has been escaped previously from an original string that describes the value of a single element, and get back the original string.
        Parameters:
        elementString - The string to be unescaped.
        Returns:
        The unescaped string.
        See Also:
        _escapeElementString(String)