org.basex.query.value
Class Value

java.lang.Object
  extended by org.basex.data.ExprInfo
      extended by org.basex.query.expr.Expr
          extended by org.basex.query.value.Value
All Implemented Interfaces:
java.lang.Iterable<Item>
Direct Known Subclasses:
Empty, Item, Seq

public abstract class Value
extends Expr
implements java.lang.Iterable<Item>

Abstract value. This class also implements the Iterable interface, which is why all of its values can also be retrieved via enhanced for (for-each) loops. The default iter() method will provide better performance.

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

Nested Class Summary
 
Nested classes/interfaces inherited from class org.basex.query.expr.Expr
Expr.Flag
 
Field Summary
 Type type
          Data type.
 
Constructor Summary
Value(Type t)
          Constructor.
 
Method Summary
 boolean accept(ASTVisitor visitor)
          Traverses this expression, notifying the visitor of declared and used variables, and checking the tree for other recursive properties.
 ValueBuilder cache()
          Creates an ValueBuilder, containing all items of this value.
 void checkUp()
          Checks if all updating expressions are correctly placed.
 Value compile(QueryContext ctx, VarScope scp)
          Compiles and optimizes the expression, assigns data types and cardinalities.
 Value copy(QueryContext ctx, VarScope scp, IntObjMap<Var> vs)
          Copies an expression.
 VarUsage count(Var v)
          Checks how often a variable is used in this expression.
 Data data()
          Returns the data reference (if) attached to this value.
 java.lang.String description()
          Returns a string description of the expression.
 int exprSize()
          Counts the number of expressions in this expression's sub-tree.
 boolean has(Expr.Flag flag)
          Indicates if an expression has the specified compiler property.
abstract  int hash(InputInfo ii)
          Returns a hash code for this value.
abstract  boolean homogeneous()
          Checks if all items of this value share the same type.
 Expr inline(QueryContext ctx, VarScope scp, Var v, Expr e)
          Inlines an expression into this one, replacing all references to the given variable.
 boolean isValue()
          Tests if this is a value.
abstract  Item itemAt(long pos)
          Gets the item at the given position in the value.
abstract  ValueIter iter()
          Returns an iterator.
 ValueIter iter(QueryContext ctx)
          Evaluates the expression and returns an iterator on the resulting items.
 java.util.Iterator<Item> iterator()
           
 boolean removable(Var v)
          Checks if the specified variable is replaceable by a context item.
 ArrayOutput serialize()
          Serializes the value, using the standard XML serializer, and returns the cached result.
abstract  long size()
          Returns the sequence size or 1.
abstract  java.lang.Object toJava()
          Returns a Java representation of the value.
 Value value(QueryContext ctx)
          Evaluates the expression and returns the resulting value.
abstract  int writeTo(Item[] arr, int start)
          Writes this value's items out to the given array.
 
Methods inherited from class org.basex.query.expr.Expr
addText, compEbv, copy, ebv, hasFreeVars, indexAccessible, indexEquivalent, inlineAll, isEmpty, isFunction, isItem, isVacuous, item, iterable, markTailCalls, optimize, sameAs, test, type, uses, visitAll
 
Methods inherited from class org.basex.data.ExprInfo
addPlan, addPlan, info, plan, planAttr, planElem, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

public Type type
Data type.

Constructor Detail

Value

public Value(Type t)
Constructor.

Parameters:
t - data type
Method Detail

checkUp

public final void checkUp()
Description copied from class: Expr
Checks if all updating expressions are correctly placed. This function is only called if any updating expression was found in the query.

Specified by:
checkUp in class Expr

compile

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

Specified by:
compile in class Expr
Parameters:
ctx - query context
scp - variable scope
Returns:
optimized expression

iter

public final ValueIter iter(QueryContext ctx)
Description copied from class: Expr
Evaluates the expression and returns an iterator on the resulting items. If this method is not overwritten, Expr.item(org.basex.query.QueryContext, org.basex.util.InputInfo) must be implemented by an expression, as it may be called by this method.

