atg.projects.b2bstore.scenario
Class PercentageComparisonFilter

java.lang.Object
  extended by atg.process.filter.Filter
      extended by atg.process.filter.ExpressionFilter
          extended by atg.projects.b2bstore.scenario.PercentageComparisonFilter

public class PercentageComparisonFilter
extends ExpressionFilter

A filter class for scenario conditions of the form

value1 [is at least / is at most] ____ percent [greater than / less than / of] value2

This class expects its evaluate method to be called with exactly 5 operands having the following types and semantics:

operands[0] (java.lang.Number)
The value of value1 in the expression above.

operands[1] (java.lang.String)
A string constant identifying the arithmatic comparison to be performed. The string should be either ge for a greater than or equal to comparison ("is at least" in the expression above) or le for a less than or equal to comparison ("is at most" in the expression above). Any other value will cause a ProcessException to be thrown when the condition is evaluated.

operands[2] (java.lang.Integer)
The percentage value in the expression above.

operands[3] (java.lang.String)
A string constant identifying how the percentage value is to be applied. The string should be gt if the expression is "X percent greater than value", or lt if the expression is "X percent less than value", or of if the expression is "X percent of value". Any other value will cause a ProcessException to be thrown when the condition is evaluated.

operands[4] (java.lang.Number)
The value of value2 in the expression above.


Field Summary
static java.lang.String CLASS_VERSION
           
protected static int COMP_GTE
           
protected static int COMP_LTE
           
protected  int mComparisonType
           
static boolean mDebugging
           
protected  double mPercentage
           
protected  int mPercentageType
           
protected static int PCT_LESS_THAN
           
protected static int PCT_MORE_THAN
           
protected static int PCT_OF
           
protected static java.util.ResourceBundle sDefaultResources
           
 
Fields inherited from class atg.process.filter.Filter
FALSE, TRUE
 
Constructor Summary
PercentageComparisonFilter()
           
 
Method Summary
protected  java.lang.String badTypeMsg(int pIndex, java.lang.String pDescription, java.lang.Object pValue, java.lang.String pExpectedClass)
          Get the error message to deliver when an operand has the wrong type.
protected  java.lang.String errorMsg(java.lang.String pResourceKey)
          Get an error message string based on an error message resource key.
protected  java.lang.String errorMsg(java.lang.String pResourceKey, java.lang.Object[] pArgs)
          Get a formatted error message string based on an error message resource key and an array of message arguments.
protected  Filter evaluate(ProcessExecutionContext pContext)
          Evaluates this filter in the given scenario execution context.
 void initialize(java.lang.String pOperator, Expression[] pOperands)
          Initializes this ExpressionFilter given its operator and operands.
protected  java.lang.String invariantOperandWasNullMsg(int pIndex, java.lang.String pDescription)
          Get the error message to deliver if we cannot compute the value of an operand that is supposed to be invariant in the initialize() method.
protected  java.lang.String invariantValueNotAvailableMsg(int pIndex, java.lang.String pDescription)
          Get the error message to deliver if we cannot compute the value of an operand that is supposed to be invariant in the initialize() method.
 
Methods inherited from class atg.process.filter.ExpressionFilter
configure, equals, getOperands, getOperator, operandsEquals, setOperands, setOperator, toString
 
Methods inherited from class atg.process.filter.Filter
andFilters, andFilters, assumeFalse, assumeTrue, createProcessInstanceQuery, createSubjectQuery, getResourceBundle, getSubjectType, hashCode, implies, isCacheable, negate, orFilters, orFilters, setCacheable, test
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION

mDebugging

public static final boolean mDebugging
See Also:
Constant Field Values

COMP_GTE

protected static final int COMP_GTE
See Also:
Constant Field Values

COMP_LTE

protected static final int COMP_LTE
See Also:
Constant Field Values

PCT_MORE_THAN

protected static final int PCT_MORE_THAN
See Also:
Constant Field Values

