package com.yanzuoguang.util.thread;

import com.yanzuoguang.util.helper.HttpHelper;
import com.yanzuoguang.util.log.Log;

/**
 * 进度数据
 * @author 颜佐光
 */
public class ProcessData {

    /**
     * 目标
     */
    private String target;

    /**
     * 位置
     */
    private long pos;

    /**
     * 长度
     */
    private long total;

    public ProcessData() {
    }

    public ProcessData(String target) {
        this.target = target;
    }

    public ProcessData(String target, long total) {
        this.target = target;
        this.total = total;
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public long getPos() {
        return pos;
    }

    public void setPos(long pos) {
        this.pos = pos;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }


    /**
     * 进度调用
     *
     * @param runProcess
     * @param pos
     */
    public void processCall(RunProcess runProcess, long pos) {
        this.pos = pos;
        if (runProcess == null) {
            return;
        }
        try {
            runProcess.execute(this);
        } catch (Exception ex) {
            Log.error(HttpHelper.class, ex);
        }
    }

    /**
     * 进度调用
     *
     * @param runProcess 运行进度
     * @param add        需要添加的量
     */
    public void processAdd(RunProcess runProcess, long add) {
        this.pos += add;
        this.processCall(runProcess, this.pos);
    }
}