package tcra.exercises.resolve_prefix_reversal_private;

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

public class ResolvePrefixReversalCapability_Prefix_ReversalExercise
      extends MethodContract
{
   protected MathString<MathType> lb_self;
   protected MathString<MathType> lb_pre;
   protected MathString<MathType> self;
   protected MathString<MathType> pre;
   
   public ResolvePrefixReversalCapability_Prefix_ReversalExercise()
   {
      super("Prefix_Reversal");
      precondition  = new
        ResolvePrefixReversalCapability_PrePrefix_ReversalAssertion();
      postcondition = new
       ResolvePrefixReversalCapability_PostPrefix_ReversalAssertion();
      args.add(new MethodArgument("Pre", new StackType()));
      returnType = new VoidType();
   } // end ctor

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

   public String toString()
   {
      return("<html>Operation Prefix_Reversal(clears Pre: Stack; "+
             "updates S: Stack);<br>" +
             "requires " + precondition +
             "<br>ensures " + postcondition);
   } // end toString()
   
   public String toInstanceString()
   {
      Vector<MathType> state = new Vector<MathType>();
      state.add(lb_self);
      state.add(lb_pre);
      state.add(self);
      state.add(pre);
      
      return("<html>Operation Prefix_Reversal(clears Pre: Stack; "+
             "updates S: Stack);<br>" +
             "requires " + precondition.toInstanceString(state) +
             "<br>ensures " + postcondition.toInstanceString(state));
   } // end toInstanceString()
} // end class
