package tcra.exercises.resolve_preemptable_queue_private;

import java.util.List;
import tcra.math.Assertion;
import tcra.math.MathInteger;
import tcra.math.MathString;
import tcra.math.MathType;

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

   @SuppressWarnings("unchecked")
   public boolean check(List<MathType> t)
   {
      MathString<MathType> lb_self = (MathString<MathType>)t.get(0);
      MathInteger          lb_swap = (MathInteger)t.get(1);
      MathString<MathType> self    = (MathString<MathType>)t.get(2);
      MathInteger          swap    = (MathInteger)t.get(3);
      
      MathString<MathType> pre =
      (MathString<MathType>)lb_self.split(lb_self.length()-2).get(0);
      
      if(!lb_self.equals(pre.concat(swap))) return false;
      if(!self.equals(pre.concat(lb_swap))) return false;
      return true;
   } // end check(List)
   
   public String toString()
   {
      return("∃ Pre: Str(Integer) ∋ #Q = Pre * &lt;I&gt; "+
             "and Q = Pre * &lt;#E&gt;");
   } // end toString()

   @SuppressWarnings("unchecked")
   public String toInstanceString(List<MathType> t)
   {
      MathString<MathType> lb_self = (MathString<MathType>)t.get(0);
      MathInteger          lb_swap = (MathInteger)t.get(1);
      MathString<MathType> self    = (MathString<MathType>)t.get(2);
      MathInteger          swap    = (MathInteger)t.get(3);
      
      MathString<MathType> pre =
      (MathString<MathType>)lb_self.split(lb_self.length()-2).get(0);
      
      return("∃ Pre: Str(Integer) ∋ "+lb_self.toHTMLString()+" = "+
             pre.toHTMLString()+" * &lt;"+swap.toHTMLString()+
             "&gt; and "+self.toHTMLString()+" = "+pre.toHTMLString()+
             " * &lt;"+lb_swap.toHTMLString()+"&gt;");
   } // end toInstanceString(List)\
} // end class
