com.bigdata.relation.rule
Class Var<E>

java.lang.Object
  extended by com.bigdata.relation.rule.Var<E>
All Implemented Interfaces:
IVariable<E>, IVariableOrConstant<E>, Serializable, Comparable<IVariable<E>>

public final class Var<E>
extends Object
implements IVariable<E>, Comparable<IVariable<E>>

A variable.

Note: This implementation provides reference testing for equality. The rest of the package assumes that it can use reference testing for equality when comparing variables.

Version:
$Id: Var.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form
TODO:
it is not entirely satisfactory to have variable names disappear from rules as they are specialized. It might be better to define a BoundVar (extends Var) whose id was the bound value and which reported true for both isVariable() and isConstant(). However this would mean that var(x) != var(x,id) where the latter is bound to a constant. Or if Var is rule-local (or rule execution thread local) then it could define set(Object) and get():Object to access its binding. A rule that was specialized would then flag bound variables as immutable., Variable canonicalization could be limited in scope to a rule or its derived rules (via specialization or for truth maintenance). This would make it easier to place constraints directly on the variable so that it can limit the types of binding that it will accept. Constraints on IPredicates limit the matched tuples. Constraints on rules limit the binding patterns across the rule. (In fact, variables can be "named" by their index into the binding set for most purposes.)

Method Summary
 int compareTo(IVariable<E> o)
          Orders variables alphabetically.
 boolean equals(IVariableOrConstant o)
          Return true if this is the same variable or if both values are Constant whose values are the same.
 E get()
          Return the bound value.
 String getName()
          Return the name of a variable.
 int hashCode()
          The hash code of the name of the variable as reported by IVariableOrConstant.getName()
 boolean isConstant()
          Return true iff this is a constant.
 boolean isVar()
          Return true iff this is a variable.
 String toString()
           
static Var var(String name)
          Singleton factory for Vars.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

isVar

public final boolean isVar()
Description copied from interface: IVariableOrConstant
Return true iff this is a variable.

Specified by:
isVar in interface IVariableOrConstant<E>

isConstant

public final boolean isConstant()
Description copied from interface: IVariableOrConstant
Return true iff this is a constant.

Specified by:
isConstant in interface IVariableOrConstant<E>

equals

public final boolean equals(IVariableOrConstant o)
Description copied from interface: IVariableOrConstant
Return true if this is the same variable or if both values are Constant whose values are the same.

Specified by:
equals in interface IVariableOrConstant<E>

hashCode

public final int hashCode()
Description copied from interface: IVariable
The hash code of the name of the variable as reported by IVariableOrConstant.getName()

Specified by:
hashCode in interface IVariable<E>
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

get

public E get()
Description copied from interface: IVariableOrConstant
Return the bound value.

Specified by:
get in interface IVariableOrConstant<E>

getName

public String getName()
Description copied from interface: IVariableOrConstant
Return the name of a variable.

Specified by:
getName in interface IVariableOrConstant<E>

var

public static Var var(String name)
Singleton factory for Vars.

Note: While only a single instance of a variable object will be created for any given variable name, the "scope" of the variable is always constrained by the rule within which it is used. The purpose of the singleton factory is to let us test for the same variable using "==" (reference testing) and also to have a shorthand for variable creation.

Parameters:
name - The variable name.
Returns:
The singleton variable for that name.

compareTo

public int compareTo(IVariable<E> o)
Orders variables alphabetically.

Specified by:
compareTo in interface Comparable<IVariable<E>>


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