Class ParameterRefTools


  • public final class ParameterRefTools
    extends Object
    This utility class provides methods to deal with ParameterRef parameter references in all kinds of strings, used in different places like SystemDataConsumer-annotated methods.
    Author:
    Patrick Schmidt
    • Field Detail

      • EVEN_BS

        public static final String EVEN_BS
        The regular expression for an even number of backslashes. In this case the following character is not escaped and has to be interpreted as syntax.
        See Also:
        Constant Field Values
      • LEADING_BACKSLASH_GRP

        public static final int LEADING_BACKSLASH_GRP
        The index of the matcher group for the leading backslashes in the parameter ref pattern.
        See Also:
        Constant Field Values
      • TYPE_CHAR_GRP

        public static final int TYPE_CHAR_GRP
        The index of the matcher group for the type character in the parameter ref pattern.
        See Also:
        Constant Field Values
      • UDT_NAME_GRP

        public static final int UDT_NAME_GRP
        The index of the matcher group for the optional UDT name in the parameter ref pattern.
        See Also:
        Constant Field Values
      • INPUT_PARAMETER_GRP

        public static final int INPUT_PARAMETER_GRP
        The index of the matcher group for input parameter name in the parameter ref pattern.
        See Also:
        Constant Field Values
      • OUTPUT_PARAMETER_GRP

        public static final int OUTPUT_PARAMETER_GRP
        The index of the matcher group for optional output parameter name in the parameter ref pattern.
        See Also:
        Constant Field Values
      • PARAMETER_REF_PATTERN

        public static final Pattern PARAMETER_REF_PATTERN
        Pattern to match simple parameter references. Syntax characters like % and : have to be escaped appropriately with \. group(2) is the type char, group(3) is the (optional) UDT name (may be null or the empty string) and group(4) is the input parameter name. The caller has to validate whether the UDT name is makes sense or is required, the pattern does not check this.
        Do not forget to unescape the found parameter and data type names.
        If you want to use this, have a look at ParameterRefParser and ParameterRefReplacer. They might be more suitable for you.
      • IO_PARAMETER_REF_PATTERN

        public static final Pattern IO_PARAMETER_REF_PATTERN
        Pattern to match IO parameter references with a user-defined type parsing the UDT-name. This also allows for escaping syntax characters like % and : with \. group(2) is the type char, group(3) is the (optional) UDT name (may be null or the empty string), group(4) is the input parameter name and group(5) the optional output parameter name (may be null or the empty string). The caller has to validate whether the UDT name is makes sense or is required, the pattern does not check this.
        Do not forget to unescape the found parameter and data type names.
        If you want to use this, have a look at ParameterRefParser and ParameterRefReplacer. They might be more suitable for you.
    • Method Detail

      • findParameterReferences

        public static ParameterRef[] findParameterReferences​(String parameterisedString,
                                                             EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Finds all simple parameter references (see SystemDataConsumer) in the given string and returns them. This method will avoid returning duplicates (i.e. two parameter references that exactly match in name and type).
        Parameters:
        parameterisedString - a string, potentially containing variables / parameter references
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        all simple parameter references found in the string
      • findIOParameterReferences

        public static IOParameterRef[] findIOParameterReferences​(String parameterisedString,
                                                                 EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Finds all IO parameter references in the given string and returns them. This method will avoid returning duplicates (i.e. two parameter references that exactly match in type and parameter names).
        Parameters:
        parameterisedString - a string, potentially containing variables / parameter references
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        all IO parameter references found in the string
      • listParameterReferences

        public static ParameterRef[] listParameterReferences​(String parameterisedString,
                                                             EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Lists all simple parameter references (see SystemDataConsumer) in the given string and returns them in the encountered order. This method will NOT avoid returning duplicates.
        Parameters:
        parameterisedString - a string, potentially containing variables / parameter references
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        all simple parameter references found in the string
      • listIOParameterReferences

        public static IOParameterRef[] listIOParameterReferences​(String parameterisedString,
                                                                 EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Finds all IO parameter references in the given string and returns them in the encountered order. This method will NOT avoid returning duplicates.
        Parameters:
        parameterisedString - a string, potentially containing variables / parameter references
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        all IO parameter references found in the string
      • parseParameterReference

        public static ParameterRef parseParameterReference​(String parameterReference,
                                                           EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Parses the specified string representation of a simple parameter reference (PARAMETER_REF_PATTERN) (including the enclosing '%'s) and returns it as a ParameterRef object (or null if the reference is in any way illegal).
        Parameters:
        parameterReference - string representation of a simple parameter reference
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        a parsed ParameterRef object or null if the reference is in any way illegal
      • parseIOParameterReference

        public static IOParameterRef parseIOParameterReference​(String parameterReference,
                                                               EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Parses the specified string representation of a IO parameter reference (IO_PARAMETER_REF_PATTERN) (including the enclosing '%'s) and returns it as a IOParameterRef object (or null if the reference is in any way illegal).
        Parameters:
        parameterReference - string representation of a simple parameter reference
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        a parsed IOParameterRef object or null if the reference is in any way illegal
      • getParser

        public static ParameterRefParser getParser​(String parameterisedString,
                                                   EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Returns a parser for the specified parameterised string (for simple parameter references). The advantage compared to findParameterReferences(String, EnumSet) is that the parser provides position information (start and end index of parameter reference).
        Parameters:
        parameterisedString - the parameterised string to be formatted
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        a formatter for the specified parameterised string
      • getReplacer

        public static ParameterRefReplacer getReplacer​(String parameterisedString,
                                                       EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Returns a replacer for the specified parameterised string (for simple parameter references) to replace parameter references with actual values.
        Parameters:
        parameterisedString - the parameterised string to be processed
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        a replacer for the specified parameterised string
      • getIOParser

        public static IOParameterRefParser getIOParser​(String parameterisedString,
                                                       EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Returns a parser for the specified parameterised string (for IO parameter references). The advantage compared to findParameterReferences(String, EnumSet) is that the parser provides position information (start and end index of parameter reference).
        Parameters:
        parameterisedString - the parameterised string to be formatted
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        a formatter for the specified parameterised string
      • getIOReplacer

        public static IOParameterRefReplacer getIOReplacer​(String parameterisedString,
                                                           EnumSet<ProcessConstants.AdeptDataType> consideredDataTypes)
        Returns a replacer for the specified parameterised string (for IO parameter references) to replace parameter references with actual values.
        Parameters:
        parameterisedString - the parameterised string to be processed
        consideredDataTypes - the set of data types considered by this parser; all others will be ignored; use null to consider all data types
        Returns:
        a replacer for the specified parameterised string
      • toTypeKey

        public static String toTypeKey​(ProcessConstants.AdeptDataType dataType)
        Returns the type key (i.e. the identifying character in parameter references) for the specified data type.
        Parameters:
        dataType - the data type for which to return the type key
        Returns:
        the type key (i.e. the identifying character in parameter references) for the specified data type
      • fromTypeKey

        public static ProcessConstants.AdeptDataType fromTypeKey​(String typeKey)
        Returns the data type associated to the given type key or null if the type key is not recognised.
        Parameters:
        typeKey - the type key for which to return the associated data type
        Returns:
        the data type associated to the given type key or null if the type key is not recognised
      • unescapeIdentifier

        public static String unescapeIdentifier​(String s)
        Unescapes the designated identifier name, that is \ are removed where appropriate.
        Parameters:
        s - The identifier name (parameter or data type name) as retrieved from the matching the regular expression.
        Returns:
        The identifier name name with appropriately removed \.