{
// compact this
MergingPathQueryNode compacted = new MergingPathQueryNode(QueryNode.TYPE_OR, getValidJcrSystemNodeTypeNames());
for (Iterator<QueryNode> it = operands.iterator(); it.hasNext();)
{
LocationStepQueryNode step = (LocationStepQueryNode)it.next();
if (step.getIncludeDescendants() && step.getNameTest() == null)
{
// check if has next
if (it.hasNext())
{
LocationStepQueryNode next = (LocationStepQueryNode)it.next();
next.setIncludeDescendants(true);
compacted.addPathStep(next);
}
else
{
compacted.addPathStep(step);
}
}
else
{
compacted.addPathStep(step);
}
}
MergingPathQueryNode matchedNode = null;
for (int i = 0; i < nodes.length; i++)
{
// loop over the steps and compare the names
if (nodes[i].operands.size() == compacted.operands.size())
{
boolean match = true;
Iterator<QueryNode> compactedSteps = compacted.operands.iterator();
Iterator<QueryNode> otherSteps = nodes[i].operands.iterator();
while (match && compactedSteps.hasNext())
{
LocationStepQueryNode n1 = (LocationStepQueryNode)compactedSteps.next();
LocationStepQueryNode n2 = (LocationStepQueryNode)otherSteps.next();
match &=
(n1.getNameTest() == null) ? n2.getNameTest() == null : n1.getNameTest().equals(n2.getNameTest());
}
if (match)
{
matchedNode = nodes[i];
break;