org.problets.domain.model.control.iteration
Class InfiniteLoopModel

java.lang.Object
  extended by org.problets.domain.model.control.iteration.InfiniteLoopModel

public class InfiniteLoopModel
extends java.lang.Object

Class: InfiniteLoopModel Author: Greg Tomalesky Purpose: This class handles creating an explanation for an infinite loop based on six different types of relational operators: >, <, >=, <=, ==, != Each type of relational operator will have sub-divisions based on how a condition is always true. >, >= : - variable always increases in value relative to the value its being compared to - variable increases the same or greater amount than the valued being compared to does - variable stays the same relative to the value <, <= : - variable always decreases in value relative to the value being compared to - variable decreases the same or greater amount than the valued being compared to - variable stays the same relative to the value != : - variable moves away from the value being compared to - variable skips over value when incremented or decremented - variable moves the same amount or more than the value being compared to does - variable stays the same relative to the value == : - variable moves the same amount that the value being compared to does - variable stays the same relative to the value NOTE: Currently, this class does not handle cases where values are increasing geometrically or linearly


Constructor Summary
InfiniteLoopModel()
           
 
Method Summary
static double calculateChange(java.util.Vector valueVector, int iterations)
          public static double calculateChange(Vector valueVector, int iterations); This function will calculate the current amount by which either the condition or boundary value will change at the present iteration of the infinite loop.
static java.util.Vector explain(java.util.Vector conditionVector, java.util.Vector terminalVector, java.lang.String condition, Expression condition_exp)
          public static void explain(Vector condVector, Vector boundVector, String operator, Vector explanation); Generate an explanation for while an infinite loop is being terminated
static java.lang.String explainSkip(java.util.Vector condVector, java.util.Vector boundVector, java.lang.String leftSideName, java.lang.String rightSideName)
          private String explainSkip(Vector condVector, Vector boundVector); This function handles explaining any cases whereby the condition or bounds skips across the other.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InfiniteLoopModel

public InfiniteLoopModel()
Method Detail

calculateChange

public static double calculateChange(java.util.Vector valueVector,
                                     int iterations)
public static double calculateChange(Vector valueVector, int iterations); This function will calculate the current amount by which either the condition or boundary value will change at the present iteration of the infinite loop.

Parameters:
valueVector - - a vector that holds Values
iterations - - the current iteration of the simulated loop
Returns:
- returns the calculated difference

explainSkip

public static java.lang.String explainSkip(java.util.Vector condVector,
                                           java.util.Vector boundVector,
                                           java.lang.String leftSideName,
                                           java.lang.String rightSideName)
private String explainSkip(Vector condVector, Vector boundVector); This function handles explaining any cases whereby the condition or bounds skips across the other.

Parameters:
condVector - - a vector that holds values of the lhs in a condition
boundVector - - a vector that holds values of the rhs in a condition
Returns:
- returns a line explanation string

explain

public static java.util.Vector explain(java.util.Vector conditionVector,
                                       java.util.Vector terminalVector,
                                       java.lang.String condition,
                                       Expression condition_exp)
public static void explain(Vector condVector, Vector boundVector, String operator, Vector explanation); Generate an explanation for while an infinite loop is being terminated

Parameters:
condVector - - a vector that holds values of a variable in a condition
boundVector - - a vector that holds values of the value that is being compared to
explanation - - a Vector holding the generated explanations
condition - - a string holding the template for the condition
condition - - a string that holds the condition template
condition_exp - - an expression object representing the condition of a loop

main

public static void main(java.lang.String[] args)