public static TupleExpr process(TupleExpr query,List<ExternalTupleSet> indexSet){
  boolean indexPlaced=false;
  TupleExpr rtn=query.clone();
  QueryNodeCount qnc=new QueryNodeCount();
  rtn.visit(qnc);
  if (qnc.getNodeCount() / 2 < indexSet.size()) {
    return null;
  }
  organizeBSAs(rtn);
  if (isTupleValid(rtn)) {
    for (    ExternalTupleSet index : indexSet) {
      if (isTupleValid(index.getTupleExpr())) {
        ExternalTupleSet eTup=(ExternalTupleSet)index.clone();
        SPBubbleDownVisitor indexVistor=new SPBubbleDownVisitor(eTup);
        rtn.visit(indexVistor);
        FilterBubbleManager fbmv=new FilterBubbleManager(eTup);
        rtn.visit(fbmv);
        SubsetEqualsVisitor subIndexVis=new SubsetEqualsVisitor(eTup,rtn);
        rtn.visit(subIndexVis);
        indexPlaced=subIndexVis.indexPlaced();
        if (!indexPlaced) {
          break;
        }
      }
    }
    if (indexPlaced) {
      return rtn;
    }
 else {
      return null;
    }
  }
 else {
    throw new IllegalArgumentException("Invalid Query.");
  }
}

public static TupleExpr process ( TupleExpr query , List < ExternalTupleSet > indexSet ) { boolean indexPlaced = false ; TupleExpr rtn = query . clone ( ) ; QueryNodeCount qnc = new QueryNodeCount ( ) ; rtn . visit ( qnc ) ; if ( qnc . getNodeCount ( ) / 2 < indexSet . size ( ) ) { return null ; } organizeBSAs ( rtn ) ; if ( isTupleValid ( rtn ) ) { for ( ExternalTupleSet index : indexSet ) { if ( isTupleValid ( index . getTupleExpr ( ) ) ) { ExternalTupleSet eTup = ( ExternalTupleSet ) index . clone ( ) ; SPBubbleDownVisitor indexVistor = new SPBubbleDownVisitor ( eTup ) ; rtn . visit ( indexVistor ) ; FilterBubbleManager fbmv = new FilterBubbleManager ( eTup ) ; rtn . visit ( fbmv ) ; SubsetEqualsVisitor subIndexVis = new SubsetEqualsVisitor ( eTup , rtn ) ; rtn . visit ( subIndexVis ) ; indexPlaced = subIndexVis . indexPlaced ( ) ; if ( ! indexPlaced ) { break ; } } } if ( indexPlaced ) { return rtn ; } else { return null ; } } else { throw new IllegalArgumentException ( "Invalid Query." ) ; } }
iterates through list of normalized indexes and replaces all subtrees of query which match index with index .
