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

com.github.nicosensei.textbatch.job.AbstractJobProgress Maven / Gradle / Ivy

/**
 *
 */
package com.github.nicosensei.textbatch.job;

import java.text.DecimalFormat;
import java.util.LinkedList;

import com.github.nicosensei.textbatch.ToolException;


/**
 * @author ngiraud
 *
 */
public abstract class AbstractJobProgress implements JobProgress {

    private final Long unitsToProcess;
    private Long unitsProcessed;

    private LinkedList errors = new LinkedList();

    AbstractJobProgress(final long unitsToProcess) {
        super();
        this.unitsToProcess = unitsToProcess;
        this.unitsProcessed = 0L;
    }

    AbstractJobProgress(
            final long unitsToProcess,
            long unitsProcessed) {
        super();
        this.unitsToProcess = unitsToProcess;
        this.unitsProcessed = unitsProcessed;
    }

    protected static final DecimalFormat PERCENTAGE =
        new DecimalFormat("###.##");

    @Override
    public double getCompletionPercentage() {
        return (100 * unitsProcessed.doubleValue())
                / unitsToProcess.doubleValue();
    }

    @Override
    public abstract void notifyLineProcessed(InputLine l);

    @Override
    public abstract void logStatus();

    @Override
    public ToolException[] getErrors() {
        return errors.toArray(new ToolException[errors.size()]);
    }

    @Override
    public synchronized void notifyError(ToolException e) {
        errors.add(e);
    }

    protected final Long getUnitsToProcess() {
        return unitsToProcess;
    }

    protected final Long getUnitsProcessed() {
        return unitsProcessed;
    }

    final void incrementUnitsProcessed(long value) {
        unitsProcessed += value;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy