@@ -0,0 +1,2232 @@
+package com.jmatch;%0A%0Aimport org.apache.commons.lang3.StringUtils;%0A%0A/**%0A * Uses single letters to represent variables in patterns.%0A */%0Apublic class SingleVariablePatternMatcher implements Matcher %7B%0A    private final String pattern;%0A%0A    /**%0A     * Constructs a new matcher with the given pattern. The pattern should consist of single letters to represent%0A     * variables in the pattern. E.g. %22abba%22 is composed of the variables 'a' and 'b'.%0A     *%0A     * @param pattern the given pattern%0A     */%0A    public SingleVariablePatternMatcher(String pattern) %7B%0A        this.pattern = pattern;%0A    %7D%0A%0A    @Override%0A    public boolean matches(String input) %7B%0A        return matchRemaining(pattern, input);%0A    %7D%0A%0A    private boolean matchRemaining(String pattern, String input) %7B%0A        // If there is no more of the pattern left to match we need an empty input String to have matched the%0A        // original input.%0A        if (pattern.isEmpty()) %7B%0A            return input.isEmpty();%0A        %7D%0A%0A        // Pick the first letter in the pattern as our current variable%0A        final String variable = Character.toString(pattern.charAt(0));%0A        // Count the number of times the variable occurs in the pattern%0A        final int numberOfVariableOccurrencesInPattern = StringUtils.countMatches(pattern, variable);%0A%0A        // Greedily attempt to assign a value to the current variable%0A        for (int endIndex = input.length(); endIndex %3E 0; endIndex--) %7B%0A            final String variableAssignment = input.substring(0, endIndex);%0A%0A            // Check to make sure that the proper number of occurrences of the assigned value exist in the input%0A            final int numberOfAssignmentOccurrencesInInput = StringUtils.countMatches(input, variableAssignment);%0A            if (numberOfAssignmentOccurrencesInInput == numberOfVariableOccurrencesInPattern) %7B%0A                // Check to see if the assignment leads to a valid match%0A                final boolean matchSuccessful = matchRemaining(pattern.replaceAll(variable, %22%22), input.replaceAll%0A                        (variableAssignment, %22%22));%0A%0A                if (matchSuccessful) %7B%0A                    return true;%0A                %7D%0A            %7D%0A        %7D%0A%0A        return false;%0A    %7D%0A%7D%0A

Add single variable implementation of Matcher