david-PC\david
2018-06-12 f240ac3ccd37c541cab2c21cfc433d3510999a3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package frame.file;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
 
import com.sun.faces.lifecycle.Phase;
 
public class Progressor {
    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 Progressor() {
        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();
    
        DateTime datetime = new DateTime();
        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.Count; i++) {
            indent = indent + "&nbsp;&nbsp;&nbsp;&nbsp;";
        }
 
        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.Count; i++) {
            indent = indent + "&nbsp;&nbsp;&nbsp;&nbsp;";
        }
 
        messageList.Add(indent + message);
    }
 
    public void appendInlineMessage(String message) {
        if (message != null) {
            if (messageList.Count == 0) {
                messageList.Add(message);
                return;
            }
 
            int max = messageList.Count - 1;
            String prior = messageList[max];
            prior = prior + "......" + message;
 
            messageList.RemoveAt(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.Count == 0;
    }
 
    public List<Phase> getCurrentPhases() {
        List<Phase> resultList = new List<Phase>();
    
        foreach (Phase phase in phaseStack) {
            resultList.Add(phase);
        }
    
        return resultList;
    }
 
}