public interface

WebExpressionHelper

com.microstrategy.web.objects.WebExpressionHelper
Known Indirect Subclasses

Class Overview

The WebExpressionHelper interface is a helper interface which is used to manipulate the expression tree with multi-step, complex manipulations. All of these manipulations can be done by using the WebExpression/WebNode interfaces, but this class simplifies the performance of many of those operations. This object can be obtained from a WebExpression instance, and is linked to that instance.

Summary

Public Methods
abstract boolean canEditExpression()
abstract boolean canGroup(int firstKey, int secondKey)
Check whether it is possible to call group() on the two nodes with the given keys.
abstract boolean canGroup(WebNode firstNode, WebNode secondNode)
Check whether it is possible to call group() on the two given nodes.
abstract boolean canSwapWithNext(int nodeKey)
Checks whether it is possible to call swapWithNext() on the node with the given key.
abstract boolean canSwapWithNext(WebNode node)
Checks whether it is possible to call swapWithNext() on the given node.
abstract boolean canSwapWithPrevious(WebNode node)
Checks whether it is possible to call swapWithPrevious() on the given node.
abstract boolean canSwapWithPrevious(int nodeKey)
Checks whether it is possible to call swapWithPrevious() on the node with the given key.
abstract boolean canUngroup(int firstKey, int secondKey)
Check whether it is possible to call ungroup() on the two nodes with the given keys.
abstract boolean canUngroup(WebNode firstNode, WebNode secondNode)
Check whether it is possible to call ungroup() on the two given nodes.
abstract boolean compareTo(WebExpression anotherExp)
Compares two WebExpression.
abstract void consolidateTree()
Consolidates the whole expression tree.
abstract void delete(int nodeKey)
Delete the node with the given key from the expression.
abstract void delete(WebNode node)
Delete the specified node from the expression.
abstract boolean getAutoConsolidation()
Return the current setting for the auto-consolidation option.
abstract WebOperatorNode getNewRootNode()
Creates a new root node for the underlying WebExpression.
abstract WebNode group(int firstKey, int secondKey)
Group two nodes in the expression together.
abstract WebNode group(WebNode firstNode, WebNode secondNode)
Group two nodes in the expression together.
abstract boolean hasFilterOn(WebObjectInfo oi)
Returns whether the expression contains an qualification on specified object
abstract boolean isEqual(WebNode n1, WebNode n2)
Checks whether two WebNode are equal.
abstract WebExpression removeEmptyFilters()
This method will take the current expression tree and attempt to remove any empty filters in the expression.
abstract void setAutoConsolidation(boolean auto)
Sets the auto-consolidation option on this instance.
abstract void swap(int firstKey, int secondKey)
Swap two nodes in the expression.
abstract void swap(WebNode firstNode, WebNode secondNode)
Swap two nodes in the expression.
abstract void swapWithNext(int nodeKey)
Swaps the node with the given key with its next sibling.
abstract void swapWithNext(WebNode node)
Swaps the given node with its next sibling.
abstract void swapWithPrevious(int nodeKey)
Swaps the node with the given key with the previous sibling.
abstract void swapWithPrevious(WebNode node)
Swaps the given node with the previous sibling.
abstract void toggleFunction(int firstKey, int secondKey, int toggleFunction)
Change the function between the two nodes with the given keys to the specified function.
abstract void toggleFunction(WebNode firstNode, WebNode secondNode, int toggleFunction)
Change the function between the two given nodes to the specified function.
abstract void ungroup(WebNode firstNode, WebNode secondNode)
Ungroup two nodes in the expression.
abstract void ungroup(int firstKey, int secondKey)
Ungroup two nodes in the expression.
abstract boolean validateOperands(WebNode node, RWDataSet ds)
Returns whether the given node and its children are valid.

Public Methods

public abstract boolean canEditExpression ()

public abstract boolean canGroup (int firstKey, int secondKey)

