org.basex.query.expr
Class CmpG

java.lang.Object
  extended by org.basex.data.ExprInfo
      extended by org.basex.query.expr.Expr
          extended by org.basex.query.expr.ParseExpr
              extended by org.basex.query.expr.Arr
                  extended by org.basex.query.expr.Cmp
                      extended by org.basex.query.expr.CmpG

public final class CmpG
extends Cmp

General comparison.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Nested Class Summary
static class CmpG.OpG
          Comparators.
 
Nested classes/interfaces inherited from class org.basex.query.expr.Expr
Expr.Flag
 
Field Summary
 
Fields inherited from class org.basex.query.expr.Arr
expr
 
Fields inherited from class org.basex.query.expr.ParseExpr
info, size, type
 
Constructor Summary
CmpG(Expr e1, Expr e2, CmpG.OpG o, InputInfo ii)
          Constructor.
 
Method Summary
 Expr compEbv(QueryContext ctx)
          This method is overwritten by CmpG, CmpV and FNSimple.
 Expr compile(QueryContext ctx, VarScope scp)
          Compiles and optimizes the expression, assigns data types and cardinalities.
 Expr copy(QueryContext ctx, VarScope scp, IntObjMap<Var> vs)
          Copies an expression.
 java.lang.String description()
          Returns a string description of the expression.
 boolean indexAccessible(IndexCosts ic)
          Checks if an expression can be rewritten to an index access.
 Expr indexEquivalent(IndexCosts ic)
          Returns an equivalent expression which accesses an index structure.
static Step indexStep(Expr expr)
          If possible, returns the last location step of the specified expression.
 CmpG invert()
          If possible, inverts the operands of the expression.
 Bln item(QueryContext ctx, InputInfo ii)
          Evaluates the expression and returns the resulting item or a null reference, if the expression yields an empty sequence.
 Expr optimize(QueryContext ctx, VarScope scp)
          Optimizes an already compiled expression without recompiling its sub-expressions.
 void plan(FElem plan)
          Creates an expression tree.
 java.lang.String toString()
           
 
Methods inherited from class org.basex.query.expr.Arr
accept, allAreValues, checkNoUp, checkUp, copyAll, count, exprSize, has, inline, removable, toString
 
Methods inherited from class org.basex.query.expr.ParseExpr
checkAdmin, checkAllUp, checkBinary, checkBln, checkColl, checkCreate, checkCtx, checkDbl, checkDBNode, checkEStr, checkEStr, checkFunc, checkItem, checkItr, checkItr, checkMap, checkNode, checkNode, checkNode, checkNoEmpty, checkNoneUp, checkNoUp, checkQNm, checkStr, checkStr, checkStrBin, checkType, checkWrite, compBln, copyType, ebv, iter, optPre, preEval, size, test, type, value
 
Methods inherited from class org.basex.query.expr.Expr
addText, copy, hasFreeVars, inlineAll, isEmpty, isFunction, isItem, isVacuous, isValue, iterable, markTailCalls, sameAs, uses, visitAll
 
Methods inherited from class org.basex.data.ExprInfo
addPlan, addPlan, info, planAttr, planElem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmpG

public CmpG(Expr e1,
            Expr e2,
            CmpG.OpG o,
            InputInfo ii)
Constructor.

Parameters:
e1 - first expression
e2 - second expression
o - operator
ii - input info
Method Detail

compile

public Expr compile(QueryContext ctx,
                    VarScope scp)
             throws QueryException
Description copied from class: Expr
Compiles and optimizes the expression, assigns data types and cardinalities.

Overrides:
compile in class Arr
Parameters:
ctx - query context
scp - variable scope
Returns:
optimized expression
Throws:
QueryException - query exception

optimize

public Expr optimize(QueryContext ctx,
                     VarScope scp)
              throws QueryException
Description copied from class: Expr
Optimizes an already compiled expression without recompiling its sub-expressions.

Overrides:
optimize in class Expr
Parameters:
ctx - query context
scp - variable scope
Returns:
optimized expression
Throws:
QueryException - query exception

compEbv

public Expr compEbv(QueryContext ctx)
Description copied from class: Expr

This method is overwritten by CmpG, CmpV and FNSimple. It is called at compile time by expressions that perform effective boolean value tests (e.g. If or Preds). If the arguments of the called expression return a boolean anyway, the expression will be simplified.

Example in CmpV: if($x eq true()) is rewritten to if($x), if $x is known to return a single boolean.

Overrides:
compEbv in class Expr
Parameters:
ctx - query context
Returns:
optimized expression

item

public Bln item(QueryContext ctx,
                InputInfo ii)
         throws QueryException
Description copied from class: Expr
Evaluates the expression and returns the resulting item or a null reference, if the expression yields an empty sequence. If this method is not overwritten, Expr.iter(org.basex.query.QueryContext) must be implemented by an expression, as it may be called by this method.

Overrides:
item in class ParseExpr
Parameters:
ctx - query context
ii - input info
Returns:
iterator
Throws:
QueryException - query exception

invert

public CmpG invert()
Description copied from class: Cmp
If possible, inverts the operands of the expression.

Specified by:
invert in class Cmp
Returns:
original or modified expression

indexAccessible

public boolean indexAccessible(IndexCosts ic)
                        throws QueryException
Description copied from class: Expr
Checks if an expression can be rewritten to an index access. If this method is implemented, Expr.indexEquivalent(org.basex.query.util.IndexCosts) must be implemented as well.

Overrides:
indexAccessible in class Expr
Parameters:
ic - index costs analyzer
Returns:
true if an index can be used
Throws:
QueryException - query exception

indexEquivalent

public Expr indexEquivalent(IndexCosts ic)
Description copied from class: Expr
Returns an equivalent expression which accesses an index structure. Will be called if Expr.indexAccessible(org.basex.query.util.IndexCosts) is returns true for an expression.

Overrides:
indexEquivalent in class Arr
Parameters:
ic - index costs analyzer
Returns:
equivalent index-expression

indexStep

public static Step indexStep(Expr expr)
If possible, returns the last location step of the specified expression.

Parameters:
expr - expression
Returns:
location step

copy

public Expr copy(QueryContext ctx,
                 VarScope scp,
                 IntObjMap<Var> vs)
Description copied from class: Expr
Copies an expression. Will be useful for inlining functions, or for copying static queries.

Specified by:
copy in class Expr
Parameters:
ctx - query context
scp - variable scope for creating new variables
vs - mapping from old variable IDs to new variable copies
Returns:
copied expression

plan

public void plan(FElem plan)
Description copied from class: ExprInfo
Creates an expression tree.

Overrides:
plan in class Arr
Parameters:
plan - root element

description

public java.lang.String description()
Description copied from class: ExprInfo
Returns a string description of the expression. This method is only called by error messages. Contrary to the ExprInfo.toString() method, arguments are not included in the output.

Overrides:
description in class ExprInfo
Returns:
result of check

toString

public java.lang.String toString()
Specified by:
toString in class ExprInfo