PCT_LESS_THAN

protected static final int PCT_LESS_THAN
See Also:
Constant Field Values

PCT_OF

protected static final int PCT_OF
See Also:
Constant Field Values

sDefaultResources

protected static java.util.ResourceBundle sDefaultResources

mComparisonType

protected int mComparisonType

mPercentageType

protected int mPercentageType

mPercentage

protected double mPercentage
Constructor Detail

PercentageComparisonFilter

public PercentageComparisonFilter()
Method Detail

initialize

public void initialize(java.lang.String pOperator,
                       Expression[] pOperands)
                throws ProcessException
Initializes this ExpressionFilter given its operator and operands. This implementation tries to compute and cache invariant parts of the condition including the comparison type, percentage literal, and percentage type so they don't have to be recomputed each time the condition is evaluated.

Overrides:
initialize in class ExpressionFilter
Throws:
ProcessException - If any of the operand values is not available or is null or is an unrecognized constant value.

evaluate

protected Filter evaluate(ProcessExecutionContext pContext)
                   throws ProcessException
Evaluates this filter in the given scenario execution context. The context may not yet contain all of the information necessary to evaluate the filter - specifically, it may be missing the particular scenario instance and/or profile that the scenario is being executed on.

Specified by:
evaluate in class Filter
Parameters:
pContext - The scenario execution context to use when getting operand values.
Returns:
Filter.TRUE if the filter can be fully evaluated and the condition is satisfied.

Filter.FALSE if the filter can be fully evaluated and the condition is not satisfied

this if the filter cannot be fully evaluated because one or more operand values are not available in the scenario execution context

null if the filter cannot be evaluated because one or more operand values are null

Throws:
ProcessException - If any operand has the wrong type or if any String constant operand has an unrecognized value

errorMsg

protected java.lang.String errorMsg(java.lang.String pResourceKey)
Get an error message string based on an error message resource key.

Parameters:
pResourceKey - A key that identifies the error message in the MessageResources file.
Returns:
The formatted error message.

errorMsg

protected java.lang.String errorMsg(java.lang.String pResourceKey,
                                    java.lang.Object[] pArgs)
Get a formatted error message string based on an error message resource key and an array of message arguments.

Parameters:
pResourceKey - A key that identifies the error message format in the MessageResources file. The corresponding value will be a java.text.MessageFormat format string.
pArgs - An array of objects that will be inserted into the format string.
Returns:
The formatted error message.

invariantValueNotAvailableMsg

protected java.lang.String invariantValueNotAvailableMsg(int pIndex,
                                                         java.lang.String pDescription)
Get the error message to deliver if we cannot compute the value of an operand that is supposed to be invariant in the initialize() method.

Parameters:
pIndex - The positional index of the operand whose type was wrong.
pDescription - A description of the operand whose type was wrong.
Returns:
The error message to use when a supposedly invariant operand value is not available.

invariantOperandWasNullMsg

protected java.lang.String invariantOperandWasNullMsg(int pIndex,
                                                      java.lang.String pDescription)
Get the error message to deliver if we cannot compute the value of an operand that is supposed to be invariant in the initialize() method.

Parameters:
pIndex - The positional index of the operand whose type was wrong.
pDescription - A description of the operand whose type was wrong.
Returns:
The error message to use when a supposedly invariant operand value is not available.

badTypeMsg

protected java.lang.String badTypeMsg(int pIndex,
                                      java.lang.String pDescription,
                                      java.lang.Object pValue,
                                      java.lang.String pExpectedClass)
Get the error message to deliver when an operand has the wrong type.

Parameters:
pIndex - The positional index of the operand whose type was wrong.
pDescription - A description of the operand whose type was wrong.
pValue - The operand value, used to derive the actual type.
pExpectedClass - The type that pValue was expected to have, e.g. "java.lang.String"
Returns:
The error message to use when building a ProcessException that describes the bad type error.