package tcra.exercises.q3_mystery_private;

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

public class Q3MysteryExercise_Mystery2 extends MethodContract
{
   protected MathString<MathType> lb_self;
   protected MathInteger          lb_index;
   protected MathString<MathType> lb_b;
   protected MathString<MathType> self;
   protected MathInteger          index;
   protected MathString<MathType> b;
   
   public Q3MysteryExercise_Mystery2()
   {
      super("Mystery2");
      precondition  = new Q3MysteryExercise_PreMystery2Assertion();
      postcondition = new Q3MysteryExercise_PostMystery2Assertion();
      returnType    = new VoidType();
      
      args.add(new MethodArgument("index", new IntegerType()));
      args.add(new MethodArgument("b", new MathStringType()));
      
      lb_self = self = lb_b = b = null;
      lb_index = index = 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_b     = msp.parse(new StringBuilder(l[2]));
      self     = msp.parse(new StringBuilder(l[3]));
      index    = mip.parse(new StringBuilder(l[4]));
      b        = msp.parse(new StringBuilder(l[5]));
      
      if(lb_self == null || self == null || lb_b == null || b == null ||
         lb_index == null || index == 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_b);
      state.add(self);
      state.add(index);
      state.add(b);
      
      return(precondition.check(state) &&
             postcondition.check(state));
   } // end check(String[])
   
   public String toString()
   {
      return("<html>void Mystery2(int index, String b)<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_b);
      state.add(self);
      state.add(index);
      state.add(b);
      
	  return("<html>void Mystery2(int index, String b)<br>Pre: "+precondition.toInstanceString(state)+
			 "<br>Post: "+postcondition.toInstanceString(state));
   } // end toInstanceString()
} // end class
