Building Parsers with Java

sjm.examples.sling
Class FunctionComparison

java.lang.Object
  |
  +--sjm.engine.Structure
        |
        +--sjm.engine.Gateway
              |
              +--sjm.examples.sling.FunctionComparison

public class FunctionComparison
extends Gateway
implements BooleanTerm

This class's constructor accepts two functions and an operator, and can evaluate and compare the functions. An object of this class can say whether a comparison holds for two functions. A comparison must ultimately be between two numbers rather than two functions. This class actually compares the y components of functions at time zero.


Field Summary
protected  SlingFunction f0
           
protected  SlingFunction f1
           
protected  java.lang.String operator
           
 
Fields inherited from class sjm.engine.Gateway
open
 
Fields inherited from class sjm.engine.Structure
emptyList, functor, terms
 
Constructor Summary
FunctionComparison(java.lang.String operator, SlingFunction f0, SlingFunction f1)
          Create a comparison with the specified operator and comparison functions.
 
Method Summary
 boolean canProveOnce()
          Returns true if the comparison operator holds true between the values of this comparison's terms.
 java.lang.Object eval()
          Returns Boolean.TRUE if the comparison operator holds true between the values of the two terms.
 java.lang.String toString()
          Returns a string representation of this comparison.
 
Methods inherited from class sjm.engine.Gateway
canFindNextProof, cleanup
 
Methods inherited from class sjm.engine.Structure
arity, copyForProof, equals, functorAndArityEquals, headAndTail, isList, list, list, list, listTailString, listTermsToString, terms, unify, unify, unify, variables
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

operator

protected java.lang.String operator

f0

protected SlingFunction f0

f1

protected SlingFunction f1
Constructor Detail

FunctionComparison

public FunctionComparison(java.lang.String operator,
                          SlingFunction f0,
                          SlingFunction f1)
Create a comparison with the specified operator and comparison functions.
Parameters:
String - the comparison operator
SlingFunction - the first function
SlingFunction - the second function
Method Detail

canProveOnce

public boolean canProveOnce()
Returns true if the comparison operator holds true between the values of this comparison's terms.

This method evaluates the two functions received in the constructor to fix any variable references. Then this method extracts the y components of the functions at time zero, and compares these values.

Overrides:
canProveOnce in class Gateway
Returns:
true if the comparison operator holds true between the values of this comparison's terms.

eval

public java.lang.Object eval()
Returns Boolean.TRUE if the comparison operator holds true between the values of the two terms.
Overrides:
eval in class Structure
Returns:
Boolean.TRUE if the comparison operator holds true between the values of the two terms.

toString

public java.lang.String toString()
Returns a string representation of this comparison.
Overrides:
toString in class Structure
Returns:
a string representation of this comparison

by Steve Metsker