package tcra.exercises.q2_mystery_private;

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

public class Q2MysteryExercise_Mystery3 extends MethodContract
{
   protected MathString<MathType> lb_self;
   protected MathInteger          lb_index;
   protected MathInteger          lb_count;
   protected MathString<MathType> self;
   protected MathInteger          index;
   protected MathInteger          count;
   
   public Q2MysteryExercise_Mystery3()
   {
      super("Mystery3");
      precondition  = new Q2MysteryExercise_PreMystery3Assertion();
      postcondition = new Q2MysteryExercise_PostMystery3Assertion();
      returnType    = new VoidType();
      
      args.add(new MethodArgument("index", new IntegerType()));
      args.add(new MethodArgument("count", new IntegerType()));
      
      lb_self = self = null;
      lb_index = lb_count = index = count = 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]));
      lb_index = mip.parse(new StringBuilder(l[1]));
      lb_count = mip.parse(new StringBuilder(l[2]));
      self     = msp.parse(new StringBuilder(l[3]));
      index    = mip.parse(new StringBuilder(l[4]));
      count    = mip.parse(new StringBuilder(l[5]));
      
      if(lb_self == null || self == null     || lb_index == null ||
         index  == null  || lb_count == null || count == null)
         throw new MathFormatException(
                   "One or more unparsable objects.");
      
      Vector<MathType> state = new Vector<MathType>();
      state.add(lb_self);
      state.add(lb_index);
      state.add(lb_count);
      state.add(self);
      state.add(index);
      state.add(count);
      
      return(precondition.check(state) &&
             postcondition.check(state));
   } // end check(String[])
   
   public String toString()
   {
      return("<html>void Mystery3(int index, int count)<br>"+
    		 "Pre: "+precondition.toString()+
    		 "<br>Post: "+postcondition.toString());
   } // end toString()

   public String toInstanceString()
   {
	  Vector<MathType> state = new Vector<MathType>();
	  state.add(lb_self);
      state.add(lb_index);
      state.add(lb_count);
      state.add(self);
      state.add(index);
      state.add(count);
      
	  return("<html>void Mystery3(int index, int count)<br>"+
			 "Pre: "+precondition.toInstanceString(state)+
			 "<br>Post: "+postcondition.toInstanceString(state));
   } // end toInstanceString()
} // end class
