1 package info.mikethomas.fahview.v6project.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import info.mikethomas.fahview.v6project.utilities.QueueReader;
25 import java.util.Date;
26
27
28
29
30
31
32
33 public class WorkUnitImpl implements WorkUnit {
34 private int proj;
35 private int run;
36 private int clone;
37 private int gen;
38 private Date issue;
39
40 private String protein, percentage;
41 private int completed, steps;
42
43 private int indexNumber, position;
44 private QueueReader reader;
45
46
47
48
49
50
51
52
53 public WorkUnitImpl(int indexNumber, QueueReader reader) throws InstantiationException {
54 percentage = "0%";
55 this.indexNumber = indexNumber;
56 switch (indexNumber) {
57 case 0:
58 position = QueueImpl.QUEUE_INDEX_0_POS + QueueIndexImpl.WUID_POS;
59 break;
60 case 1:
61 position = QueueImpl.QUEUE_INDEX_1_POS + QueueIndexImpl.WUID_POS;
62 break;
63 case 2:
64 position = QueueImpl.QUEUE_INDEX_2_POS + QueueIndexImpl.WUID_POS;
65 break;
66 case 3:
67 position = QueueImpl.QUEUE_INDEX_3_POS + QueueIndexImpl.WUID_POS;
68 break;
69 case 4:
70 position = QueueImpl.QUEUE_INDEX_4_POS + QueueIndexImpl.WUID_POS;
71 break;
72 case 5:
73 position = QueueImpl.QUEUE_INDEX_5_POS + QueueIndexImpl.WUID_POS;
74 break;
75 case 6:
76 position = QueueImpl.QUEUE_INDEX_6_POS + QueueIndexImpl.WUID_POS;
77 break;
78 case 7:
79 position = QueueImpl.QUEUE_INDEX_7_POS + QueueIndexImpl.WUID_POS;
80 break;
81 case 8:
82 position = QueueImpl.QUEUE_INDEX_8_POS + QueueIndexImpl.WUID_POS;
83 break;
84 case 9:
85 position = QueueImpl.QUEUE_INDEX_9_POS + QueueIndexImpl.WUID_POS;
86 break;
87 default:
88 throw new InstantiationException("Queue index should be 0-9.");
89 }
90 this.reader = reader;
91 update();
92 }
93
94
95 @Override
96 public int getProj() {
97 return proj;
98 }
99
100
101 @Override
102 public int getRun() {
103 return run;
104 }
105
106
107 @Override
108 public int getClone() {
109 return clone;
110 }
111
112
113 @Override
114 public int getGen() {
115 return gen;
116 }
117
118
119 @Override
120 public Date getIssue() {
121 return issue;
122 }
123
124
125
126
127 protected void setProj() {
128 proj = reader.readLEUShort(PROJ_POS + position, PROJ_LENGTH);
129 }
130
131
132
133
134 protected void setRun() {
135 run = reader.readLEUShort(RUN_POS + position, RUN_LENGTH);
136 }
137
138
139
140
141 protected void setClone() {
142 clone = reader.readLEUShort(CLONE_POS + position, CLONE_LENGTH);
143 }
144
145
146
147
148 protected void setGen() {
149 gen = reader.readLEUShort(GEN_POS + position, GEN_LENGTH);
150 }
151
152
153
154
155 protected void setIssue() {
156 long epoch = reader.readLEUInt(ISSUE_POS + position, ISSUE_LENGTH);
157 issue = new Date(epoch * 1000);
158 }
159
160
161
162
163
164
165 protected void setCompleted(String line) {
166 String[] values = line.split(" ");
167 completed = Integer.parseInt(values[2]);
168 steps = Integer.parseInt(values[5]);
169 percentage = values[8].substring(1, values[8].length() - 1);
170 }
171
172
173
174
175
176
177 public int getCompleted() {
178 return completed;
179 }
180
181
182
183
184
185
186 public String getPercentage() {
187 return percentage;
188 }
189
190
191
192
193
194
195 public String getProtein() {
196 return protein;
197 }
198
199
200
201
202
203
204 public int getSteps() {
205 return steps;
206 }
207
208
209
210
211
212
213 @Override
214 public String toString() {
215 String result = "";
216 result += "queue.index[" + indexNumber + "].wuid.proj\t" + getProj();
217 result += "\nqueue.index[" + indexNumber + "].wuid.run\t" + getRun();
218 result += "\nqueue.index[" + indexNumber + "].wuid.clone\t" + getClone();
219 result += "\nqueue.index[" + indexNumber + "].wuid.gen\t" + getGen();
220 result += "\nqueue.index[" + indexNumber + "].wuid.issue\t" + getIssue();
221 return result;
222 }
223
224
225 @Override
226 public final void update() {
227 setProj();
228 setRun();
229 setClone();
230 setGen();
231 setIssue();
232 }
233 }