org.omegahat.Models.Formulae.Expressions
Class ModelAnalyzer

java.lang.Object
  |
  +--org.omegahat.Models.Formulae.Expressions.ModelAnalyzer

public class ModelAnalyzer
extends java.lang.Object

Provides a form of reflectance for certain characteristics of a given model, revealing the dependent, independent and free variables.


Field Summary
protected  FormulaName[] dependentVariables
          Collection of the dependent variables in the model that is cached when it is first computed.
protected  MultiLineModelFormula formula
          The symbolic version of the model to be analyzed.
protected  FormulaName[] freeVariables
          Collection of the free variables in the model associated with this object that is cached when it is first computed.
 
Constructor Summary
ModelAnalyzer(ModelFormula formula)
          Constructor that takes a model consisting of a single formula.
ModelAnalyzer(MultiLineModelFormula formula)
          Constructor using a model with one or more formulae elements.
 
Method Summary
 FormulaName[] computeDependentVariables()
          Compute all the variables that are identified on the left hand side of a formula in the model.
protected  int computeDependentVariables(ModelFormula formula, java.util.HashSet els)
          Compute the response variables (i.e.
protected  java.util.HashSet computeDependentVariableSet()
          Internal method used to compute the list of dependent variables that has a different return type than the method computeDependentVariables.
 FormulaName[] computeFreeVariables()
          Identifies the variables referenced in the model specification that are not defined as the LHS of any formula within the model.
protected  int computeFreeVariables(ModelFormula formula, java.util.HashSet els)
          Computes the free variables in the specified formula.
protected  FormulaName[] copyToArray(java.util.HashSet els)
          Method to convert the elements in HashSet to a more specific type - an array of FormulaName.
 FormulaName[] dependentVariables()
          Return the collection of dependent variables in the model, computing and caching it as needed.
 FormulaName[] dependentVariables(boolean force)
           
 FormulaName[] dependentVariables(FormulaName[] vars)
           
 MultiLineModelFormula formula()
          Retrieve the formula being analyzed by this object.
protected  MultiLineModelFormula formula(ModelFormula f)
          Set the formula being analyzed by this object.
protected  MultiLineModelFormula formula(MultiLineModelFormula f)
          Specify the formula to be analyzed, usually only set a instantiation of this object.
 FormulaName[] freeVariables()
          Return the collection of free variables in the model, computing and caching it if it has not been computed previously.
 FormulaName[] freeVariables(boolean force)
          Return the collection of the free variables identified in the associated model, optionally caching it for future calls.
protected  FormulaName[] freeVariables(FormulaName[] vars)
          Cache the computed collection of free variables for quick recall in future computations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

formula

protected MultiLineModelFormula formula
The symbolic version of the model to be analyzed.

freeVariables

protected FormulaName[] freeVariables
Collection of the free variables in the model associated with this object that is cached when it is first computed.

dependentVariables

protected FormulaName[] dependentVariables
Collection of the dependent variables in the model that is cached when it is first computed.
Constructor Detail

ModelAnalyzer

public ModelAnalyzer(ModelFormula formula)
Constructor that takes a model consisting of a single formula.

ModelAnalyzer

public ModelAnalyzer(MultiLineModelFormula formula)
Constructor using a model with one or more formulae elements.
Method Detail

computeDependentVariables

public FormulaName[] computeDependentVariables()
Compute all the variables that are identified on the left hand side of a formula in the model. Currently, doesn't handle anything but simple names and collections of names ((x,y)).
See Also:
computeFreeVariables()

computeDependentVariableSet

protected java.util.HashSet computeDependentVariableSet()
Internal method used to compute the list of dependent variables that has a different return type than the method computeDependentVariables.
Returns:
a HashSet from the collections framework containing (unique) elements of class FormulaName.
See Also:
computeDependentVariables()

computeDependentVariables

protected int computeDependentVariables(ModelFormula formula,
                                        java.util.HashSet els)
Compute the response variables (i.e. on the LHS) of the given formula and add these to the list. This is used internally when iterating over the model's formulae and the results are stored across iterations in this container. It takes care of ensuring that an entry is entered only once - relying on the equals() of FormulaName.

computeFreeVariables

protected int computeFreeVariables(ModelFormula formula,
                                   java.util.HashSet els)
Computes the free variables in the specified formula. This means the values that are not defined as the LHS of a formula.

copyToArray

protected FormulaName[] copyToArray(java.util.HashSet els)
Method to convert the elements in HashSet to a more specific type - an array of FormulaName.

computeFreeVariables

public FormulaName[] computeFreeVariables()
Identifies the variables referenced in the model specification that are not defined as the LHS of any formula within the model.
Returns:
an array of FormulaName objects identifying the free variables.
See Also:
computeDependentVariables(),

formula

public MultiLineModelFormula formula()
Retrieve the formula being analyzed by this object.

formula

protected MultiLineModelFormula formula(ModelFormula f)
Set the formula being analyzed by this object.

formula

protected MultiLineModelFormula formula(MultiLineModelFormula f)
Specify the formula to be analyzed, usually only set a instantiation of this object.

freeVariables

public FormulaName[] freeVariables()
Return the collection of free variables in the model, computing and caching it if it has not been computed previously.
Returns:
array of FormulaName objects identifying the free variables.

freeVariables

public FormulaName[] freeVariables(boolean force)
Return the collection of the free variables identified in the associated model, optionally caching it for future calls.
Parameters:
force - indicates whether to compute the values if they have not been cached from previous calls. By default, this is true by invoking freeVariables()
Returns:
array of FormulaName elements identifying each free variable.

freeVariables

protected FormulaName[] freeVariables(FormulaName[] vars)
Cache the computed collection of free variables for quick recall in future computations.

dependentVariables

public FormulaName[] dependentVariables()
Return the collection of dependent variables in the model, computing and caching it as needed.

dependentVariables

public FormulaName[] dependentVariables(boolean force)

dependentVariables

public FormulaName[] dependentVariables(FormulaName[] vars)