Specified by:
iter in class Expr
Parameters:
ctx - query context
Returns:
resulting item

iterator

public final java.util.Iterator<Item> iterator()
Specified by:
iterator in interface java.lang.Iterable<Item>

iter

public abstract ValueIter iter()
Returns an iterator.

Returns:
iterator

value

public final Value value(QueryContext ctx)
Description copied from class: Expr
Evaluates the expression and returns the resulting value.

Specified by:
value in class Expr
Parameters:
ctx - query context
Returns:
iterator

data

public Data data()
Returns the data reference (if) attached to this value. This method is overwritten by DBNode and DBNodeSeq.

Returns:
data reference

isValue

public final boolean isValue()
Description copied from class: Expr
Tests if this is a value.

Overrides:
isValue in class Expr
Returns:
result of check

size

public abstract long size()
Description copied from class: Expr
Returns the sequence size or 1.

Specified by:
size in class Expr
Returns:
result of check

toJava

public abstract java.lang.Object toJava()
                                 throws QueryException
Returns a Java representation of the value.

Returns:
Java object
Throws:
QueryException - query exception

has

public boolean has(Expr.Flag flag)
Description copied from class: Expr
Indicates if an expression has the specified compiler property. This method is called by numerous Expr.compile(org.basex.query.QueryContext, org.basex.query.var.VarScope) methods to test properties of sub-expressions. It returns true if at least one test is successful.

Specified by:
has in class Expr
Parameters:
flag - flag to be found
Returns:
result of check

removable

public final boolean removable(Var v)
Description copied from class: Expr
Checks if the specified variable is replaceable by a context item. The following tests might return false: This method is called by GFLWOR.compile(org.basex.query.QueryContext, org.basex.query.var.VarScope) to rewrite where clauses into predicates.

Specified by:
removable in class Expr
Parameters:
v - variable to be replaced
Returns:
result of check

count

public final VarUsage count(Var v)
Description copied from class: Expr
Checks how often a variable is used in this expression.

Specified by:
count in class Expr
Parameters:
v - variable to look for
Returns:
how often the variable is used, see VarUsage

inline

public Expr inline(QueryContext ctx,
                   VarScope scp,
                   Var v,
                   Expr e)
            throws QueryException
Description copied from class: Expr
Inlines an expression into this one, replacing all references to the given variable.

Specified by:
inline in class Expr
Parameters:
ctx - query context for recompilation
scp - variable scope for recompilation
v - variable to replace
e - expression to inline
Returns:
resulting expression in something changed, null otherwise
Throws:
QueryException - query exception

copy

public Value 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

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

hash

public abstract int hash(InputInfo ii)
                  throws QueryException
Returns a hash code for this value.

Parameters:
ii - input info
Returns:
hash code
Throws:
QueryException - if atomization can't be applied (e.g. function item)

writeTo

public abstract int writeTo(Item[] arr,
                            int start)
Writes this value's items out to the given array.

Parameters:
arr - array to write to
start - start position
Returns:
number of written items

cache

public final ValueBuilder cache()
Creates an ValueBuilder, containing all items of this value. Use with care, as compressed Values are expanded, creating many objects.

Returns:
cached items

serialize

public final ArrayOutput serialize()
                            throws QueryException
Serializes the value, using the standard XML serializer, and returns the cached result.

Returns:
serialized value
Throws:
QueryException - query exception

itemAt

public abstract Item itemAt(long pos)
Gets the item at the given position in the value.

Parameters:
pos - position
Returns:
item

homogeneous

public abstract boolean homogeneous()
Checks if all items of this value share the same type.

Returns:
result of check

accept

public boolean accept(ASTVisitor visitor)
Description copied from class: Expr
Traverses this expression, notifying the visitor of declared and used variables, and checking the tree for other recursive properties.

Specified by:
accept in class Expr
Parameters:
visitor - visitor
Returns:
if the walk should be continued

exprSize

public final int exprSize()
Description copied from class: Expr
Counts the number of expressions in this expression's sub-tree.

Specified by:
exprSize in class Expr
Returns:
number of expressions