Check whether it is possible to call group() on the two nodes with the given keys.

Parameters
firstKey The key of the first node.
secondKey The key of the second node.
Returns
  • True if calling group() on the two given nodes will not cause an error, or false if it is not possible to group the two given nodes.
Throws
IllegalArgumentException Thrown if either key does not exist in the expression.

public abstract boolean canGroup (WebNode firstNode, WebNode secondNode)

Check whether it is possible to call group() on the two given nodes.

Parameters
firstNode The first node.
secondNode The second node.
Returns
  • True if calling group() on the two given nodes will not cause an error, or false if it is not possible to group the two given nodes.
Throws
IllegalArgumentException Thrown if either input parameter is null.

public abstract boolean canSwapWithNext (int nodeKey)

Checks whether it is possible to call swapWithNext() on the node with the given key.

Parameters
nodeKey The key of the node to be swapped.
Returns
  • True if swapWithNext will not cause an error, false otherwise.
Throws
IllegalArgumentException Thrown if the node parameter is null.

public abstract boolean canSwapWithNext (WebNode node)

Checks whether it is possible to call swapWithNext() on the given node.

Parameters
node The node to be swapped.
Returns
  • True if swapWithNext will not cause an error, false otherwise.
Throws
IllegalArgumentException Thrown if the node parameter is null.

public abstract boolean canSwapWithPrevious (WebNode node)

Checks whether it is possible to call swapWithPrevious() on the given node.

Parameters
node The node to be swapped.
Returns
  • True if swapWithPrevious will not cause an error, false otherwise.
Throws
IllegalArgumentException Thrown if the node parameter is null.

public abstract boolean canSwapWithPrevious (int nodeKey)

Checks whether it is possible to call swapWithPrevious() on the node with the given key.

Parameters
nodeKey The key of the node to be swapped.
Returns
  • True if swapWithPrevious will not cause an error, false otherwise.
Throws
IllegalArgumentException Thrown if the node parameter is null.

public abstract boolean canUngroup (int firstKey, int secondKey)

Check whether it is possible to call ungroup() on the two nodes with the given keys.

Parameters
firstKey The key of the first node.
secondKey The key of the second node.
Returns
  • True if calling ungroup() on the two given nodes will not cause an error, or false if it is not possible to ungroup the two given nodes.
Throws
IllegalArgumentException Thrown if either key does not exist in the expression.

public abstract boolean canUngroup (WebNode firstNode, WebNode secondNode)

Check whether it is possible to call ungroup() on the two given nodes.

Parameters
firstNode The first node.
secondNode The second node.
Returns
  • True if calling ungroup() on the two given nodes will not cause an error, or false if it is not possible to ungroup the two given nodes.
Throws
IllegalArgumentException Thrown if either input parameter is null.

public abstract boolean compareTo (WebExpression anotherExp)

Compares two WebExpression. The comparison is based on the structure of each root node in the expressions.

Note that this method is currently used to compare the expressions which are used in derived elements editor.

Parameters
anotherExp the WebExpression to be compared..
Returns
  • true if this expression is the same as the anotherExp argument; false otherwise.

public abstract void consolidateTree ()

Consolidates the whole expression tree.

Consolidation rules:

  1. Any branch qualification (AND, OR, or NOT) which has no child nodes will be removed.
  2. Branch qualifications (AND, OR), which have 1 child node will be removed and the tree adjusted such that the expression's meaning will not be changed.
  3. If a NOT node has a NOT node as it's child node, both not nodes will be removed.
  4. Any AND or OR node, can not have its first child as NOT node,
    1. If the first child is a NOT node,
      1. if there is at least one non-NOT child, try to swap with the first non-NOT child
      2. else, create a NOT node, move current AND or OR node under the NOT node, then change the AND to OR, OR to AND, then replace all NOT children with their children. Eg. (NOT A AND NOT B) -> NOT (A OR B)

Note that this operation will be performed on the tree after every operation if the auto-consolidation setting is true.

public abstract void delete (int nodeKey)

Delete the node with the given key from the expression. If it is the root node of the expression, this method will do nothing.

Parameters
nodeKey The key of the node to be deleted.
Throws
IllegalArgumentException Thrown if the key is not found in the expression.

public abstract void delete (WebNode node)

Delete the specified node from the expression. If it is the root node of the expression, this method will do nothing.

Parameters
node The node to be deleted.
Throws
IllegalArgumentException Thrown if the input parameter is null.

public abstract boolean getAutoConsolidation ()

Return the current setting for the auto-consolidation option. When the auto-consolidation setting is on, a consolidation of the expression tree will be done after every other manipulation on this interface. See the consolidateTree method for the effects of a consolidation operation. By default, this option is true.

Returns
  • The current setting for auto-consolidation.

public abstract WebOperatorNode getNewRootNode ()

Creates a new root node for the underlying WebExpression. The new root node has function EnumDSSXMLFunction.DssXmlFunctionAnd and expression type EnumDSSXMLExpressionType.DssXmlFilterBranchQual. If the specified WebExpression has any sub expression originally, the sub expression becomes the first child of the new root node after the method call returns.

Returns
  • a new root node for the specified expression object.

public abstract WebNode group (int firstKey, int secondKey)

Group two nodes in the expression together. This method is used to identify the nodes by the key of the expression. The two nodes given must either share a parent node or for the first node and the parent node of the second child (which must be a NOT node) share a common parent node. In the second case, the operator will be considered to be the parent and the not node combined(i.e. AND NOT or OR NOT). This method will create a new node, which will have the same function (AND or OR) as the original parent of these two nodes. The new node is inserted at the position of the first given node, and the two given nodes will be set as child nodes of the newly created node.

Parameters
firstKey The key of the first node.
secondKey The key of the second node. the parent node must be a NOT node, and that node must share a parent with the firstNode.
Returns
  • The new parent node of the two given nodes.
Throws
WebObjectsException Thrown when the parent of one child is not a branch qualification operator, when these children do not share the same parent, or when one of the input nodes is the root node of the expression.
IllegalArgumentException Thrown if either input parameter is null.

public abstract WebNode group (WebNode firstNode, WebNode secondNode)

Group two nodes in the expression together. The two nodes given must either share a parent node or for the first node and the parent node of the second child (which must be a NOT node) share a common parent node. In the second case, the operator will be considered to be the parent and the not node combined(i.e. AND NOT or OR NOT). This method will create a new node, which will have the same function (AND or OR) as the original parent of these two nodes. The new node is inserted at the position of the first given node, and the two given nodes will be set as child nodes of the newly created node.

Parameters
firstNode The first input parameter, which must share a parent with secondNode
secondNode The second input parameter, which must either share a parent with firstNode or the parent node must be a NOT node, and that node must share a parent with the firstNode.
Returns
  • The new parent node of the two given nodes.
Throws
WebObjectsException Thrown when the parent of one child is not a branch qualification operator, when these children do not share the same parent, or when one of the input nodes is the root node of the expression.
IllegalArgumentException Thrown if either input parameter is null.

public abstract boolean hasFilterOn (WebObjectInfo oi)

Returns whether the expression contains an qualification on specified object

public abstract boolean isEqual (WebNode n1, WebNode n2)

Checks whether two WebNode are equal.

Note that this method is currently used to compare the expressions which are used in derived elements editor.

Parameters
n1 the first WebNode to check equality
n2 the second WebNode to check equality
Returns
  • true if the two WebNode are the same; false otherwise.

public abstract WebExpression removeEmptyFilters ()

This method will take the current expression tree and attempt to remove any empty filters in the expression. After doing that, it will consolidate the new expression. This method, if it is necessary to change the expresssion, will return a copy of the current expression; the expression that belongs to this WebExpressionHelper object will never be modified.

