com.bigdata.bop
Class ModifiableBOpBase

java.lang.Object
  extended by com.bigdata.bop.CoreBaseBOp
      extended by com.bigdata.bop.ModifiableBOpBase
All Implemented Interfaces:
BOp, IPropertySet, Serializable, Cloneable
Direct Known Subclasses:
ASTBase, RangeBOp

public class ModifiableBOpBase
extends CoreBaseBOp

Abstract base class for mutable BOps. Unlike BOpBase, this class supports destructive mutation. This is the base class for the bigdata AST nodes. ASTs are destructively rewritten by optimizers before they are turned into a query plan.

Constructor patterns

ModifiableBOpBases should define the following public constructors

public Class(BOp[] args, Map<String,Object> anns)
A shallow copy constructor. This is used when initializing a BOp from the caller's data or when generated a query plan from Prolog. There are some exceptions to this rule. For example, Constant does not define a shallow copy constructor because that would not provide a means to set the constant's value.
public Class(Class src)
A copy constructor.

Version:
$Id: ModifiableBOpBase.java 5680 2011-11-18 00:46:57Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.bigdata.bop.BOp
BOp.Annotations
 
Field Summary
 
Fields inherited from class com.bigdata.bop.CoreBaseBOp
DEFAULT_INITIAL_CAPACITY
 
Fields inherited from interface com.bigdata.bop.BOp
NOANNS, NOARGS
 
Constructor Summary
ModifiableBOpBase(BOp[] args, Map<String,Object> annotations)
          Shallow copy constructor (required).
ModifiableBOpBase(ModifiableBOpBase op)
          Deep copy constructor (required).
 
Method Summary
 void addArg(BOp newArg)
          Add a new argument (core mutation method).
 void addArg(int index, BOp newArg)
          Add a new argument (core mutation method) at the specified index.
 void addArgIfAbsent(BOp arg)
          Add an argument iff it is not already present.
 Map<String,Object> annotations()
          The operator's annotations.
protected  boolean annotationsEqual(BOp o)
          Return true iff the annotations of this BOp and the other BOp are equals.
 Iterator<BOp> argIterator()
          An iterator visiting the operator's arguments.
 List<BOp> args()
          An unmodifiable view of the list of arguments (aka children) of this node.
 int arity()
          The #of arguments to the operation.
 ModifiableBOpBase clearProperty(String name)
          Clear the named annotation (destructive mutation).
 ModifiableBOpBase copyAll(Map<String,Object> anns)
          Copy all annotations from the caller's map.
 BOp get(int index)
          Return an argument to the operation.
 Object getProperty(String name)
          Return the value of a named property.
protected  void mutation()
          Invoked automatically any time a mutation operation occurs.
 boolean removeArg(BOp arg)
          Remove the 1st occurrence of the argument (core mutation method).
 int replaceWith(BOp oldChild, BOp newChild)
          Replace a child of a node with another reference (destructive modification).
 ModifiableBOpBase setArg(int index, BOp newArg)
          Replace the value of the argument at the specified index (core mutation method).
 ModifiableBOpBase setArgs(BOp[] args)
          Replace the arguments.
 void setId(int id)
          Unconditionally set the Annotations#BOP_ID.
 ModifiableBOpBase setProperty(String name, Object value)
          Set the named property value (destructive mutation).
 ModifiableBOpBase setUnboundProperty(String name, Object value)
          Conditionally set the named property iff it is not bound (destructive mutation).
 BOp[] toArray()
          A shallow copy of the operator's arguments.
<T> T[]
toArray(T[] a)
          A shallow copy of the operator's arguments using the generic type of the caller's array.
 
Methods inherited from class com.bigdata.bop.CoreBaseBOp
annotationsEqual, annotationsToString, checkArgs, clone, equals, getEvaluationContext, getId, getProperty, getRequiredProperty, hashCode, indent, isController, toShortString, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModifiableBOpBase

public ModifiableBOpBase(ModifiableBOpBase op)
Deep copy constructor (required).

Each BOp MUST implement a public copy constructor with the signature:

 public Foo(Foo)
 
This construct is invoked by CoreBaseBOp.clone() using reflection.

The default implementation makes a shallow copy of args() and annotations() but DOES NOT perform field-by-field copying. Subclasses may simply delegate the constructor to their super class unless they have additional fields which need to be copied.

Parameters:
op - A deep copy will be made of this BOp.
Throws:
NullPointerException - if the argument is null.

ModifiableBOpBase

public ModifiableBOpBase(BOp[] args,
                         Map<String,Object> annotations)
Shallow copy constructor (required).

