Mercurial > repos > pfrommolt > ngsrich
view 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 |
line wrap: on
line source
package middlewares; import java.util.Vector; /** * Counts the number of bases hit at least 1, 5, 10, 20 or 30 times. * * @author Ali Abdallah * @version 22.07.2011 * @since Java 1.6 */ public class HitsCounter { /** * The hits vector with the number of bases hit at different levels. */ private Vector<Integer> hits; /** * The number of bases hit at the five different levels for a specific * target. */ private Vector<Integer> currentHits; /** * The levels at which the number of bases is counted. */ private int[] levels = { 1, 5, 10, 20, 30 }; /** * Creates and initializes a hit counter. */ public HitsCounter() { hits = new Vector<Integer>(); currentHits = new Vector<Integer>(); for (int i = 0; i < levels.length; i++) { hits.add(0); currentHits.add(0); } } /** * Update the number of bases hit at the specified different levels. */ public void updateHits() { for (int i = 0; i < hits.size(); i++) { hits.set(i, hits.get(i) + currentHits.get(i)); } } /** * Reset the number of bases hit at the specified different leverls for * a specific target for user for the next target. */ public void resetCurrentHits() { currentHits = new Vector<Integer>(); for (int i = 0; i < levels.length; i++) { currentHits.add(0); } } /** * Increments the number of bases hit at some levels by one, if the number * of hits on this base reach or exceed this level. * * @param hitsOnBase */ public void updateCurrentHits(int hitsOnBase) { for (int i = 0; i < currentHits.size(); i++) { if (hitsOnBase >= levels[i]) { currentHits.set(i, currentHits.get(i) + 1); } } } // Index of the bases level of the current target. int currHit = 0; /** * @return the number of bases hit at the next higher level in the current * target. */ public int getNextLevelCurrentHits() { if (currHit < currentHits.size()) return currentHits.get(currHit++); else { currHit = 1; return currentHits.get(0); } } // Index of the bases level of the target. int hit = -1; /** * @return the number of bases hit at the next higher level. */ public int getNextLevelHits() { if (++hit < hits.size()) { return hits.get(hit); } else { return (hit = -1); } } }