Returns
  • Either the current expression, if no change was needed, or a copy of the current expression that has empty filters removed and is consolidated.

public abstract void setAutoConsolidation (boolean auto)

Sets the auto-consolidation option on this instance. When the auto-consolidation setting is on, a consolidation of the expression tree will be done after every other manipulation on this interface. See the consolidateTree method for the effects of a consolidation operation.

Parameters
auto The desired setting for auto-consolidation.

public abstract void swap (int firstKey, int secondKey)

Swap two nodes in the expression. These two nodes can be anywhere in the expression tree. After calling this method, the two nodes' locations will be swapped.

Parameters
firstKey The key of the first node to be swapped.
secondKey The key of the second node to be swapped.
Throws
IllegalArgumentException Thrown when one of the keys do not exist in the expression tree.

public abstract void swap (WebNode firstNode, WebNode secondNode)

Swap two nodes in the expression. These two nodes can be anywhere in the expression tree. After calling this method, the two nodes' locations will be swapped.

Parameters
firstNode The first node to be swapped.
secondNode The second node to be swapped.
Throws
IllegalArgumentException Thrown when the input parameter is null.

public abstract void swapWithNext (int nodeKey)

Swaps the node with the given key with its next sibling. This only works if the given node is not the last child of it's parent node.

There are two special cases:

  • If the parent node is a NOT node, swap the given node with the NOT node's next sibling.
  • If the next sibling is a NOT node, swap the given node with its child.

Parameters
nodeKey The key of the node to be swapped.
Throws
WebObjectsException Thrown if the parent of the given node is not a branch qualification operator or when there is no previous sibling to swap with.
IllegalArgumentException Thrown if no node with the given key exists.

public abstract void swapWithNext (WebNode node)

Swaps the given node with its next sibling. This only works if the given node is not the last child of it's parent node.

There are two special cases:

  • If the parent node is a NOT node, swap the given node with the NOT node's next sibling.
  • If the next sibling is a NOT node, swap the given node with its child.

Parameters
node The node to be swapped.
Throws
WebObjectsException Thrown if the parent of the given node is not a branch qualification operator or when there is no previous sibling to swap with.
IllegalArgumentException Thrown when the input parameter is null.

public abstract void swapWithPrevious (int nodeKey)

Swaps the node with the given key with the previous sibling. This only works if the given node is not the first child of it's parent node.

There are two special cases:

  • If the parent node is a NOT node, swap the given node with the NOT node's previous sibling.
  • If the previous sibling is a NOT node, swap the given node with its child.

Parameters
nodeKey The key of the node to be swapped.
Throws
WebObjectsException Thrown if the parent of the given node is not a branch qualification operator or when there is no previous sibling to swap with.
IllegalArgumentException Thrown if no node with the given key exists.

public abstract void swapWithPrevious (WebNode node)

Swaps the given node with the previous sibling. This only works if the given node is not the first child of it's parent node.

There are two special cases:

  • If the parent node is a NOT node, swap the given node with the NOT node's previous sibling.
  • If the previous sibling is a NOT node, swap the given node with its child.

Parameters
node The node to be swapped.
Throws
WebObjectsException Thrown if the parent of the given node is not a branch qualification operator or when there is no previous sibling to swap with.
IllegalArgumentException Thrown when the input parameter is null.

public abstract void toggleFunction (int firstKey, int secondKey, int toggleFunction)

Change the function between the two nodes with the given keys to the specified function. The functions which are available come from EnumWebToggleFunction. Note that if AND NOT or OR NOT are the original operator, the node directly under the NOT node should be specified as the second argument to this method. These two nodes either should be the direct children of the same parent, or the second node must have a NOT node as its parent which shares a parent with the first argument.

For example, if there were an AND node, with children firstNode and a NOT node which has the secondNode as a child node, then the original function is considered to be AND NOT.

