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

com.graphaware.common.stopwatch.Event Maven / Gradle / Ivy

There is a newer version: 4.2.0.58
Show newest version
package com.graphaware.common.stopwatch;

import java.util.ArrayList;
import java.util.List;

public class Event {

    private Long start;

    private List periods = new ArrayList<>();

    private boolean isStopped = false;

    public Event() {
        start = System.currentTimeMillis();
    }

    public void stop() {
        periods.add(new Period(getLastPeriodTime(), System.currentTimeMillis()));
    }

    public Long getStartTime() {
        return start;
    }

    public Long duration() {
        return getLastPeriodTime() - start;
    }

    public void addPeriod() {
        periods.add(new Period(getLastPeriodTime(), System.currentTimeMillis()));
    }

    public List getPeriods() {
        return periods;
    }

    private Long getLastPeriodTime() {
        return periods.size() == 0 ? start : periods.get(periods.size()-1).endTime();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy