Predicate eachPred = null;
Object contextNode = null;
Object predResult = null;
Context predContext = new Context( support );
// Filter the 'filterSet' against all predicates. This has been
// tuned for performance, so there are two separate loops
// In the first run, all nodes matching the first predicate will
// be copied from contextNodeSet to newNodeSet
// In the second loop, newNodeSet is filtered progressively against
// the remaining predicates, eliminating any non-matching nodes
if ( predIter.hasNext() )
{
eachPred = (Predicate) predIter.next();
int filterSize = filterSet.size();
for ( int i = 0 ; i < filterSize ; ++i )
{
contextNode = filterSet.get( i );
List list = new ArrayList( 1 );
list.add( contextNode );
predContext.setNodeSet( list );
predContext.setPosition( i + 1 );
predContext.setSize( filterSize );
predResult = eachPred.evaluate( predContext );
if ( predResult instanceof Number )
{
int proximity = ((Number)predResult).intValue();
if ( proximity == ( i + 1 ) )
{
newNodeSet.add( contextNode );
}
}
else
{
Boolean includes = BooleanFunction.evaluate( predResult, predContext.getNavigator() );
if ( includes.booleanValue() )
{
newNodeSet.add( contextNode );
}
}
}
}
// This will be true if any filtering takes place from here on
boolean nodesFiltered = false;
// Second loop: Filter filterSet until no more predicates are left
filterSet = newNodeSet;
while ( predIter.hasNext() )
{
eachPred = (Predicate) predIter.next();
int filterSize = filterSet.size();
for ( int i = 0 ; i < filterSize ; ++i )
{
contextNode = filterSet.get(i);
// Check if a node has been eliminated already
if (contextNode == null) continue;
List list = new ArrayList( 1 );
list.add( contextNode );
predContext.setNodeSet( list );
predContext.setPosition( i + 1 );
predContext.setSize( filterSize );
predResult = eachPred.evaluate( predContext );
if ( predResult instanceof Number )
{
int proximity = ((Number)predResult).intValue();
if ( proximity != ( i + 1 ) )
{
filterSet.set(i,null);
nodesFiltered = true;
}
}
else
{
Boolean includes = BooleanFunction.evaluate( predResult, predContext.getNavigator() );
if ( !includes.booleanValue() )
{
filterSet.set(i,null);
nodesFiltered = true;