package LogParser;

import java.util.*;

public class XMLLog_FileEntry
{
   private Date                       timestamp;
   private String                     filename;
   private Vector<XMLLog_MethodEntry> entries;
   
   public XMLLog_FileEntry() { entries = new Vector<XMLLog_MethodEntry>(); }
   
   public void setTimestamp(Date date) { timestamp = date; }
   
   public Date getTimestamp() { return timestamp; }
   
   public void addEntry(XMLLog_MethodEntry me) { entries.add(me); }
   
   public Vector<String> getMethods()
   {
      Vector<String> methods = new Vector<String>();
      for(int i = 0; i < entries.size(); ++i)
      {
         if(!methods.contains(entries.elementAt(i).getName()))
         {
            methods.add(entries.elementAt(i).getName());
         } // end if
      } // end for
      
      return methods;
   } // end getMethods()
   
   public Vector<XMLLog_MethodEntry> getEntriesOf(String name)
   {
      Vector<XMLLog_MethodEntry> temp =
         new Vector<XMLLog_MethodEntry>();
         
      for(int i = 0; i < entries.size(); ++i)
      {
         if(entries.elementAt(i).getName() == name)
            temp.add(entries.elementAt(i));
      }
      
      return temp;
   } // end getEntriesOf
   
   public int correctnessQuery(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(method))
         {
            //System.out.println("Found method: " + method + " at element " + i);
            count += entries.elementAt(i).correctnessQuery(correctness, from, to);
         } // end if
      } // end for
      return count;
   } // end correctnessQuery(String,bool,Date,Date)
   
   public void setName(String name) { filename = name; }
   
   public String getName() { return filename.substring(0,filename.length()-6); }
   
   public String toString()
   {
      String temp = "<File name=\""+filename+"\" timestamp=\""+
                    timestamp+"\">\n";
      for(int i = 0; i < entries.size(); ++i)
         temp += entries.elementAt(i)+"\n";
      temp += "</File>\n";
      
      return temp;
   } // end toString()
} // end class
