package tcra.exercises.resolve_one_way_list_private;

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

public class ResolveOneWayList_PostSwapPrevEntryAssertion implements
      Assertion
{
   public ResolveOneWayList_PostSwapPrevEntryAssertion() {}
   
   @SuppressWarnings("unchecked")
   public boolean check(List<MathType> t)
   {
      MathString<MathType> lb_prec = (MathString<MathType>)t.get(0);
      MathString<MathType> lb_rem  = (MathString<MathType>)t.get(1);
      MathInteger          lb_ent  = (MathInteger)t.get(2);
      MathString<MathType> prec    = (MathString<MathType>)t.get(3);
      MathString<MathType> rem     = (MathString<MathType>)t.get(4);
      MathInteger          ent     = (MathInteger)t.get(5);
      
      if(!rem.equals(lb_rem)) return false;
      
      MathString<MathType> lb_a = lb_prec.split(lb_prec.length()-2).elementAt(0);
      MathString<MathType> a    = prec.split(prec.length()-2).elementAt(0);
      
      if(!lb_prec.equals(lb_a.concat(ent))) return false;
      if(!prec.equals(a.concat(lb_ent)))    return false;
      
      return(true);
   } // end check(List<MathType>)

   @SuppressWarnings("unchecked")
   public String toInstanceString(List<MathType> t)
   {
      MathString<MathType> lb_prec = (MathString<MathType>)t.get(0);
      MathString<MathType> lb_rem  = (MathString<MathType>)t.get(1);
      MathInteger          lb_ent  = (MathInteger)t.get(2);
      MathString<MathType> prec    = (MathString<MathType>)t.get(3);
      MathString<MathType> rem     = (MathString<MathType>)t.get(4);
      MathInteger          ent     = (MathInteger)t.get(5);
      
      MathString<MathType> lb_a = lb_prec.split(lb_prec.length()-2).elementAt(0);
      MathString<MathType> a    = prec.split(prec.length()-2).elementAt(0);
      
      return ""+rem.toHTMLString()+" = "+lb_rem.toHTMLString()+
             " and (there exists A: Str(Entry),<br>"+
             lb_prec.toHTMLString()+" = "+lb_a.toHTMLString()+
             " o &lt; "+ent+" &gt; and "+prec.toHTMLString()+" = "+
             a.toHTMLString()+" o &lt; "+lb_ent+" &gt; ;";
   } // end toInstanceString(List<MathType>)

   public String toString()
   {
      return "P.Rem = #P.Rem and (there exists A: Str(Entry),<br>"+
             " #P.Prec = A o &lt; E &gt; and P.Prec = A o &lt; #E &gt;)";
   } // end toString()
} // end class
