org.openanzo.glitter.syntax.abstrakt
Class TreeNode

java.lang.Object
  extended by org.openanzo.glitter.syntax.abstrakt.TreeNode
Direct Known Subclasses:
GraphPattern

public abstract class TreeNode
extends java.lang.Object

A TreeNode is the (abstract) base class for all nodes in the abstract syntax of a SPARQL query. TreeNodes also maintain a cache of properties calculated recursively over a node and its descendants.

Author:
Lee Feigenbaum

Constructor Summary
TreeNode()
           
 
Method Summary
abstract  void addChild(TreeNode child)
          Adds the given child at the end of this node's children.
 boolean containsVariable(Variable v)
           
 java.util.Map<Variable,java.lang.Integer> getBindableVariableCount()
           
 java.util.Set<Variable> getBindableVariableSet()
           
abstract  java.util.Iterator<? extends TreeNode> getChildren()
           
 java.util.Set<Expression> getFilters()
          Default implementation of getFilters().
 java.util.Set<Expression> getInScopeFilterSet()
           
 TreeNode getParent()
           
 TreeNode getRoot()
           
 java.util.Map<Variable,java.lang.Integer> getVariableCount()
           
 java.util.Set<Variable> getVariableSet()
           
 void invalidateCache()
          Invalidate the entire cache.
 void invalidateCache(java.lang.String key)
          Clear the cache corresponding to the given key
 boolean mightBindVariable(Variable v)
           
 void prettyPrint(java.lang.StringBuffer output)
          Pretty prints this tree node to the given StringBuffer.
 void prettyPrint(java.lang.StringBuffer output, boolean deep)
          Pretty prints this tree node to the given StringBuffer.
abstract  boolean removeChild(TreeNode child)
          Removes the given child from the collection of children
abstract  boolean replaceChild(TreeNode oldChild, TreeNode newChild)
          Changes the tree below this node by replacing oldChild with newChild
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeNode

public TreeNode()
Method Detail

invalidateCache

public void invalidateCache(java.lang.String key)
Clear the cache corresponding to the given key

Parameters:
key -

invalidateCache

public void invalidateCache()
Invalidate the entire cache.


getParent

public TreeNode getParent()
Returns:
The parent of this TreeNode. If this is the root of a query, returns null.

getChildren

public abstract java.util.Iterator<? extends TreeNode> getChildren()
Returns:
An Iterator over the children of this node.

replaceChild

public abstract boolean replaceChild(TreeNode oldChild,
                                     TreeNode newChild)
Changes the tree below this node by replacing oldChild with newChild

Parameters:
oldChild -
newChild -
Returns:
true if the oldChild was found and replaced; false otherwise.

removeChild

public abstract boolean removeChild(TreeNode child)
Removes the given child from the collection of children

Parameters:
child -
Returns:
true if the child was found and removed; false otherwise.

addChild

public abstract void addChild(TreeNode child)
Adds the given child at the end of this node's children.

Parameters:
child -

containsVariable

public final boolean containsVariable(Variable v)
Parameters:
v -
Returns:
whether or not this node and its subtree contains Variable v.

mightBindVariable

public final boolean mightBindVariable(Variable v)
Parameters:
v -
Returns:
whether or not this node and its subtree contains Variable v in a position that it could receive bindings (e.g., a variable in a FILTER cannot receive bindings, but a variable in the GRAPH clause can.

getVariableCount

public final java.util.Map<Variable,java.lang.Integer> getVariableCount()
Returns:
A map from variables to counts for all variables that appear in this node and its descendants.

getBindableVariableCount

public final java.util.Map<Variable,java.lang.Integer> getBindableVariableCount()
Returns:
A map from variables to counts for all variables that appear in this node and its descendants. This only counts instances of Variables that can receive bindings. (As in mightBindVariable(Variable).

getVariableSet

public final java.util.Set<Variable> getVariableSet()
Returns:
A set of all variables that occur in this node and its descendants.

getBindableVariableSet

public final java.util.Set<Variable> getBindableVariableSet()
Returns:
A set of all variables that occur in this node and its descendants that may receive bindings.

getRoot

public final TreeNode getRoot()
Returns:
The root of the tree that contains this TreeNode.

getInScopeFilterSet

public final java.util.Set<Expression> getInScopeFilterSet()
Returns:
A set of all filters Expressions that are in scope (act on the bindings) for this tree node.

getFilters

public java.util.Set<Expression> getFilters()
Default implementation of getFilters(). Most tree nodes cannot contain filters.

Returns:
Default implementation of getFilters().

prettyPrint

public void prettyPrint(java.lang.StringBuffer output)
Pretty prints this tree node to the given StringBuffer.

Parameters:
output -

prettyPrint

public void prettyPrint(java.lang.StringBuffer output,
                        boolean deep)
Pretty prints this tree node to the given StringBuffer.

Parameters:
output -
deep - If true, recurse into descendants. Otherwise, includes an elipsis ("...") for any children.


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.