001package org.javasimon.javaee.reqreporter; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import org.javasimon.Split; 007import org.javasimon.Stopwatch; 008 009/** 010 * Contains cummulated information about about single {@link Stopwatch} with all its reported {@link Split}s. 011 * Naturally comparable by total time descending. 012 */ 013public class ReporterStopwatchInfo implements Comparable<ReporterStopwatchInfo> { 014 Stopwatch stopwatch; 015 List<Split> splits = new ArrayList<>(); 016 Split maxSplit; 017 long total; 018 019 ReporterStopwatchInfo(Stopwatch stopwatch) { 020 this.stopwatch = stopwatch; 021 } 022 023 @Override 024 public int compareTo(ReporterStopwatchInfo o) { 025 return total < o.total ? 1 : total == o.total ? 0 : -1; 026 } 027 028 public void addSplit(Split split) { 029 splits.add(split); 030 long runningFor = split.runningFor(); 031 if (maxSplit == null || runningFor > maxSplit.runningFor()) { 032 maxSplit = split; 033 } 034 total += runningFor; 035 } 036}