public int getTailMatchLength(ElementPath p) {
        if (p == null) {
            return 0;
        }

        int lSize = this.partList.size();
        int rSize = p.partList.size();

        // no match possible for empty sets
        if ((lSize == 0) || (rSize == 0)) {
            return 0;
        }

        int minLen = (lSize <= rSize) ? lSize : rSize;
        int match = 0;

        // loop from the end to the front
        for (int i = 1; i <= minLen; i++) {
            String l = this.partList.get(lSize - i);
            String r = p.partList.get(rSize - i);

            if (equalityCheck(l, r)) {
                match++;
            } else {
                break;
            }
        }
        return match;
    }
@Test
    public void testTailMatch() {
        {
            ElementPath p = new ElementPath("/a/b");
            ElementSelector ruleElementSelector = new ElementSelector("*");
            assertEquals(0, ruleElementSelector.getTailMatchLength(p));
        }

        {
            ElementPath p = new ElementPath("/a");
            ElementSelector ruleElementSelector = new ElementSelector("*/a");
            assertEquals(1, ruleElementSelector.getTailMatchLength(p));
        }

        {
            ElementPath p = new ElementPath("/A");
            ElementSelector ruleElementSelector = new ElementSelector("*/a");
            assertEquals(1, ruleElementSelector.getTailMatchLength(p));
        }

        {
            ElementPath p = new ElementPath("/a");
            ElementSelector ruleElementSelector = new ElementSelector("*/A");
            assertEquals(1, ruleElementSelector.getTailMatchLength(p));
        }

        {
            ElementPath p = new ElementPath("/a/b");
            ElementSelector ruleElementSelector = new ElementSelector("*/b");
            assertEquals(1, ruleElementSelector.getTailMatchLength(p));
        }

        {
            ElementPath p = new ElementPath("/a/B");
            ElementSelector ruleElementSelector = new ElementSelector("*/b");
            assertEquals(1, ruleElementSelector.getTailMatchLength(p));
        }

        {
            ElementPath p = new ElementPath("/a/b/c");
            ElementSelector ruleElementSelector = new ElementSelector("*/b/c");
            assertEquals(2, ruleElementSelector.getTailMatchLength(p));
        }
    }