cdx.scorebot.scoring
Class ScoringRule

java.lang.Object
  extended by cdx.scorebot.scoring.ScoringRule
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ScoringRule
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

defines how to score a test or group of test(s) and any associated threshold(s)

Author:
David Underhill
See Also:
Serialized Form

Nested Class Summary
static class ScoringRule.BASIC_METHOD_TYPE
          defines the methods which may be used as actions in a basic rule
 class ScoringRule.BasicCodeGenerator
          defines the fields which are used to generate the code for a basic rule
 
Constructor Summary
ScoringRule()
          default constructor
 
Method Summary
 boolean applies(TestItem ti)
          Whether or not a specified TestItem applies here.
static void checkCode(java.lang.String code, TestSuite ts)
          checks the specified code for compile-time errors
 void checkCode(TestSuite ts)
          checks the code which describes this logic for compile-time errors
 java.lang.Object clone()
          Returns a clone of this scoring rule.
 boolean equals(java.lang.Object o)
           
 java.util.Vector<TestScoreEvent> executeLogic(TestSuite suite, TestEvent t)
          executes the scoring logic on the specified TestEvent and returns any resulting TestScoreEvents, or null if none was generated (this just passes the TestEvent to ScoringLogic's executeLogic method)
 ScoringRule.BasicCodeGenerator getBasicCode()
          gets the basic code generator and information
 java.lang.String getCode()
          gets the code which describes this logic
 java.lang.String getDescription()
          gets explains what this rule does
 int getMaxBonus()
          gets total points which can be gained by bonuses applied by this rule
 int getMaxDeduction()
          gets total points which can be lost by penalties applied by this rule
 int getMaxPerTimeBonus()
          gets maximum number of points which can be gained in maxPerTimeSecs seconds
 int getMaxPerTimeDeduction()
          gets maximum number of points which can be lost in maxPerTimeSecs seconds
 int getMaxPerTimeMinutes()
          gets number of minutes in which no more than maxPerTimeDeduction can be lost or maxPerTimeBonus can be gained
 int getMaxPerTimeSecs()
          gets number of seconds in which no more than maxPerTimeDeduction can be lost or maxPerTimeBonus can be gained
 java.lang.String getName()
          gets rule's name (user-defined)
 java.lang.String getNameNoSpaces()
          gets rule's name with underscores in place of spaces (user-defined)
 java.util.HashMap<java.lang.String,TestNumPair> getTestsToTrack()
          gets what tests are being tracked by this rule
 boolean getUseBasicCode()
          sets whether or not to use the basic code (false => user-specified code)
 boolean getUseUniqueResults()
          Gets whether or not results can only be used once in this scoring rule
 void prepareRule(TestSuite ts)
          Prepare this rule for execution -- determines what tests need to be tracked and builds the logic
 void setCode(java.lang.String code)
          sets the code which describes this logic
 void setCode(java.lang.String code, TestSuite ts)
          sets the code which describes this logic
 void setDescription(java.lang.String description)
          sets explains what this rule does
 void setMaxBonus(int maxBonus)
          sets total points which can be gained by bonuses applied by this rule
 void setMaxDeduction(int maxDeducation)
          sets total points which can be lost by penalties applied by this rule (a negative magnitude)
 void setMaxPerTimeBonus(int maxPerTimeBonus)
          sets maximum number of points which can be gained in maxPerTimeSecs seconds
 void setMaxPerTimeDeduction(int maxPerTimeDeduction)
          sets maximum number of points which can be lost in maxPerTimeSecs seconds
 void setMaxPerTimeMinutes(int maxPerTimeMins)
          sets number of minutes in which no more than maxPerTimeDeduction can be lost or maxPerTimeBonus can be gained
 void setMaxPerTimeSecs(int maxPerTimeSecs)
          sets number of seconds in which no more than maxPerTimeDeduction can be lost or maxPerTimeBonus can be gained
 void setName(java.lang.String name)
          sets rule's name (user-defined)
 void setUseBasicCode(boolean useBasicCode)
          gets whether or not to use the basic code (false => user-specified code)
 void setUseUniqueResults(boolean useUniqueResults)
          Sets whether or not results can only be used once in this scoring rule.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScoringRule

public ScoringRule()
default constructor

Method Detail

applies

public boolean applies(TestItem ti)
Whether or not a specified TestItem applies here. Only accurate after this rule has been prepared by a call to prepareRule.

Parameters:
ti - the TestItem to check
Returns:
true if the specified TestItem is used by this rule

clone

public java.lang.Object clone()
Returns a clone of this scoring rule. The copy will contain a reference to a clone of the internal test results hash map, not a reference to the original internal test results hash map of this ScoringRule object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this scoring rule

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

executeLogic

public java.util.Vector<TestScoreEvent> executeLogic(TestSuite suite,
                                                     TestEvent t)
                                              throws LogicException
executes the scoring logic on the specified TestEvent and returns any resulting TestScoreEvents, or null if none was generated (this just passes the TestEvent to ScoringLogic's executeLogic method)

Parameters:
suite - the suite which score events generated by this context refer to
t - the TestEvent whose result is to be considered by the logic
Returns:
an empty vector if score wasn't impacted by the specified TestEvent. Otherwise, the return is a TestScoreEvent which details the score change.
Throws:
LogicException - occurs if a runtime error occurs in the scoring language

prepareRule

public void prepareRule(TestSuite ts)
                 throws LogicException,
                        ParseException,
                        TokenMgrError
Prepare this rule for execution -- determines what tests need to be tracked and builds the logic

Parameters:
ts - the TestSuite which holds this
Throws:
LogicException - if there is a problem processing the code's logic
ParseException - if there is a problem parsing the code
TokenMgrError - if there is a problem parsing the code

checkCode

public static void checkCode(java.lang.String code,
                             TestSuite ts)
                      throws LogicException,
                             ParseException,
                             TokenMgrError
checks the specified code for compile-time errors

Parameters:
code - the code to check
ts - the test suite to check
Throws:
LogicException - if there is a problem processing the code's logic
ParseException - if there is a problem parsing the code
TokenMgrError - if there is a problem parsing the code

checkCode

public void checkCode(TestSuite ts)
               throws LogicException,
                      ParseException,
                      TokenMgrError
checks the code which describes this logic for compile-time errors

Parameters:
ts - the test suite to check
Throws:
LogicException - if there is a problem processing the code's logic
ParseException - if there is a problem parsing the code
TokenMgrError - if there is a problem parsing the code

getCode

public java.lang.String getCode()
gets the code which describes this logic


setCode

public void setCode(java.lang.String code)
             throws LogicException,
                    ParseException,
                    TokenMgrError
sets the code which describes this logic

Throws:
ParseException - if there is a problem with the code (the code will, however, still be saved even if it is invalid!)
TokenMgrError - if there is a problem parsing the code
LogicException

setCode

public void setCode(java.lang.String code,
                    TestSuite ts)
             throws LogicException,
                    ParseException,
                    TokenMgrError
sets the code which describes this logic

Throws:
LogicException - if there is a problem processing the code's logic (the code will, however, still be saved even if it is invalid!)
ParseException - if there is a problem parsing the code (the code will, however, still be saved even if it is invalid!)
TokenMgrError - if there is a problem parsing the code

getName

public java.lang.String getName()
gets rule's name (user-defined)


getNameNoSpaces

public java.lang.String getNameNoSpaces()
gets rule's name with underscores in place of spaces (user-defined)


setName

public void setName(java.lang.String name)
             throws IllegalArgValException
sets rule's name (user-defined)

Throws:
IllegalArgValException

getDescription

public java.lang.String getDescription()
gets explains what this rule does


setDescription

public void setDescription(java.lang.String description)
sets explains what this rule does


getMaxDeduction

public int getMaxDeduction()
gets total points which can be lost by penalties applied by this rule


setMaxDeduction

public void setMaxDeduction(int maxDeducation)
sets total points which can be lost by penalties applied by this rule (a negative magnitude)


getMaxPerTimeDeduction

public int getMaxPerTimeDeduction()
gets maximum number of points which can be lost in maxPerTimeSecs seconds


getMaxBonus

public int getMaxBonus()
gets total points which can be gained by bonuses applied by this rule


setMaxBonus

public void setMaxBonus(int maxBonus)
sets total points which can be gained by bonuses applied by this rule


getMaxPerTimeBonus

public int getMaxPerTimeBonus()
gets maximum number of points which can be gained in maxPerTimeSecs seconds


setMaxPerTimeBonus

public void setMaxPerTimeBonus(int maxPerTimeBonus)
sets maximum number of points which can be gained in maxPerTimeSecs seconds


setMaxPerTimeDeduction

public void setMaxPerTimeDeduction(int maxPerTimeDeduction)
sets maximum number of points which can be lost in maxPerTimeSecs seconds


getMaxPerTimeSecs

public int getMaxPerTimeSecs()
gets number of seconds in which no more than maxPerTimeDeduction can be lost or maxPerTimeBonus can be gained


setMaxPerTimeSecs

public void setMaxPerTimeSecs(int maxPerTimeSecs)
sets number of seconds in which no more than maxPerTimeDeduction can be lost or maxPerTimeBonus can be gained


getMaxPerTimeMinutes

public int getMaxPerTimeMinutes()
gets number of minutes in which no more than maxPerTimeDeduction can be lost or maxPerTimeBonus can be gained


setMaxPerTimeMinutes

public void setMaxPerTimeMinutes(int maxPerTimeMins)
sets number of minutes in which no more than maxPerTimeDeduction can be lost or maxPerTimeBonus can be gained


getTestsToTrack

public java.util.HashMap<java.lang.String,TestNumPair> getTestsToTrack()
gets what tests are being tracked by this rule


getUseUniqueResults

public boolean getUseUniqueResults()
Gets whether or not results can only be used once in this scoring rule


setUseUniqueResults

public void setUseUniqueResults(boolean useUniqueResults)
Sets whether or not results can only be used once in this scoring rule. If true, then whenever this rule generate a TestScoreEvent(s) with the executeLogic method, all known results are purged so that only new results will contribute to future scoring. For example, if something was required to happen three times for a TestScoreEvent to fire and this was set to true and that something happened five times then this rule would fire only once -- however, if this was set to false, this rule would fire a TestScoreEvent three times: [1,2,3]+[2,3,4]+[3,4,5].

Parameters:
useUniqueResults - true means only test results which have not previously contributed to a TestScoreEvent from this rule will be used

getUseBasicCode

public boolean getUseBasicCode()
sets whether or not to use the basic code (false => user-specified code)


setUseBasicCode

public void setUseBasicCode(boolean useBasicCode)
gets whether or not to use the basic code (false => user-specified code)


getBasicCode

public ScoringRule.BasicCodeGenerator getBasicCode()
gets the basic code generator and information