/**
  * Clears the data in the database.
  *
  * @param dataBase the database to truncate
  */
 @SuppressWarnings("unchecked")
 public static synchronized void clear(IDataBase dataBase) {
   Project<?, ?> project =
       (Project<?, ?>) dataBase.find(Project.class, Toolkit.hash(Project.class.getName()));
   if (project != null) {
     dataBase.remove(Project.class, project.getId());
   }
   List<Package> packages = dataBase.find(Package.class);
   for (Composite<?, ?> composite : packages) {
     dataBase.remove(composite.getClass(), composite.getId());
   }
   List<Class> classes = dataBase.find(Class.class);
   for (Composite composite : classes) {
     dataBase.remove(composite.getClass(), composite.getId());
   }
   List<Method> methods = dataBase.find(Method.class);
   for (Composite composite : methods) {
     dataBase.remove(composite.getClass(), composite.getId());
   }
   List<Line> lines = dataBase.find(Line.class);
   for (Composite composite : lines) {
     dataBase.remove(composite.getClass(), composite.getId());
   }
   List<Snapshot> snapshots = dataBase.find(Snapshot.class);
   for (Snapshot snapshot : snapshots) {
     dataBase.remove(Snapshot.class, snapshot.getId());
   }
 }
  private Element tableElement(List<Snapshot<?, ?>> snapshots) {
    Document document = DocumentHelper.createDocument();
    Element htmlElement = document.addElement("html");
    Element headElement = addElement(htmlElement, "head", null);
    Element linkElement = addElement(headElement, "link", null);
    addAttributes(
        linkElement,
        new String[] {"href", "rel", "type", "media"},
        new String[] {IConstants.STYLE_SHEET, "stylesheet", "text/css", "screen"});

    Element bodyElement = addElement(linkElement, "body", null);
    Element tableElement = addElement(bodyElement, "table", null);

    Element headerRowElement = addElement(tableElement, "tr", null);
    String periods = "no periods";
    if (snapshots.size() > 0) {
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
      Snapshot<?, ?> firstSnapshot = snapshots.get(0);
      Snapshot<?, ?> lastSnapshot = snapshots.get(snapshots.size() - 1);

      String start = dateFormat.format(firstSnapshot.getStart());
      String end = dateFormat.format(lastSnapshot.getStart());

      StringBuilder builder = new StringBuilder(start);
      builder.append(" to ");
      builder.append(end);

      //noinspection ConstantConditions
      if (firstSnapshot != null
          && firstSnapshot.getEnd() != null
          && firstSnapshot.getStart() != null) {
        long intervals = firstSnapshot.getEnd().getTime() - firstSnapshot.getStart().getTime();
        builder.append(", at intervals of : ");
        builder.append(intervals);
        builder.append(" ms.");
      }

      periods = builder.toString();
    }
    Element headerElement = addElement(headerRowElement, "th", "Period from : " + periods);
    addAttributes(headerElement, new String[] {"colspan"}, new String[] {"9"});

    Element rowElement = addElement(tableElement, "tr", null);
    addElement(rowElement, "th", "Class");
    addElement(rowElement, "th", "Method");
    addElement(rowElement, "th", "Time");
    addElement(rowElement, "th", "Net time");
    addElement(rowElement, "th", "Delta time");
    addElement(rowElement, "th", "Net delta time");
    addElement(rowElement, "th", "Invocations");
    addElement(rowElement, "th", "Graph");
    addElement(rowElement, "th", "Delta draph");
    return tableElement;
  }