package tcra.exercises.q2_mystery_private;

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

public class Q2MysteryExercise_Mystery5 extends MethodContract
{
   protected MathString<MathType> lb_self;
   protected MathInteger          lb_a1;
   protected MathInteger          lb_a2;
   protected MathInteger          lb_b1;
   protected MathInteger          lb_b2;
   protected MathString<MathType> self;
   protected MathInteger          a1;
   protected MathInteger          a2;
   protected MathInteger          b1;
   protected MathInteger          b2;
   
   public Q2MysteryExercise_Mystery5()
   {
      super("Mystery5");
      precondition  = new Q2MysteryExercise_PreMystery5Assertion();
      postcondition = new Q2MysteryExercise_PostMystery5Assertion();
      returnType    = new VoidType();
      
      args.add(new MethodArgument("a1", new IntegerType()));
      args.add(new MethodArgument("a2", new IntegerType()));
      args.add(new MethodArgument("b1", new IntegerType()));
      args.add(new MethodArgument("b2", new IntegerType()));
      
      lb_self = self = null;
      lb_a1 = lb_a2 = lb_b1 = lb_b2 = a1 = b1 = a2 = b2 = 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_a1   = mip.parse(new StringBuilder(l[1]));
      lb_a2   = mip.parse(new StringBuilder(l[2]));
      lb_b1   = mip.parse(new StringBuilder(l[3]));
      lb_b2   = mip.parse(new StringBuilder(l[4]));
      self    = msp.parse(new StringBuilder(l[5]));
      a1      = mip.parse(new StringBuilder(l[6]));
      a2      = mip.parse(new StringBuilder(l[7]));
      b1      = mip.parse(new StringBuilder(l[8]));
      b2      = mip.parse(new StringBuilder(l[9]));
      
      if(lb_self == null  || self == null || lb_a1 == null || lb_a2 == null ||
         a1      == null  || a2   == null || lb_b1 == null || b1    == null ||
         lb_b2   == null  || b2   == null)
         throw new MathFormatException(
                   "One or more unparsable objects.");
      
      Vector<MathType> state = new Vector<MathType>();
      state.add(lb_self);
      state.add(lb_a1);
      state.add(lb_a2);
      state.add(lb_b1);
      state.add(lb_b2);
      state.add(self);
      state.add(a1);
      state.add(a2);
      state.add(b1);
      state.add(b2);
      
      return(precondition.check(state) &&
             postcondition.check(state));
   } // end check(String[])
   
   public String toString()
   {
      return("<html>void Mystery5(int a1, int a2, int b1, int b2)<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_a1);
      state.add(lb_a2);
      state.add(lb_b1);
      state.add(lb_b2);
      state.add(self);
      state.add(a1);
      state.add(a2);
      state.add(b1);
      state.add(b2);
      
	  return("<html>void Mystery5(int a1, int a2, int b1, int b2)<br>"+
			 "Pre: "+precondition.toInstanceString(state)+
			 "<br>Post: "+postcondition.toInstanceString(state));
   } // end toInstanceString()
} // end class
