All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.jcgay.maven.profiler.ArtifactDescriptor Maven / Gradle / Ivy

There is a newer version: 3.2
Show newest version
package fr.jcgay.maven.profiler;

import com.google.common.base.Stopwatch;
import org.eclipse.aether.artifact.Artifact;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.filter;
import static fr.jcgay.maven.profiler.KnownElapsedTimeTicker.aStopWatchWithElapsedTime;

public class ArtifactDescriptor {

    private final Stopwatch totalStopwatch;

    private ArtifactDescriptor(long totalTime) {
        this.totalStopwatch = aStopWatchWithElapsedTime(totalTime);
    }

    public static ArtifactDescriptor instance(Map times) {
        if (times == null || times.isEmpty()) {
            return new ArtifactDescriptor(0);
        }

        return new ArtifactDescriptor(totalTime(times));
    }

    private static long totalTime(Map times) {
        long totalTime = 0;
        for (Stopwatch stopwatch : filter(times.values(), notNull())) {
            totalTime += stopwatch.elapsedTime(TimeUnit.NANOSECONDS);
        }
        return totalTime;
    }

    public Stopwatch getTotalTimeSpentDownloadingArtifacts() {
        return totalStopwatch;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy