package tcra.exercises.resolve_delete_entries_private;

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

public class ResolveDeleteEntries_Delete_EntriesContract extends
      MethodContract
{
   protected MathString<MathType> lb_self;
   protected MathInteger          lb_index;
   protected MathString<MathType> self;
   protected MathInteger          index;
   
   public ResolveDeleteEntries_Delete_EntriesContract()
   {
      super("Delete_Entries");
      precondition  =
                new ResolveDeleteEntries_PreDelete_EntriesAssertion();
      postcondition = 
               new ResolveDeleteEntries_PostDelete_EntriesAssertion();
      args.add(new MethodArgument("k", new IntType()));
      returnType = new VoidType();
      
      lb_self  = self  = null;
      lb_index = index = null;
   } // end ctor

   public boolean check(String[] l) throws MathFormatException
   {
      MathIntegerParser mip = new MathIntegerParser();
      MathStringParser  msp = new MathStringParser(mip);
      lb_self  = msp.parse(new StringBuilder(l[0]));
      lb_index = mip.parse(new StringBuilder(l[1]));
      self     = msp.parse(new StringBuilder(l[2]));
      index    = mip.parse(new StringBuilder(l[3]));
      
      Vector<MathType> state = new Vector<MathType>();
      state.add(lb_self);
      state.add(lb_index);
      state.add(self);
      state.add(index);
      
      return(precondition.check(state) &&
             postcondition.check(state));
   } // end check(String[])

   public String toString()
   {
      return("<html>Operation Delete_Entries(restores k: Integer; "+
             "updates S: Stack);<br>"+
             "restores " + precondition +
             "<br>ensures " + postcondition);
   } // end toString()
   
   public String toInstanceString()
   {  
      Vector<MathType> state = new Vector<MathType>();
      state.add(lb_self);
      state.add(lb_index);
      state.add(self);
      state.add(index);
      
      return("<html>Operation Delete_Entries(restores k: Integer; "+
            "updates S: Stack);<br>"+
            "restores " + precondition.toInstanceString(state) +
            "<br>ensures " + postcondition.toInstanceString(state));
   } // end toInstanceString()
} // end class
