package tcra.exercises.stack_reasoning_private;

import java.util.Vector;
import tcra.math.*;
import tcra.programmatic.*;
import tcra.exercises.general_assertions.*;

public class StackClearContract extends MethodContract
{
   protected MathString<MathType> lb_self;
   protected MathString<MathType> self;
	
   public StackClearContract()
   {
      super("clear");
      precondition  = new TrueAssertion();
      postcondition = new StackPostClearAssertion();
      args          = new Vector<MethodArgument>();
      returnType    = new VoidType();
            
      lb_self = null;
      self    = null;
   } // end ctor

   public boolean check(String[] l) throws MathFormatException
   {
      MathIntegerParser mip = new MathIntegerParser();
      MathStringParser  msp = new MathStringParser(mip);
      lb_self = msp.parse(new StringBuilder(l[0]));
      self    = msp.parse(new StringBuilder(l[1]));

      if(lb_self == null || self == null)
         throw new MathFormatException("One or more unparsable arguments.");
      
      Vector<MathType> args = new Vector<MathType>();
      args.add(lb_self);
      args.add(self);

      return (precondition.check(args) && postcondition.check(args));
   } // end check(List)

   public String toString()
   {
      return("<html>" + returnType + " " + name + "( )<br>" +
             "requires:<br>"+ precondition +
             "<br>ensures:<br>" + postcondition);
   } // end toString()

   public String toInstanceString()
   {
	  Vector<MathType> argVals = new Vector<MathType>();
	  argVals.add(lb_self);
	  argVals.add(self);
	   
      return("<html>" + returnType + " " + name + "( )<br>" +
             "requires:<br>"+
             precondition.toInstanceString(argVals) +
             "<br>ensures:<br>" +
             postcondition.toInstanceString(argVals));
   } // end toString(List)
} // end class