Each time, this function will add a new node for the new toggleFunction first. Then if the auto consolidation is set, it may remove the original function node (the shared parent of the two input nodes).

Parameters
firstKey The key of the first node whose parent operator will be toggled.
secondKey The key of the second node whose parent operator will be toggled.
toggleFunction The function to toggle to, which is a value from EnumWebToggleFunction.
Throws
WebObjectsException Thrown if the parent of the given nodes is not aa branch qualification operator, the two given nodes do not share the same parent, or if either the first node, second node, or the shared parent node are the root node of the expression.
IllegalArgumentException Thrown if one of the keys given is not found in the expression.

public abstract void toggleFunction (WebNode firstNode, WebNode secondNode, int toggleFunction)

Change the function between the two given nodes to the specified function. The functions which are available come from EnumWebToggleFunction. Note that if AND NOT or OR NOT are the original operator, the node directly under the NOT node should be specified as the second argument to this method. These two nodes either should be the direct children of the same parent, or the second node must have a NOT node as its parent which shares a parent with the first argument.

For example, if there were an AND node, with children firstNode and a NOT node which has the secondNode as a child node, then the original function is considered to be AND NOT.

Each time, this function will add a new node for the new toggleFunction first. Then if the auto consolidation is set, it may remove the original function node (the shared parent of the two input nodes).

Parameters
firstNode The first node whose parent operator will be toggled.
secondNode The second node whose parent operator will be toggled.
toggleFunction The function to toggle to, which is a value from EnumWebToggleFunction.
Throws
WebObjectsException Thrown if the parent of the given nodes is not aa branch qualification operator, the two given nodes do not share the same parent, or if either the first node, second node, or the shared parent node are the root node of the expression.
IllegalArgumentException Thrown when input parameter is null.

public abstract void ungroup (WebNode firstNode, WebNode secondNode)

Ungroup two nodes in the expression. The parent of both given nodes, which is an operator node, will be removed and the two child nodes will be moved to the removed node's position in the expression. The two nodes given must either share a parent node or for the first node and the parent node of the second child (which must be a NOT node) share a common parent node. In the second case, the operator will be considered to be the parent and the not node combined(i.e. AND NOT or OR NOT).

Parameters
firstNode The first node to be ungrouped.
secondNode The second node to be ungrouped.
Throws
WebObjectsException Thrown when parent node of one of the given nodes is not a branch qualificaiton operator, when the given nodes do not share the same parent, or when one of the input nodes or the parent of the input nodes is the root node of the expression.
IllegalArgumentException Thrown when one of the input parameters is null.

public abstract void ungroup (int firstKey, int secondKey)

Ungroup two nodes in the expression. This method allows the user to specify the nodes to be ungrouped by their keys. The parent of both given nodes, which is an operator node, will be removed and the two child nodes will be moved to the removed node's position in the expression. The two nodes given must either share a parent node or for the first node and the parent node of the second child (which must be a NOT node) share a common parent node. In the second case, the operator will be considered to be the parent and the not node combined(i.e. AND NOT or OR NOT).

Parameters
firstKey The key of first node to be ungrouped.
secondKey The key of second node to be ungrouped.
Throws
WebObjectsException Thrown when parent node of one of the given nodes is not a branch qualificaiton operator, when the given nodes do not share the same parent, or when one of the input nodes or the parent of the input nodes is the root node of the expression.
IllegalArgumentException Thrown when one of the input parameters is null.

public abstract boolean validateOperands (WebNode node, RWDataSet ds)

Returns whether the given node and its children are valid. The primary use of this is to ensure that the given node is valid within the given RW context.

Parameters
node The WebNode object which will be validated. If null is passed, then the validation will start at the root. Note that all children will be validated as well.
ds The dataset which is used to validate if it contains the operand objects
Returns
  • True if the expression is valid, false if it is not.