package tcra.exercises.resolve_replica_capability_private;

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

public class ResolveReplicaCapability_ReplicaContract extends
      MethodContract
{
   protected MathString<MathType> lb_self;
   protected MathString<MathType> self;
   protected MathString<MathType> replica;
   
   public ResolveReplicaCapability_ReplicaContract()
   {
      super("Replica");
      precondition  = new TrueAssertion();
      postcondition =
                   new ResolveReplicaCapability_PostRepliaAssertion();
      returnType = new QueueType();
      
      lb_self = self = replica = null;
   } // end ctor

   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]));
      replica = msp.parse(new StringBuilder(l[2]));
      
      Vector<MathType> state = new Vector<MathType>();
      state.add(lb_self);
      state.add(self);
      state.add(replica);
      
      return(precondition.check(state) &&
             postcondition.check(state));
   } // end check(String[])

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