package frame.file.processor;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Stack;
|
|
public class Processor {
|
private String taskName;
|
private Stack<Phase> phaseStack;
|
private List<String> messageList;
|
private Phase priorPhase;
|
|
private long max;
|
private long min;
|
private long step;
|
private long position;
|
private long stepBuffer;
|
private String stepMessage;
|
|
public Processor() {
|
messageList = new ArrayList<String>(100);
|
phaseStack = new Stack<Phase>();
|
|
max = 0;
|
min = 0;
|
step = 0;
|
position = 0;
|
stepBuffer = 0;
|
stepMessage = "0%--------0/0";
|
}
|
|
public void clear() {
|
priorPhase = null;
|
phaseStack.clear();
|
clearMessage();
|
clearStep();
|
}
|
|
public void clearStep() {
|
max = 0;
|
min = 0;
|
step = 0;
|
position = 0;
|
stepBuffer = 0;
|
stepMessage = "0%--------0/0";
|
}
|
|
public void stepIt() {
|
if (position < max) {
|
position++;
|
stepBuffer++;
|
|
if (stepBuffer >= step) {
|
double percent = position * 100 / max;
|
stepBuffer = 0;
|
stepMessage = Math.round(percent) + "%" + "--------" + position + "/" + max;
|
}
|
}
|
else {
|
stepMessage = "100%" + "--------" + max + "/" + max;
|
}
|
}
|
|
public void stepIt(int aStep) {
|
if (position < max) {
|
position = Math.min(position + aStep, max);
|
stepBuffer = stepBuffer + aStep;
|
|
if (stepBuffer >= step) {
|
double percent = position * 100 / max;
|
stepBuffer = 0;
|
stepMessage = Math.round(percent) + "%" + "--------" + position + "/" + max;
|
}
|
}
|
else {
|
stepMessage = "100%" + "--------" + max + "/" + max;
|
}
|
}
|
|
public long getMax() {
|
return max;
|
}
|
|
public void setMax(long max) {
|
clearStep();
|
this.max = max;
|
}
|
|
public long getMin() {
|
return min;
|
}
|
|
public void setMin(int min) {
|
this.min = min;
|
}
|
|
public String getStepMsg() {
|
return stepMessage;
|
}
|
|
public void newTask(String name) {
|
taskName = name;
|
|
clearMessage();
|
clearStep();
|
|
Date datetime = new Date();
|
appendLine(name + "开始..." + datetime);
|
}
|
|
public void endTask() {
|
appendLine(taskName + "结束");
|
}
|
|
public void newPhase(String code, String phaseName) {
|
Phase phase = new Phase(code, phaseName);
|
phase.setNo(priorPhase, phaseStack);
|
|
String indent = "";
|
for (int i = 0; i < phaseStack.size(); i++) {
|
indent = indent + " ";
|
}
|
|
String title = indent + phase.getNoString() + phaseName;
|
appendLine(title);
|
|
phaseStack.push(phase);
|
priorPhase = null;
|
}
|
|
public void endPhase() {
|
clearStep();
|
priorPhase = phaseStack.pop();
|
}
|
|
public void clearMessage() {
|
messageList.clear();
|
}
|
|
private void appendLine(String message) {
|
if (message != null) {
|
messageList.add(message);
|
}
|
}
|
|
public void appendMesage(String message) {
|
String indent = "";
|
for (int i = 0; i <= phaseStack.size(); i++) {
|
indent = indent + " ";
|
}
|
|
messageList.add(indent + message);
|
}
|
|
public void appendInlineMessage(String message) {
|
if (message != null) {
|
if (messageList.isEmpty()) {
|
messageList.add(message);
|
return;
|
}
|
|
int max = messageList.size() - 1;
|
String prior = messageList.get(max);
|
prior = prior + "......" + message;
|
|
messageList.remove(max);
|
messageList.add(prior);
|
}
|
}
|
|
public void setStepName(String step) {
|
messageList.add(step);
|
}
|
|
public List<String> getMessageList() {
|
return messageList;
|
}
|
|
public void terminate(String error) {
|
messageList.add(error);
|
}
|
|
public Boolean isEmpty() {
|
return messageList.size() == 0;
|
}
|
|
public List<Phase> getCurrentPhases() {
|
List<Phase> resultList = new ArrayList<Phase>();
|
|
for (Phase phase : phaseStack) {
|
resultList.add(phase);
|
}
|
|
return resultList;
|
}
|
|
}
|