package LogParser;

import java.util.*;

public class XMLLog_SessionEntry
{
   private Date                     timestamp;
   private Vector<XMLLog_FileEntry> entries;
   
   public XMLLog_SessionEntry() { entries = new Vector<XMLLog_FileEntry>(); }
   
   public void setTimestamp(Date date) { timestamp = date; }
   public Date getTimestamp() { return timestamp; }
   
   public void addEntry(XMLLog_FileEntry fe) { entries.add(fe); }
   
   public Vector<String> getUniqueFilenames()
   {
      Vector<String> uniqueNames = new Vector<String>();
      for(int i = 0; i < entries.size(); ++i)
      {
         if(!uniqueNames.contains(entries.elementAt(i).getName()))
            uniqueNames.add(entries.elementAt(i).getName());
      } // end for
      return uniqueNames;
   } // end getUniqueFilename
   
   public Vector<String> getMethods(String filename)
   {
      Vector<String> results = new Vector<String>();
      for(int i = 0; i < entries.size(); ++i)
      {
         if(entries.elementAt(i).getName().equals(filename))
         {
            Vector<String> temp = entries.elementAt(i).getMethods();
            for(int j = 0; j < temp.size(); ++j)
            {
               if(!results.contains(temp.elementAt(j)))
               {
                  results.add(temp.elementAt(j));
               }
            }
         } // end if
      } // 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)
      {
         if(entries.elementAt(i).getName().equals(exercise))
         {
            //System.out.println("Found file: " + exercise + " at element " + i);
            count += entries.elementAt(i).correctnessQuery(method, correctness, from, to);
         } // end if
      } // end for
      return count;
   } // end correctnessQuery(String,String,bool,Date,Date)
   
   public String toString()
   {
      String temp = "<Session timestamp=\""+timestamp+"\">\n";
      for(int i = 0; i < entries.size(); ++i)
         temp += entries.elementAt(i)+"\n";
      temp += "</Session>\n";
      
      return temp;
   } // end toString()
} // end class
