package LogParser;

import java.util.*;

public class XMLLog_MethodEntry
{
   private String                       name;
   private Date                         timestamp;
   private Vector<XMLLog_TestCaseEntry> entries;
   
   public XMLLog_MethodEntry()
   {
      entries = new Vector<XMLLog_TestCaseEntry>();
   } // end ctor
   
   public void addEntry(XMLLog_TestCaseEntry tce)
   { entries.add(tce); }
   
   public int countAllCases(boolean correctness)
   {
      int count = 0;
      
      for(int i = 0; i < entries.size(); ++i)
      {
         if(entries.elementAt(i).isCorrect() == correctness)
            ++count;
      } // end for
      
      return count;
   } // end getAllTrueCases
   
   public int correctnessQuery(boolean correctness, Date from, Date to)
   {
      int count = 0;
      for(int i = 0; i < entries.size(); ++i)
      {
         XMLLog_TestCaseEntry entry = entries.elementAt(i);
         Date temp = entry.getTimestamp();
         
         //System.out.println("TC is "+temp.after(from)+" after and "+temp.before(to)+" before and is " +entry.isCorrect());
         if(temp.after(from) && temp.before(to) && (entry.isCorrect() == correctness))
         {
            //System.out.println("Method entry i: "+i);
            ++count;
         } // end if
      } // end for
      
      return count;
   } // end correctnessQuery(bool,Date,Date)
   
   public void setTimestamp(Date date) { timestamp = date; }
   public Date getTimestamp() { return timestamp; }
   
   public void setName(String name) { this.name = name; }
   public String getName() { return name; }
   
   public String toString()
   {
      String temp = "<Method name=\""+name+"\" timestamp=\""+
                    timestamp+"\">\n";
      for(int i = 0; i < entries.size(); ++i)
         temp += entries.elementAt(i)+"\n";
      temp += "</Method>\n";
      
      return temp;
   } // end toString()
} // end class
