package com.secret.fastalign.main;

import java.io.BufferedReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.TreeMap;

import com.secret.fastalign.utils.Utils;

public class GetHistogramStats {
	private static final NumberFormat nf = new DecimalFormat(
			"############.####");
	private static final int NUM_SD = 7;
	private TreeMap<Integer, Integer> histogram = new TreeMap<Integer, Integer>();
	private double percent = 0.99;
	private double mean = 0;
	private double stdev = 0;
	private int cut = 0;

	public GetHistogramStats(String fileName, double p) {
		try {
			BufferedReader bf = Utils.getFile(fileName, "hist");
			String line = null;

			while ((line = bf.readLine()) != null) {
				String[] split = line.trim().split("\\s+");
				int val = Integer.parseInt(split[0]);
				int count = Integer.parseInt(split[1]);
				histogram.put(val, count);
			}
			bf.close();
			percent = p;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void process() throws NumberFormatException, IOException {
		double variance = 0;
		double sum = 0;
		int total = 0;

		for (int val : histogram.keySet()) {
			int count = histogram.get(val);
			for (int i = 0; i < count; i++) {
				total++;
				double delta = (val - mean);
				mean += (delta / total);
				variance += delta * (val - mean);
				sum += val;
			}
		}
		variance /= total;
		stdev = Math.sqrt(variance);

		double runningSum = 0;
		for (int val : histogram.keySet()) {
			int count = histogram.get(val);
			runningSum += (double) val * count;
			if ((runningSum / sum) > percent) {
				cut = val;
				break;
			}
		}
	}

	@Override
	public String toString() {
		return nf.format(mean) + "\t" + nf.format(stdev) + "\t" + "\t" + cut
				+ "\t" + nf.format(mean + NUM_SD * stdev);
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		GetHistogramStats s = new GetHistogramStats(args[0], Double.parseDouble(args[1]));
		s.process();
		System.out.println(s.toString());
	}
}

@@ -401,23 +401,20 @@
 nteger, 
-Integer
+Long
 %3E histog
@@ -440,23 +440,20 @@
 nteger, 
-Integer
+Long
 %3E();%0A%09pr
@@ -838,19 +838,20 @@
 %5D);%0A%09%09%09%09
-int
+long
  count =
@@ -851,32 +851,30 @@
 count = 
-Integer
+Long
 .parse
-Int
+Long
 (split%5B1
@@ -1162,35 +1162,36 @@
 .keySet()) %7B%0A%09%09%09
-int
+long
  count = histogr
@@ -1498,19 +1498,20 @@
 )) %7B%0A%09%09%09
-int
+long
  count =

Use long values for counter