package tcra.math;

import java.util.List;
import java.util.Vector;
import tcra.programmatic.MethodArgument;
import tcra.programmatic.ProgrammingType;

/**
 * Representation of a method's formal contract.
 *
 * @param name Method name
 * @param precondition Assertion that must hold before this method
 *                     is called
 * @param postcondition Assertion that must hold after this method
 *                      has finished executing.
 * @param args Arguments that would be passed to this method
 * @param returnType Programming type of the return value
 */
public abstract class MethodContract
{
   protected String name;
   protected Assertion precondition;
   protected Assertion postcondition;
   protected Vector<MethodArgument> args;
   protected ProgrammingType returnType;
   
   protected MethodContract(String name) 
   {
      this.name = name;
      args = new Vector<MethodArgument>();
   }

   /**
    * Returns the signature of the method being tested.
    *
    * @return the signature of the method
    */
   public String getMethodName() { return name; }

   /**
    * Returns the preconditional Assertion.
    *
    * @return the preconditional assertion
    */
   public Assertion getPrecondition() { return precondition; }

   /**
    * Returns the postconditional Assertion.
    *
    * @return the postconditional assertion
    */
   public Assertion getPostcondition() { return postcondition; }

   /**
    * Returns the list of arguments required by this method.
    *
    * @return list of Arguments
    */
   public List<MethodArgument> getArgs() { return args; }

   /**
    * Returns the programming type of what is returned from this
    * method.
    *
    * @return programming type of the return value
    */
   public ProgrammingType getReturnType() { return returnType; }

   /**
    * Returns whether the supplied values hold to the precondition
    * and postcondition using the Assertions' check method.<br>
    * It is recommended that the parsed input is saved in a private
    * variable of any extending class for use in the toInstanceString
    * method.
    *
    * @param l User input obtained from the GUI. Must be parsed
    *          by the contract to obtain the correct MathType objects
    * @return <code>true</code> if the user input is parsed correctly
    *         and the values hold to the pre and postconditions.
    *         <code>false</code> if the values do not hold to the
    *         precondition and postcondition.
    * @throws MathFormatException If the parsing of the user input
    *                             goes awry.
    */
   public abstract boolean check(String[] l)
      throws MathFormatException;
   public abstract String toInstanceString();
}
