public int getPrefixMatchLength(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;

    for (int i = 0; i < minLen; i++) {
      String l = this.partList.get(i);
      String r = p.partList.get(i);

      if (equalityCheck(l, r)) {
        match++;
      } else {
        break;
      }
    }

    return match;
  }
@Test
  public void testPrefixMatch() {
    {
      ElementPath p = new ElementPath("/a/b");
      ElementSelector ruleElementSelector = new ElementSelector("/x/*");
      assertEquals(0, ruleElementSelector.getPrefixMatchLength(p));
    }

    {
      ElementPath p = new ElementPath("/a");
      ElementSelector ruleElementSelector = new ElementSelector("/x/*");
      assertEquals(0, ruleElementSelector.getPrefixMatchLength(p));
    }

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

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

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

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

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