// Approach 2:  Testing Shell

// OutputFormatter2 Class

import OurSinglyLinkedList2;
import Terminal2;
import GUI2;

public class OutputFormatter2 {
    SimpleOutput simpOut;
    int correctnessLevel;
    SchemeTesterInterface2 outTarget;

    /** genOutput method receives results from the coordinator program
     * and formats them into a list.
     */

    public OutputFormatter2 (SchemeTesterInterface2 sender, int correctness) {
        outTarget = sender;
        correctnessLevel = correctness;
        simpOut = new SimpleOutput ();
    }

    public void genOutput (OurSinglyLinkedList2 testList,
                           OurSinglyLinkedList2 aResultList,
                           OurSinglyLinkedList2 uResultList,
                           OurSinglyLinkedList2 correctList
                           ) {

        simpOut.println ("OutputFormatter2::genOutput called with parameters:");
        simpOut.println ("     test case list:  " + testList);
        simpOut.println ("     authority results list:  " + aResultList.toString());
        simpOut.println ("     user results list:  " + uResultList.toString());
        simpOut.println ("     correctness list:  " + correctList);
    

        SinglyLinkedListElement2 testPtr = (SinglyLinkedListElement2) testList.getHead();
        SinglyLinkedListElement2 authPtr = (SinglyLinkedListElement2)aResultList.getHead();
        SinglyLinkedListElement2 userPtr = (SinglyLinkedListElement2)uResultList.getHead();
        SinglyLinkedListElement2 corrPtr = (SinglyLinkedListElement2)correctList.getHead();

        String results ="";
        // while loop to go through the lists and add them to results

       while(corrPtr != null){
           results += "test case" + testPtr.value()
                   + "\n     correctness level " + corrPtr.value()
                   + "\n     authority results:  " + authPtr.value()
                   + "\n     user results:  " + userPtr.value() + "\n\n";
           corrPtr = corrPtr.next();
           authPtr = authPtr.next();
           userPtr = userPtr.next();           
       }//while

       // Sending the results to the interface.
       outTarget.printer(results);

    }//genOutput
}//OutputFormatter2()
