package com.jscape.zip;

import java.util.EventObject;

/**
 * Class to measure the compression progress.
 *
 * @author mjawwad
 */
public class CompressionEvent
        extends EventObject {

    private double compressedBytes = 0d;
    private double totalBytes = 0d;
    private ProgressEventMode mode;

    /**
     * Creates a CompressionEvent object
     *
     * @param source     - the source object
     * @param totalBytes - the total number of bytes that need to be compressed
     */
    public CompressionEvent(final Object source, double compressedBytes, double totalBytes, ProgressEventMode mode) {
        super(source);
        this.compressedBytes = compressedBytes;
        this.totalBytes = totalBytes;
        this.mode = mode;
    }

    /**
     * Get progress event mode.
     *
     * @return mode
     */
    public ProgressEventMode getMode() {
        return this.mode;
    }

    /**
     * Get compressed bytes.
     *
     * @return bytes
     */
    public double getCompressedBytes() {
        return this.compressedBytes;
    }

    /**
     * Get total number of bytes to be compressed.
     *
     * @return bytes
     */
    public double getTotalBytes() {
        return this.totalBytes;
    }

    /**
     * Get bytes compressed as percentage of the total.
     *
     * @return percentage if total bytes greater than zero, -1 otherwise
     */
    public double getPercentage() {
        return this.totalBytes > 0L ? (this.getCompressedBytes() / this.getTotalBytes()) * 100d : -1;
    }

}
