package LogParser;

import java.util.*;

public class XMLLog
{
   private Vector<XMLLog_SessionEntry> entries;
   private String id;
   
   public XMLLog(String id)
   {
      this.id = id;
      entries = new Vector<XMLLog_SessionEntry>();
   } // end ctor
   
   public void addEntry(XMLLog_SessionEntry se) { entries.add(se); }
   
   public Vector<String> getUniqueFilenames()
   {
      Vector<String> files = new Vector<String>(entries.elementAt(0).getUniqueFilenames());
      for(int i = 1; i < entries.size(); ++i)
      {
         Vector<String> temp = entries.elementAt(i).getUniqueFilenames();
         for(int j = 0; j< temp.size(); ++j)
         {
            if(!files.contains(temp.elementAt(j)))
               files.add(temp.elementAt(j));
         } // end for
      } // end for
      
      return files;
   } // end getUniqueFilenames()
   
   public Vector<String> getMethods(String filename)
   {
      Vector<String> results = new Vector<String>();
      for(int i = 0; i < entries.size(); ++i)
      {
         Vector<String> temp = entries.elementAt(i).getMethods(filename);
         for(int j = 0; j < temp.size(); ++j)
         {
            if(!results.contains(temp.elementAt(j)))
               results.add(temp.elementAt(j));
         } // end for
      } // end for
      return results;
   } // end getMethods(String)
   
   public int correctnessQuery(String exercise, String method,
                           boolean correctness, Date from, Date to)
   {
      int count = 0;
      for(int i = 0; i < entries.size(); ++i)
      {
         //System.out.println("Searching session "+i);
         count += entries.elementAt(i).correctnessQuery(exercise,
                                       method, correctness, from, to);
      } // end for
      return count;
   } // end correctnessQuery(String,String,bool,Date,Date)
   
   public String getID() { return id; }
   
   public String toString()
   {
      String temp = "<TCRA_Log id="+id+">\n";
      for(int i = 0; i < entries.size(); ++i)
         temp += entries.elementAt(i)+"\n";
      temp += "</TCRA_Log>\n";
      
      return temp;
   } // end toString()
} // end class