Parameters:
args - The arguments to the operator.
annotations - The annotations for the operator (optional). When null, a mutable map with a default capacity of is allocated. Do NOT specify an immutable map.
Method Detail

annotations

public final Map<String,Object> annotations()
Description copied from interface: BOp
The operator's annotations.


annotationsEqual

protected boolean annotationsEqual(BOp o)
Description copied from class: CoreBaseBOp
Return true iff the annotations of this BOp and the other BOp are equals.

Note: This method permits override by subclasses with direct access to the maps to be compared.

Overrides:
annotationsEqual in class CoreBaseBOp
See Also:
CoreBaseBOp.annotationsEqual(Map, Map)

get

public BOp get(int index)
Description copied from interface: BOp
Return an argument to the operation.

Parameters:
index - The argument index in [0:BOp.arity()-1].
Returns:
The argument.

mutation

protected void mutation()
Invoked automatically any time a mutation operation occurs. The default implementation is a NOP.


setArgs

public ModifiableBOpBase setArgs(BOp[] args)
Replace the arguments.

Parameters:
args - The new arguments.
Returns:
this.

setArg

public ModifiableBOpBase setArg(int index,
                                BOp newArg)
Replace the value of the argument at the specified index (core mutation method).

Parameters:
index - The index of the child expression to be replaced.
newArg - The new child expression.
Returns:
This ModifiableBOpBase.
Throws:
IllegalArgumentException - if the argument is null.
IllegalArgumentException - if the argument is this.

addArg

public void addArg(BOp newArg)
Add a new argument (core mutation method).

Parameters:
newArg - The argument.
Throws:
IllegalArgumentException - if the argument is null.
IllegalArgumentException - if the argument is this.

addArg

public void addArg(int index,
                   BOp newArg)
Add a new argument (core mutation method) at the specified index.

Parameters:
index - The index of the child expression to be replaced.
newArg - The argument.
Throws:
IllegalArgumentException - if the argument is null.
IllegalArgumentException - if the argument is this.

addArgIfAbsent

public void addArgIfAbsent(BOp arg)
Add an argument iff it is not already present.

Parameters:
arg - The argument.
Throws:
IllegalArgumentException - if the argument is null.
IllegalArgumentException - if the argument is this.

removeArg

public boolean removeArg(BOp arg)
Remove the 1st occurrence of the argument (core mutation method).

Parameters:
arg - The argument.
Returns:
true iff the argument was removed.
Throws:
IllegalArgumentException - if the argument is null.
IllegalArgumentException - if the argument is this.

replaceWith

public int replaceWith(BOp oldChild,
                       BOp newChild)
Replace a child of a node with another reference (destructive modification). All arguments which point to the oldChild will be replaced by references to the newChild.

Parameters:
oldChild -
newChild -
Returns:
The #of references which were replaced.

arity

public int arity()
Description copied from interface: BOp
The #of arguments to the operation.


args

public final List<BOp> args()
An unmodifiable view of the list of arguments (aka children) of this node.

Note: The view is not modifiable in order to preserve the contract that mutation() will be invoked if there is change in the state of this BOp.


argIterator

public final Iterator<BOp> argIterator()
An iterator visiting the operator's arguments.

Note: This Iterator supports removal.


toArray

public BOp[] toArray()
Description copied from interface: BOp
A shallow copy of the operator's arguments.


toArray

public <T> T[] toArray(T[] a)
Description copied from interface: BOp
A shallow copy of the operator's arguments using the generic type of the caller's array. If the array has sufficient room, then the arguments are copied into the caller's array. If there is space remaining, a null is appended to mark the end of the data.


getProperty

public Object getProperty(String name)
Description copied from interface: IPropertySet
Return the value of a named property.

Parameters:
name - The property name.
Returns:
The property value.

copyAll

public ModifiableBOpBase copyAll(Map<String,Object> anns)
Copy all annotations from the caller's map.

Parameters:
anns - The annotations to be copied.
Returns:
this

setProperty

public ModifiableBOpBase setProperty(String name,
                                     Object value)
Set the named property value (destructive mutation).

Parameters:
name - The name.
value - The new value.
Returns:
this.

setUnboundProperty

public ModifiableBOpBase setUnboundProperty(String name,
                                            Object value)
Conditionally set the named property iff it is not bound (destructive mutation).

Parameters:
name - The name.
value - The value.
Returns:
this.
Throws:
IllegalStateException - if the property is already set.

clearProperty

public ModifiableBOpBase clearProperty(String name)
Clear the named annotation (destructive mutation).

Parameters:
name - The annotation.
Returns:
this.

setId

public void setId(int id)
Unconditionally set the Annotations#BOP_ID.

Parameters:
id - The id.


Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.