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_Rem_CapacityContract extends
      MethodContract
{
   protected MathString<MathType> lb_self;
   protected MathString<MathType> self;
   protected MathInteger          rem_capacity;

   public ResolveBoundedQueue_Rem_CapacityContract()
   {
      super("Rem_Capacity");
      precondition  = new TrueAssertion();
      postcondition =
                 new ResolveBoundedQueue_PostRem_CapacityAssertion();
      returnType = new IntType();
      
      lb_self = self = null;
      rem_capacity   = 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]));
      self         = msp.parse(new StringBuilder(l[1]));
      rem_capacity = mip.parse(new StringBuilder(l[2]));
      
      if(lb_self == null ||
            self == null || rem_capacity == null)
            throw new MathFormatException(
                      "One or more unparsable arguments.");
      
      Vector<MathType> state = new Vector<MathType>();
      state.add(lb_self);
      state.add(self);
      state.add(rem_capacity);
      
      return(precondition.check(state) &&
             postcondition.check(state));
   } // end check(String)
   
   public String toString()
   {
      return("<html>Operation Rem_Capacity(restores Q: Queue): "+
             "Integer;<br>ensures " + postcondition);
   } // end toString()

   public String toInstanceString()
   {
      Vector<MathType> state = new Vector<MathType>();
      state.add(lb_self);
      state.add(self);
      state.add(rem_capacity);
      
      return("<html>Operation Rem_Capacity(restores Q: Queue): "+
             "Integer;<br>ensures " +
             postcondition.toInstanceString(state));
   } // end toInstanceString()
} // end class
