Class AbstractPathRuleMatchExpression

    • Field Detail

      • MULTIPLE_CHAR_MATCH_CHAR

        private static final char MULTIPLE_CHAR_MATCH_CHAR
        See Also:
        Constant Field Values
      • SINGLE_CHAR_MATCH_CHAR

        private static final char SINGLE_CHAR_MATCH_CHAR
        See Also:
        Constant Field Values
      • NORMALIZED_FILE_SEPARATOR_CHAR

        private static final char NORMALIZED_FILE_SEPARATOR_CHAR
        See Also:
        Constant Field Values
      • MULTIPLE_CHAR_MATCH

        private static final java.lang.String MULTIPLE_CHAR_MATCH
      • SINGLE_CHAR_MATCH

        private static final java.lang.String SINGLE_CHAR_MATCH
      • NORMALIZED_FILE_SEPARATOR

        private static final java.lang.String NORMALIZED_FILE_SEPARATOR
    • Constructor Detail

      • AbstractPathRuleMatchExpression

        public AbstractPathRuleMatchExpression()
    • Method Detail

      • getResolved

        protected abstract Path getResolved()
        Returns the resolved expression.
        Returns:
        the resolved expression
      • determineExpected

        public java.lang.Object determineExpected​(AbstractRuleMatchExpression rhsExpr,
                                                  java.lang.Object rhsValue)
                                           throws VilException
        Description copied from class: AbstractRuleMatchExpression
        Determines the expected value on the left side (represented by this object) based on the actual value for the corresponding right side.
        Specified by:
        determineExpected in class AbstractRuleMatchExpression
        Parameters:
        rhsExpr - the (resolved) RHS expression
        rhsValue - the RHS value
        Returns:
        the expected LHS value (null denotes no expectation)
        Throws:
        VilException - in case that determining the expected object fails
      • contributesTo

        public boolean contributesTo​(AbstractRuleMatchExpression expression)
        Description copied from class: AbstractRuleMatchExpression
        Returns whether this rule match expression may contribute to the fulfillment of expression.
        Specified by:
        contributesTo in class AbstractRuleMatchExpression
        Parameters:
        expression - the expression to be considered (typically a RHS expression, while this is a LHS expression)
        Returns:
        true if this rule may contribute, false else
      • overlaps

        public static boolean overlaps​(java.lang.String leftPattern,
                                       java.lang.String rightPattern)
        Returns whether the leftPattern and rightPattern match, i.e., whether the matches on one side can be considered as the same or a subset of the matches on the other side.
        Parameters:
        leftPattern - the first pattern to match (LHS)
        rightPattern - the right pattern to match (RHS)
        Returns:
        true if the patterns overlap, false else
      • overlaps

        public static boolean overlaps​(java.lang.String leftPattern,
                                       int lPos,
                                       java.lang.String rightPattern,
                                       int rPos)
        Returns whether the leftPattern and rightPattern match, i.e., whether the matches on one side can be considered as the same or a subset of the matches on the other side. This method executes the implied recognizing state machines in intertwined fashion and stops as soon as no match is possible anymore.
        Parameters:
        leftPattern - the first pattern to match (LHS)
        lPos - the position to start from within leftPattern
        rightPattern - the right pattern to match (RHS)
        rPos - the position to start from within rightPattern
        Returns:
        true if the patterns overlap, false else
      • tryAndTrackBack

        private static boolean tryAndTrackBack​(java.lang.String leftPattern,
                                               AbstractPathRuleMatchExpression.MatchState leftState,
                                               java.lang.String rightPattern,
                                               AbstractPathRuleMatchExpression.MatchState rightState,
                                               int[] pos)
        Tries a match at the offsets determined by the states and tracks back if the match cannot be made.
        Parameters:
        leftPattern - the left pattern
        leftState - the matching state for the left pattern
        rightPattern - the right pattern
        rightState - the matching state for the right pattern
        pos - the current positions, at index 0 for left pattern, at index 1 for right
        Returns:
        true if a match was found at the given positions, false else
      • preparePattern

        private static java.lang.String preparePattern​(java.lang.String pattern)
        Prepares the given pattern conventions.
        Parameters:
        pattern - the pattern to be prepared
        Returns:
        the prepared pattern, may be pattern if nothing is changed
      • isPatternChar

        private static boolean isPatternChar​(char ch)
        Returns whether ch belongs to a pattern.
        Parameters:
        ch - the char to be tested
        Returns:
        true if ch belongs to a pattern, false else
      • determineNextState

        private static AbstractPathRuleMatchExpression.MatchState determineNextState​(java.lang.String text,
                                                                                     int pos,
                                                                                     int lastPos,
                                                                                     AbstractPathRuleMatchExpression.MatchState state)
        Determines the next matching state at the given position in text.
        Parameters:
        text - the text to be considered
        pos - the actual position within text
        lastPos - the last position where state was determined
        state - the actual state (determined at lastPos)
        Returns:
        the current state or null if pos is invalid
      • determineState

        private static AbstractPathRuleMatchExpression.MatchState determineState​(java.lang.String text,
                                                                                 int pos)
        Determines the current matching state at the given position in text.
        Parameters:
        text - the text to be considered
        pos - the actual position within text
        Returns:
        the current state or null if pos is invalid
      • replace

        public static java.lang.String replace​(java.lang.String lhsPattern,
                                               java.lang.String rhsPattern,
                                               java.lang.String rhsValue)
        Replaces the wildcards in lhsPattern with corresponding wildcard matches in rhsPattern derived from rhsValue.
        Parameters:
        lhsPattern - the pattern to be filled
        rhsPattern - the pattern to be used use to determine the values
        rhsValue - the value string (must match rhsPattern)
        Returns:
        lhsPattern with resolved wildcards or the original lhsPattern if rhsValue does not match rhsValue or lhsPattern has no wildcards
      • isWildcard

        private static boolean isWildcard​(java.lang.String token)
        Returns whether token is a wildcard.
        Parameters:
        token - the token to be tested
        Returns:
        true if token is a wildcard, false else
      • containsWildcards

        private static boolean containsWildcards​(java.util.List<java.lang.String> tokens)
        Returns whether tokens contains wildcards.
        Parameters:
        tokens - the tokens to be tested
        Returns:
        true if tokens contains wildcards, false else
      • match

        private static void match​(java.util.List<java.lang.String> tokens,
                                  java.lang.String valueText)
        Matches the tokens against the (matching!) value, removes common parts and replaces wildcards. Prerequisit: value already matches tokens!
        Parameters:
        tokens - the tokens to consider and to be modified as a side effect
        valueText - the value
      • replaceWildcards

        private static java.lang.String replaceWildcards​(java.util.List<java.lang.String> tokens,
                                                         java.util.List<java.lang.String> values)
        Replaces the wildcards in tokens by the values in values. Replacement happens as long as values are available.
        Parameters:
        tokens - the tokens to be considered for creating the result
        values - the values replacing wildcards in sequence
        Returns:
        the concatenated tokens and replaced wildcards
      • tokenize

        private static java.util.List<java.lang.String> tokenize​(java.lang.String text,
                                                                 boolean considerSeparator)
        Tokenizes the given path according to wildcards.
        Parameters:
        text - the text to be tokenized
        considerSeparator - tokenize also separators
        Returns:
        the tokens