1 package net.sourceforge.basher;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6
7
8
9
10
11 public class TaskConfiguration
12 {
13
14
15
16
17 private int _weight = 100;
18
19
20
21
22 private double _doubleWeight = _weight;
23
24
25
26
27 private int _originalWeight = _weight;
28
29
30
31
32 private double _inertia = 1.0d;
33
34
35
36
37 private int _maxInvocations = 0;
38
39
40
41
42
43 private long _runFrom = 0;
44
45
46
47
48
49 private long _stopAfter = Long.MAX_VALUE;
50
51
52
53
54
55 private int _maxTime = 0;
56
57
58
59
60 private String _taskName;
61
62
63
64
65
66 private List<Phase> _applicablePhases = new ArrayList<Phase>();
67
68 public TaskConfiguration()
69 {
70 _applicablePhases.add( Phase.RUN );
71 }
72
73
74
75
76
77
78
79 public Integer getWeight()
80 {
81 return _weight;
82 }
83
84
85
86
87
88
89
90 public Double getInertia()
91 {
92 return _inertia;
93 }
94
95
96
97
98
99
100
101
102 public void setInertia( final Double inertia )
103 {
104 _inertia = inertia;
105 }
106
107
108
109
110 public void reset()
111 {
112 _weight = _originalWeight;
113 _doubleWeight = _weight;
114 }
115
116
117
118
119
120
121
122 public void setWeight( final Integer weight )
123 {
124 _weight = weight;
125
126 _doubleWeight = _weight;
127
128
129 _originalWeight = weight;
130 _doubleWeight = weight;
131
132 }
133
134
135
136
137
138
139
140
141 public void setMaxInvocations( final Integer maxInvocations )
142 {
143 _maxInvocations = maxInvocations;
144 }
145
146
147
148
149
150
151
152 public Integer getMaxInvocations()
153 {
154 return _maxInvocations;
155 }
156
157
158
159
160
161
162 public void reCalculateWeight()
163 {
164
165 if ( Double.compare( _inertia, 1.0D ) != 0 )
166 {
167
168
169 _doubleWeight = _doubleWeight * _inertia;
170 _weight = ( int ) _doubleWeight;
171 }
172 }
173
174
175
176
177
178
179
180 public Long getRunFrom()
181 {
182 return _runFrom;
183 }
184
185
186
187
188
189
190
191 public Long getStopAfter()
192 {
193 return _stopAfter;
194 }
195
196
197
198
199
200
201
202 public void setRunFrom( final Long runFrom )
203 {
204 _runFrom = runFrom;
205 }
206
207
208
209
210
211
212
213 public void setStopAfter( final Long stopAfter )
214 {
215 _stopAfter = stopAfter;
216 }
217
218
219
220
221
222 public void clearApplicablePhases()
223 {
224 _applicablePhases.clear();
225 }
226
227
228
229
230
231
232 public void addApplicablePhase( Phase phase )
233 {
234 if ( phase == null )
235 {
236 throw new NullPointerException( "phase" );
237 }
238 if ( !_applicablePhases.contains( phase ) )
239 {
240 _applicablePhases.add( phase );
241 }
242 }
243
244
245
246
247
248
249
250 public List<Phase> getApplicablePhases()
251 {
252 return _applicablePhases;
253 }
254
255
256
257
258
259
260 public Integer getMaxTime()
261 {
262 return _maxTime;
263 }
264
265 public void setMaxTime( final Integer maxTime )
266 {
267 _maxTime = maxTime;
268 }
269
270
271
272
273
274
275 public String getTaskName()
276 {
277 return _taskName;
278 }
279
280
281
282
283
284
285 public void setTaskName( final String taskName )
286 {
287 _taskName = taskName;
288 }
289
290
291
292
293 public void initialize( final TaskConfiguration taskConfiguration )
294 {
295 _applicablePhases = new ArrayList<Phase>( taskConfiguration.getApplicablePhases() );
296 _inertia = taskConfiguration.getInertia();
297 _maxInvocations = taskConfiguration.getMaxInvocations();
298 _maxTime = taskConfiguration.getMaxTime();
299 _runFrom = taskConfiguration.getRunFrom();
300 _stopAfter = taskConfiguration.getStopAfter();
301 _taskName = taskConfiguration.getTaskName();
302 _weight = taskConfiguration.getWeight();
303 }
304
305
306 @Override
307 public boolean equals( final Object o )
308 {
309 if ( this == o )
310 {
311 return true;
312 }
313 if ( !( o instanceof TaskConfiguration ) )
314 {
315 return false;
316 }
317
318 final TaskConfiguration that = ( TaskConfiguration ) o;
319
320 if ( Double.compare( that._doubleWeight, _doubleWeight ) != 0 )
321 {
322 return false;
323 }
324 if ( Double.compare( that._inertia, _inertia ) != 0 )
325 {
326 return false;
327 }
328 if ( _maxInvocations != that._maxInvocations )
329 {
330 return false;
331 }
332 if ( _maxTime != that._maxTime )
333 {
334 return false;
335 }
336 if ( _originalWeight != that._originalWeight )
337 {
338 return false;
339 }
340 if ( _runFrom != that._runFrom )
341 {
342 return false;
343 }
344 if ( _stopAfter != that._stopAfter )
345 {
346 return false;
347 }
348 if ( _weight != that._weight )
349 {
350 return false;
351 }
352 if ( _taskName != null ? !_taskName.equals( that._taskName ) : that._taskName != null )
353 {
354 return false;
355 }
356
357 return true;
358 }
359
360 @Override
361 public int hashCode()
362 {
363 int result;
364 long temp;
365 result = _weight;
366 temp = _doubleWeight != +0.0d ? Double.doubleToLongBits( _doubleWeight ) : 0L;
367 result = 31 * result + ( int ) ( temp ^ ( temp >>> 32 ) );
368 result = 31 * result + _originalWeight;
369 temp = _inertia != +0.0d ? Double.doubleToLongBits( _inertia ) : 0L;
370 result = 31 * result + ( int ) ( temp ^ ( temp >>> 32 ) );
371 result = 31 * result + _maxInvocations;
372 result = 31 * result + ( int ) ( _runFrom ^ ( _runFrom >>> 32 ) );
373 result = 31 * result + ( int ) ( _stopAfter ^ ( _stopAfter >>> 32 ) );
374 result = 31 * result + _maxTime;
375 result = 31 * result + ( _taskName != null ? _taskName.hashCode() : 0 );
376 result = 31 * result + ( _applicablePhases != null ? _applicablePhases.hashCode() : 0 );
377 return result;
378 }
379
380 @Override
381 public String toString()
382 {
383 return "TaskConfiguration{" +
384 "_weight=" + _weight +
385 ", _doubleWeight=" + _doubleWeight +
386 ", _originalWeight=" + _originalWeight +
387 ", _inertia=" + _inertia +
388 ", _maxInvocations=" + _maxInvocations +
389 ", _runFrom=" + _runFrom +
390 ", _stopAfter=" + _stopAfter +
391 ", _maxTime=" + _maxTime +
392 ", _taskName='" + _taskName + '\'' +
393 '}';
394 }
395 }