Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2009 Mysema Ltd.
  * All rights reserved.
  * 
  */
 package com.mysema.rdfbean.sesame.query;
 
 
import  org.openrdf.query.algebra.Exists;
import  org.openrdf.query.algebra.Not;
import  org.openrdf.query.algebra.ValueExpr;
import  org.openrdf.query.algebra.Var;
ColSizeTransformer provides

Author(s):
tiwe
Version:
$Id$
public class ColSizeTransformer implements OperationTransformer{
    @Override
    public Collection<? extends Operator<?>> getSupportedOperations() {
        throw new UnsupportedOperationException();
    }
    @SuppressWarnings("unchecked")
    @Override
    public ValueExpr transform(Operation<?, ?> operationTransformerContext context) {
        Operator<?> op = operation.getOperator();
        int size = ((Constant<Integer>) operation.getArg(1)).getConstant().intValue();
        if (op == .){
            op = .;
            size--;
        }else if (op == .){
            op = .;
            size++;
        }
        
        JoinBuilder builder = context.createJoinBuilder();
        // path from size operation
        Path<?> path = (Path<?>)((Operation<?,?>)operation.getArg(0)).getArg(0); 
        Var pathVar = context.toVar(path);                                
        for (int i=0; i < size-1; i++){
            Var rest = context.createVar();
            context.match(builderpathVar.rest);
            pathVar = rest;
        }
        
        // last
        if (op == .){
            context.match(builderpathVar.context.toVar(.));
            
        }else if (op == .){
            Var next = context.createVar();
            context.match(builderpathVar.next);
            context.match(buildernext.context.createVar());
            
        }else if (op == .){
            context.match(builderpathVar.context.createVar());
        }          
        
        if (op != .){
            return new Exists(builder.getTupleExpr());    
        }else{
            return new Not(new Exists(builder.getTupleExpr()));
        }    
    }
New to GrepCode? Check out our FAQ X