package tcra.exercises.resolve_bounded_queue_private;

import java.util.*;
import tcra.math.*;
import tcra.programmatic.*;
import tcra.exercises.general_assertions.TrueAssertion;

public class ResolveBoundedQueue_ClearContract extends MethodContract
{
   protected MathString<MathType> lb_self;
   protected MathString<MathType> self;
   
   public ResolveBoundedQueue_ClearContract()
   {
      super("Clear");
      precondition  = new TrueAssertion();
      postcondition = new ResolveBoundedQueue_PostClearAssertion();
      returnType    = new VoidType();
      
      lb_self = self = null;
   } // end ctor

   @Override
   public boolean check(String[] l) throws MathFormatException
   {
      MathStringParser msp = new MathStringParser(
                             new MathIntegerParser());
      lb_self = msp.parse(new StringBuilder(l[0]));
      self    = msp.parse(new StringBuilder(l[1]));
      
      if(lb_self == null || self == null)
            throw new MathFormatException(
                      "One or more unparsable arguments.");
      
      Vector<MathType> state = new Vector<MathType>();
      state.add(lb_self);
      state.add(self);

      return(precondition.check(state) &&
             postcondition.check(state));
   } // end check(String[])
   
   public String toString()
   {
      return("<html>Operation Clear(clears Q: Queue);");
   } // end toString()

   @Override
   public String toInstanceString()
   {
      return("<html>Operation Clear(clears Q: Queue);");
   } // end toInstanceString()
} // end class
