QJCC homepage

biz.chitec.quarterback.util.logic
Class SmartCompareExpr

java.lang.Object
  extended bybiz.chitec.quarterback.util.logic.SmartCompareExpr
All Implemented Interfaces:
java.lang.Cloneable, LogicExpr
Direct Known Subclasses:
BooleanCompareExpr, IntCompareExpr, StringCompareExpr

public abstract class SmartCompareExpr
extends java.lang.Object
implements LogicExpr

Compares a value to something else. This is the master class for several, type-constrained children. Idea is to have a key and to compare it with several values. The values are given as a string which is interpretated depending on the expected type of the value to be found. This master class only defines the general workflow. See the derived classes for datatype-aware operation.

Version:
$Id: af9c75631280009364dc69695f8bb1fdba3d7bc5 $
Author:
cantamen/Dirk Hillbrecht 2008. Released under LGPL or GPL with classpath exception.

Nested Class Summary
 
Nested classes inherited from class biz.chitec.quarterback.util.logic.LogicExpr
LogicExpr.Converter, LogicExpr.UniverseGenerator
 
Field Summary
private  java.lang.String displaykey
           
protected  java.lang.String key
           
protected  java.util.List values
           
 
Constructor Summary
protected SmartCompareExpr(java.lang.String keyx, java.util.List valuesx)
           
protected SmartCompareExpr(java.lang.String keyx, java.lang.String svaluesx)
           
 
Method Summary
 java.lang.Object clone()
          Deep-copy the logic expression.
 void convertValues(LogicExpr.Converter c)
          Conversion of values in the expressions (e.g. for replacing external representations of database entries with their internal key)
 boolean equals(java.lang.Object o)
           
 boolean evaluate(java.lang.Object universe)
          Is the expression valid in the given universe
 java.lang.String getDisplayKey()
           
 java.lang.Object[] getInternalVars()
          Only for GJSA class parsers: get class variables to create object from a parsed string.
 java.lang.String getKey()
           
 int[] getResultSet(LogicExpr.UniverseGenerator generator)
          Return all elements of the universe which match the expression
 java.util.List getValues()
           
 java.lang.String getValuesString()
           
protected abstract  java.lang.String internalToString(java.util.List internalvalues)
           
 boolean isReady()
          Returns if the expression is actually evaluable, i.e. any of the evaluating methods can be called.
 boolean isTreeReady()
          Returns whether this and all deeper expressions are evaluable.
 void setDisplayKey(java.lang.String displaykeyx)
           
 void setValuesString(java.lang.String svaluesx)
           
protected abstract  java.util.List stringToInternal(java.lang.String values)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface biz.chitec.quarterback.util.logic.LogicExpr
sqlString
 

Field Detail

key

protected java.lang.String key

displaykey

private java.lang.String displaykey

values

protected java.util.List values
Constructor Detail

SmartCompareExpr

protected SmartCompareExpr(java.lang.String keyx,
                           java.lang.String svaluesx)

SmartCompareExpr

protected SmartCompareExpr(java.lang.String keyx,
                           java.util.List valuesx)
Method Detail

setDisplayKey

public void setDisplayKey(java.lang.String displaykeyx)

getDisplayKey

public java.lang.String getDisplayKey()

getKey

public java.lang.String getKey()

getValues

public java.util.List getValues()

getValuesString

public java.lang.String getValuesString()

setValuesString

public void setValuesString(java.lang.String svaluesx)

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Description copied from interface: LogicExpr
Deep-copy the logic expression. The contract for this method says the the logic expression must be deep-copied. I.e. if clone() is called for the root expression of a certain expression tree, a completely independent tree is returned.

Note: This method must be defined in a way that makes it quite complicated to call it for simply cloning a logic expression tree: It returns an Object (which always happens to be a LogicExpr) and it might throw a CloneNotSupportedException - which will (a) never happen and is (b) no RuntimeException, so a caller would always have to catch it.

To make life simpler, there is a static method LogicExprUtilties.cloneLogicExpr() which will call clone() on the root object and take care of return value and exceptions.

Specified by:
clone in interface LogicExpr
Throws:
java.lang.CloneNotSupportedException

equals

public boolean equals(java.lang.Object o)

convertValues

public void convertValues(LogicExpr.Converter c)
Description copied from interface: LogicExpr
Conversion of values in the expressions (e.g. for replacing external representations of database entries with their internal key)

Specified by:
convertValues in interface LogicExpr

evaluate

public boolean evaluate(java.lang.Object universe)
Description copied from interface: LogicExpr
Is the expression valid in the given universe

Specified by:
evaluate in interface LogicExpr

getInternalVars

public java.lang.Object[] getInternalVars()
Description copied from interface: LogicExpr
Only for GJSA class parsers: get class variables to create object from a parsed string.

Specified by:
getInternalVars in interface LogicExpr

getResultSet

public int[] getResultSet(LogicExpr.UniverseGenerator generator)
Description copied from interface: LogicExpr
Return all elements of the universe which match the expression

Specified by:
getResultSet in interface LogicExpr

isReady

public boolean isReady()
Description copied from interface: LogicExpr
Returns if the expression is actually evaluable, i.e. any of the evaluating methods can be called. If this method returns false, the expression should not be evaluated. Note that this method does not care for the evaluation state of any potential children of this LogicExpr. Use isTreeEvaluable() for this test.

Specified by:
isReady in interface LogicExpr
Returns:
True if an evaluation is possible, false if not.

isTreeReady

public boolean isTreeReady()
Description copied from interface: LogicExpr
Returns whether this and all deeper expressions are evaluable. Walks through the the expression tree and returns only true if all expressions below are evaluable.

Specified by:
isTreeReady in interface LogicExpr
Returns:
True if this and all expressions below are evaluable, false otherwise.

stringToInternal

protected abstract java.util.List stringToInternal(java.lang.String values)

internalToString

protected abstract java.lang.String internalToString(java.util.List internalvalues)

QJCC homepage