package co.leantechniques.maven.buildtime;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ProjectTimer {

    private final String projectName;

    private final ConcurrentMap<String, MojoTimer> dataStore;
    private final SystemClock systemClock;

    public ProjectTimer(String projectName, ConcurrentMap<String, MojoTimer> dataStore, SystemClock systemClock) {
        this.dataStore = dataStore;
        this.systemClock = systemClock;
        this.projectName = projectName;
    }

    public ProjectTimer(String projectName, SystemClock systemClock) {
        this(projectName, new ConcurrentHashMap<String, MojoTimer>(), systemClock);
    }

    public void stopTimerFor(MojoExecutionName me) {
        getMojoTimer(me).stop();
    }

    public void startTimerFor(MojoExecutionName name) {
        getMojoTimer(name).start();
    }

    public MojoTimer getMojoTimer(MojoExecutionName name) {
        if(!dataStore.containsKey(name.getName())) {
            dataStore.putIfAbsent(name.getName(), new MojoTimer(projectName, name.getName(), systemClock));
        }
        return dataStore.get(name.getName());
    }

    public Long getDuration() {
        long startTime = Long.MAX_VALUE;
        long endTime = 0;

        for (MojoTimer mojoTimer : dataStore.values()) {
            startTime = Math.min(startTime, mojoTimer.getStartTime());
            endTime = Math.max(endTime, mojoTimer.getEndTime());
        }

        return endTime - startTime;
    }

    public void accept(TimerVisitor visitor){
        visitor.visit(this);

        final List<MojoTimer> mojoTimers = new ArrayList<MojoTimer>(dataStore.values());
        Collections.sort(mojoTimers);

        for (MojoTimer mojoTimer : mojoTimers) {
            mojoTimer.accept(visitor);
        }
    }

    public String getProjectName() {
        return projectName;
    }
}

@@ -234,16 +234,52 @@
 ectTimer
+ implements Comparable%3CProjectTimer%3E
  %7B%0A%0A    
@@ -1339,306 +1339,56 @@
     
-long startTime = Long.MAX_VALUE;%0A        long endTime = 0;%0A%0A        for (MojoTimer mojoTimer : dataStore.values()) %7B%0A            startTime = Math.min(startTime, mojoTimer.getStartTime());%0A            endTime = Math.max(endTime, mojoTimer.getEndTime());%0A        %7D%0A%0A        return endTime - s
+return getProjectEndTime() - getProjectS
 tartTime
 ;%0A  
@@ -1383,16 +1383,18 @@
 tartTime
+()
 ;%0A    %7D%0A
@@ -1718,58 +1718,964 @@
 lic 
-String getProjectName() %7B%0A        return projectNa
+int compareTo(ProjectTimer that) %7B%0A        if (that == null)%0A            return 1;%0A%0A        if (this == that)%0A            return 0;%0A%0A        long thisStartTime = this.getProjectStartTime();%0A        long thatStartTime = that.getProjectStartTime();%0A%0A        if (thisStartTime %3E thatStartTime)%0A            return 1;%0A        else if (thisStartTime %3C thatStartTime)%0A            return -1;%0A%0A        return 0;%0A    %7D%0A%0A    public String getProjectName() %7B%0A        return projectName;%0A    %7D%0A%0A    private long getProjectStartTime() %7B%0A        long startTime = Long.MAX_VALUE;%0A%0A        for (MojoTimer mojoTimer : dataStore.values()) %7B%0A            startTime = Math.min(startTime, mojoTimer.getStartTime());%0A        %7D%0A%0A        return startTime;%0A    %7D%0A%0A    private long getProjectEndTime() %7B%0A        long endTime = 0;%0A%0A        for (MojoTimer mojoTimer : dataStore.values()) %7B%0A            endTime = Math.max(endTime, mojoTimer.getEndTime());%0A        %7D%0A%0A        return endTi
 me;%0A

Update ProjectTimer.java