Building Parsers with Java

sjm.engine
Class Comparison

java.lang.Object
  |
  +--sjm.engine.Structure
        |
        +--sjm.engine.Gateway
              |
              +--sjm.engine.Comparison

public class Comparison
extends Gateway
implements BooleanTerm

A Comparison object applies a comparison operator to its terms in order to prove itself.

The functor of a comparison must be one of the strings, "<", ">", "<=", ">=", "=", or "!=", indicating comparison this object will perform during a proof. Any other functor will cause the comparison to always be false.

Here is an example of a comparison:

     Atom alpha = new Atom("alpha");
     Atom beta = new Atom("beta");
     Comparison c = new Comparison("<=", alpha, beta);
     System.out.println(c + ", " + c.canFindNextProof());
 
This prints out:
     <=(alpha, beta), true
 

Fields inherited from class sjm.engine.Gateway
open
 
Fields inherited from class sjm.engine.Structure
emptyList, functor, terms
 
Constructor Summary
Comparison(java.lang.String operator, ComparisonTerm term0, ComparisonTerm term1)
          Create a comparison with the specified operator and comparison terms.
 
Method Summary
 boolean canProveOnce()
          Returns true if the comparison operator holds true between the values of this comparison's terms.
protected  boolean compare(java.lang.Object obj0, java.lang.Object obj1)
          Returns the result of comparing two objects, using the indicated comparison operator.
protected  boolean compareNumber(java.lang.Number n0, java.lang.Number n1)
          Returns the result of comparing two Numbers, using the indicated comparison operator.
protected  boolean compareString(java.lang.String s0, java.lang.String s1)
          Returns the result of comparing two Strings, using the indicated comparison operator.
 Term copyForProof(AxiomSource ignored, Scope scope)
          Create a copy that uses the provided scope.
 java.lang.Object eval()
          Returns Boolean.TRUE if the comparison operator holds true between the values of the two terms.
 
Methods inherited from class sjm.engine.Gateway
canFindNextProof, cleanup
 
Methods inherited from class sjm.engine.Structure
arity, equals, functorAndArityEquals, headAndTail, isList, list, list, list, listTailString, listTermsToString, terms, toString, unify, unify, unify, variables
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Comparison

public Comparison(java.lang.String operator,
                  ComparisonTerm term0,
                  ComparisonTerm term1)
Create a comparison with the specified operator and comparison terms.
Parameters:
String - the comparison operator
ComparisonTerm - the first term
ComparisonTerm - the second term
Method Detail

canProveOnce

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

compare

protected boolean compare(java.lang.Object obj0,
                          java.lang.Object obj1)
Returns the result of comparing two objects, using the indicated comparison operator.
Parameters:
Object - a string or number to compare
Object - a string or number to compare
Returns:
the result of comparing two objects

compareNumber

protected boolean compareNumber(java.lang.Number n0,
                                java.lang.Number n1)
Returns the result of comparing two Numbers, using the indicated comparison operator.
Parameters:
Number - a Number to compare
Number - a Number to compare
Returns:
the result of comparing the two numbers

compareString

protected boolean compareString(java.lang.String s0,
                                java.lang.String s1)
Returns the result of comparing two Strings, using the indicated comparison operator.
Parameters:
String - a String to compare
String - a String to compare
Returns:
the result of comparing the two strings

copyForProof

public Term copyForProof(AxiomSource ignored,
                         Scope scope)
Create a copy that uses the provided scope.
Overrides:
copyForProof in class Structure
Parameters:
AxiomSource - ignored
Scope - the scope to use for variables in the copy
Returns:
a copy that uses the provided scope

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.

by Steve Metsker