package tcra.exercises.resolve_delete_entries_private;

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

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

   @SuppressWarnings("unchecked")
   public boolean check(List<MathType> t)
   {
      MathString<MathType> lb_self  = (MathString<MathType>)t.get(0);
      MathInteger          lb_index = (MathInteger)t.get(1);
      MathString<MathType> self     = (MathString<MathType>)t.get(2);
      MathInteger          index    = (MathInteger)t.get(3);
      
      if(!index.equals(lb_index))
         return false;
      if(!lb_self.isSuffix(self))
         return false;
      if(lb_index.getValue()+self.length() != lb_self.length())
         return false;
      
      return true;
   } // end check(List)

   public String toString()
   {
      return("Is_Suffix(S, #S) <b>and</b> |S| + k = |#S|;");
   } // end toString()
   
   @SuppressWarnings("unchecked")
   public String toInstanceString(List<MathType> t)
   {
      MathString<MathType> lb_self  = (MathString<MathType>)t.get(0);
      MathInteger          lb_index = (MathInteger)t.get(1);
      MathString<MathType> self     = (MathString<MathType>)t.get(2);
      
      return("Is_Suffix("+self.toHTMLString()+", "+
             lb_self.toHTMLString()+") <b>and</b> |"+
             self.toHTMLString()+"| + "+lb_index.toHTMLString()+
             " = |"+lb_self.toHTMLString()+"|;");
   } // end toInstanceString(List)
} // end class
