package tcra.exercises.q3_mystery_private;

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

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

   @SuppressWarnings("unchecked")
   public boolean check(List<MathType> t)
   {
      MathString<MathType> lb_self = (MathString<MathType>)t.get(0);
      MathString<MathType> lb_b    = (MathString<MathType>)t.get(1);
      MathString<MathType> self    = (MathString<MathType>)t.get(2);
      MathString<MathType> b       = (MathString<MathType>)t.get(3);
      
      Vector<MathType> zipper = new Vector<MathType>();
      for(int i = 0; i < lb_self.length(); ++i)
      {
    	  zipper.add(lb_self.elementAt(i));
    	  zipper.add(lb_b.elementAt(i));
      } // end for
      
      return(self.equals(new MathString<MathType>(zipper, null)));
   } // end check(List)
   
   public String toString()
   {
      return("there exists int N = |#self|; A1, A2, ..., AN, B1, B2, ..., BN: Object such that<br>"+
    		 "#self = &lt;A1&gt; * &lt;A2&gt; * ... * &lt;AN&gt; and<br>"+
    		 "#b = &lt;B1&gt; * &lt;B2&gt; * ... * &lt;BN&gt; and<br>"+
    		 "self = &lt;A1&gt; * &lt;B1&gt; * &lt;A2&gt; * &lt;B2&gt; * ... * &lt;AN&gt; * &lt;BN&gt;;");
   } // end toString()

   @SuppressWarnings("unchecked")
   public String toInstanceString(List<MathType> t)
   {
      MathString<MathType> lb_self = (MathString<MathType>)t.get(0);
      MathString<MathType> lb_b    = (MathString<MathType>)t.get(1);
      MathString<MathType> self    = (MathString<MathType>)t.get(2);
      MathString<MathType> b       = (MathString<MathType>)t.get(3);
      
      Vector<MathType> zipper = new Vector<MathType>();
      for(int i = 0; i < lb_self.length(); ++i)
      {
    	  zipper.add(lb_self.elementAt(i));
    	  zipper.add(lb_b.elementAt(i));
      } // end for
      
      String inorder;
      if(lb_self.length() > 3)
      {
    	  inorder = lb_self.toHTMLString()+" = &lt;"+lb_self.elementAt(0).toHTMLString() + "&gt; * &lt;" +
    	            lb_self.elementAt(1).toHTMLString() + "&gt; * ... * &lt;" +
    	            lb_self.elementAt(lb_self.length()-1) + "&gt and<br>"+
    	            lb_b.toHTMLString()+" = &lt;"+lb_b.elementAt(0).toHTMLString() + "&gt; * &lt;" +
                    lb_b.elementAt(1).toHTMLString() + "&gt; * ... * &lt;" +
                    lb_b.elementAt(lb_b.length()-1) + "&gt;";
      }
      else if(lb_self.length() == 3)
      {
    	  inorder = lb_self.toHTMLString()+" = &lt;"+lb_self.elementAt(0).toHTMLString() + "&gt; * &lt;" +
    	            lb_self.elementAt(1).toHTMLString() + "&gt; * &lt;" +
    	            lb_self.elementAt(2) + "&gt; and<br>"+
    	            lb_b.toHTMLString()+" = &lt;"+lb_b.elementAt(0).toHTMLString() + "&gt; * &lt;" +
    	            lb_b.elementAt(1).toHTMLString() + "&gt; * &lt;" +
    	            lb_b.elementAt(2) + "&gt;";
      }
      else if(lb_self.length() == 2)
      {
    	  inorder = lb_self.toHTMLString()+" = &lt;"+lb_self.elementAt(0).toHTMLString() + "&gt; * &lt;" +
    	            lb_self.elementAt(1).toHTMLString() + "&gt; and<br>"+
    	            lb_b.toHTMLString()+" = &lt;"+lb_b.elementAt(0).toHTMLString() + "&gt; * &lt;" +
    	            lb_b.elementAt(1).toHTMLString() + "&gt;";
      }
      else if(lb_self.length() == 1)
      {
    	  inorder = lb_self.toHTMLString()+" = &lt;"+lb_self.elementAt(0).toHTMLString() + "&gt; and<br>"+
    	            lb_b.toHTMLString()+" = &lt;"+lb_b.elementAt(0).toHTMLString() + "&gt;";
      }
      else
      {
    	  inorder = lb_self.toHTMLString()+" = &lt;&gt; and<br>"+
    	            lb_b.toHTMLString()+" = &lt;&gt;";
      }
      
      return("there exists int N = |#self|; A1, A2, ..., AN, B1, B2, ..., BN: Object such that<br>"+
     		 inorder+"<br>"+self.toHTMLString()+" = "+new MathString<MathType>(zipper, null).toHTMLString()+";");	  
   } // end toInstanceString(List)
} // end class
