Progress.java

package net.morimekta.terminal.progress;

/**
 * A progress
 */
public class Progress {
    private final long progress;
    private final long total;

    public Progress(long progress, long total) {
        if (total <= 0) {
            throw new IllegalArgumentException("total <= 0: " + total);
        }
        if (progress < 0) {
            throw new IllegalArgumentException("progress < 0" + progress);
        }
        if (progress > total) {
            throw new IllegalArgumentException("" + progress + " < " + total);
        }
        this.progress = progress;
        this.total = total;
    }

    /**
     * @return The current progress of total.
     */
    public long getProgress() {
        return progress;
    }

    /**
     * @return The total of which the progress is part of.
     */
    public long getTotal() {
        return total;
    }

    /**
     * @return The ration of progress of the total.
     */
    public double getRatio() {
        return ((double) progress) / total;
    }
}