package tcra.exercises.q3_mystery_private;

import java.util.*;
import tcra.math.*;

public class Q3MysteryExercise_PostMystery5Assertion implements
      Assertion
{
   public Q3MysteryExercise_PostMystery5Assertion() {}

   @SuppressWarnings("unchecked")
   public boolean check(List<MathType> t)
   {
      MathString<MathType> lb_self = (MathString<MathType>)t.get(0);
      MathInteger          lb_a1   = (MathInteger)t.get(1);
      MathInteger          lb_a2   = (MathInteger)t.get(2);
      MathInteger          lb_b1   = (MathInteger)t.get(3);
      MathInteger          lb_b2   = (MathInteger)t.get(4);
      MathString<MathType> lb_b    = (MathString<MathType>)t.get(5);
      MathString<MathType> self    = (MathString<MathType>)t.get(6);
      MathInteger          a1      = (MathInteger)t.get(7);
      MathInteger          a2      = (MathInteger)t.get(8);
      MathInteger          b1      = (MathInteger)t.get(9);
      MathInteger          b2      = (MathInteger)t.get(10);
      MathString<MathType> b       = (MathString<MathType>)t.get(11);
      
      MathString<MathType> A, B, C, X, Y, Z, temp;
      
      A = lb_self.split(lb_a1.getValue()-1).get(0);
      temp = lb_self.split(lb_a1.getValue()-1).get(1);
      B = temp.split(lb_a2.getValue() - lb_a1.getValue() - 1).get(0);
      C = temp.split(lb_a2.getValue() - lb_a1.getValue() - 1).get(1);
      X = lb_b.split(lb_b1.getValue()-1).get(0);
      temp = lb_b.split(lb_b1.getValue()-1).get(1);
      Y = temp.split(lb_b2.getValue() - lb_b1.getValue() - 1).get(0);
      Z = temp.split(lb_b2.getValue() - lb_b1.getValue() - 1).get(1);
      
      if(A.length() != lb_a1.getValue()) return false;
      if(B.length() != lb_a2.getValue() - lb_a1.getValue()) return false;
      if(X.length() != lb_b1.getValue()) return false;
      if(Y.length() != lb_b2.getValue() - lb_b1.getValue()) return false;
      if(!self.equals(A.concat(Y.concat(C)))) return false;
      if(!b.equals(X.concat(B.concat(Z)))) return false;
      
      return true;
   } // end check(List)
   
   public String toString()
   {
      return("there exists A, B, C, X, Y, Z: String of Object such that<br>"+
             "#self = A * B * C and<br>"+
             "|A| = a1 and<br>"+
             "|B| = a2 - a1 and<br>"+
             "|X| = b1 and <br>"+
             "|Y| = b2 - b1 and<br>"+
             "self = A * Y * C and<br>"+
             "b = X * B * C;");
   } // end toString()

   @SuppressWarnings("unchecked")
   public String toInstanceString(List<MathType> t)
   {
      MathString<MathType> lb_self = (MathString<MathType>)t.get(0);
      MathInteger          lb_a1   = (MathInteger)t.get(1);
      MathInteger          lb_a2   = (MathInteger)t.get(2);
      MathInteger          lb_b1   = (MathInteger)t.get(3);
      MathInteger          lb_b2   = (MathInteger)t.get(4);
      MathString<MathType> lb_b    = (MathString<MathType>)t.get(5);
      MathString<MathType> self    = (MathString<MathType>)t.get(6);
      MathInteger          a1      = (MathInteger)t.get(7);
      MathInteger          a2      = (MathInteger)t.get(8);
      MathInteger          b1      = (MathInteger)t.get(9);
      MathInteger          b2      = (MathInteger)t.get(10);
      MathString<MathType> b       = (MathString<MathType>)t.get(11);
	      
      MathString<MathType> A, B, C, X, Y, Z, temp;
	      
      A = lb_self.split(lb_a1.getValue()-1).get(0);
      temp = lb_self.split(lb_a1.getValue()-1).get(1);
      B = temp.split(lb_a2.getValue() - lb_a1.getValue() - 1).get(0);
      C = temp.split(lb_a2.getValue() - lb_a1.getValue() - 1).get(1);
      X = lb_b.split(lb_b1.getValue()-1).get(0);
      temp = lb_b.split(lb_b1.getValue()-1).get(1);
      Y = temp.split(lb_b2.getValue() - lb_b1.getValue() - 1).get(0);
      Z = temp.split(lb_b2.getValue() - lb_b1.getValue() - 1).get(1);
      
      return("there exists A, B, C, X, Y, Z: String of Object such that<br>"+
              lb_self.toHTMLString()+" = "+A.toHTMLString()+" * "+B.toHTMLString()+" * "+C.toHTMLString()+" and<br>"+
              "|"+A.toHTMLString()+"| = "+lb_a1.toHTMLString()+" and<br>"+
              "|"+B.toHTMLString()+"| = "+lb_a2.toHTMLString()+" - "+lb_a1.toHTMLString()+" and<br>"+
              "|"+X.toHTMLString()+"| = "+lb_b1.toHTMLString()+" and <br>"+
              "|"+Y.toHTMLString()+"| = "+lb_b2.toHTMLString()+" - "+lb_b1.toHTMLString()+" and<br>"+
              self.toHTMLString()+" = "+A.toHTMLString()+" * "+Y.toHTMLString()+" * "+C.toHTMLString()+" and<br>"+
              b.toHTMLString()+" = "+X.toHTMLString()+" * "+B.toHTMLString()+" * "+Z.toHTMLString()+";");
   } // end toInstanceString(List)
} // end class
