comparison NGSrich_0.5.5/src/middlewares/HitsCounter.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:89ad0a9cca52
1 package middlewares;
2 import java.util.Vector;
3
4 /**
5 * Counts the number of bases hit at least 1, 5, 10, 20 or 30 times.
6 *
7 * @author Ali Abdallah
8 * @version 22.07.2011
9 * @since Java 1.6
10 */
11 public class HitsCounter {
12
13 /**
14 * The hits vector with the number of bases hit at different levels.
15 */
16 private Vector<Integer> hits;
17
18 /**
19 * The number of bases hit at the five different levels for a specific
20 * target.
21 */
22 private Vector<Integer> currentHits;
23
24 /**
25 * The levels at which the number of bases is counted.
26 */
27 private int[] levels = { 1, 5, 10, 20, 30 };
28
29 /**
30 * Creates and initializes a hit counter.
31 */
32 public HitsCounter() {
33 hits = new Vector<Integer>();
34 currentHits = new Vector<Integer>();
35 for (int i = 0; i < levels.length; i++) {
36 hits.add(0);
37 currentHits.add(0);
38 }
39 }
40
41 /**
42 * Update the number of bases hit at the specified different levels.
43 */
44 public void updateHits() {
45 for (int i = 0; i < hits.size(); i++) {
46 hits.set(i, hits.get(i) + currentHits.get(i));
47 }
48 }
49
50 /**
51 * Reset the number of bases hit at the specified different leverls for
52 * a specific target for user for the next target.
53 */
54 public void resetCurrentHits() {
55 currentHits = new Vector<Integer>();
56 for (int i = 0; i < levels.length; i++) {
57 currentHits.add(0);
58 }
59 }
60
61 /**
62 * Increments the number of bases hit at some levels by one, if the number
63 * of hits on this base reach or exceed this level.
64 *
65 * @param hitsOnBase
66 */
67 public void updateCurrentHits(int hitsOnBase) {
68 for (int i = 0; i < currentHits.size(); i++) {
69 if (hitsOnBase >= levels[i]) {
70 currentHits.set(i, currentHits.get(i) + 1);
71 }
72 }
73 }
74
75 // Index of the bases level of the current target.
76 int currHit = 0;
77
78 /**
79 * @return the number of bases hit at the next higher level in the current
80 * target.
81 */
82 public int getNextLevelCurrentHits() {
83 if (currHit < currentHits.size())
84 return currentHits.get(currHit++);
85 else {
86 currHit = 1;
87 return currentHits.get(0);
88 }
89 }
90
91 // Index of the bases level of the target.
92 int hit = -1;
93
94 /**
95 * @return the number of bases hit at the next higher level.
96 */
97 public int getNextLevelHits() {
98 if (++hit < hits.size()) {
99 return hits.get(hit);
100 } else {
101 return (hit = -1);
102 }
103 }
104
105 }