package yi.iu.ft.local;

import java.util.*;
import java.io.*;

public class GlobalHistogram extends Vector {

  /**
   * Constants for histogram globalization method
   */
  public static int GLOBALIZE_FTH1 = 1;
  public static int GLOBALIZE_FTH2 = 2;
  public static int GLOBALIZE_FTH3 = 3;
  public static int GLOBALIZE_FTH4 = 4;
  public static int GLOBALIZE_FTH5 = 5;
  public static int GLOBALIZE_FTH6 = 6;

  /**
   * The suffixs for the output of globalized histogram.
   */
  public static String[] GLOBALIZE_SUFFIX = new String[] {
    new String("FTH0"),
    new String("FTH1"),
    new String("FTH2"),
    new String("FTH3"),
    new String("FTH4"),
    new String("FTH5"),
    new String("FTH6"),
  };

  /**
   * Output the global histogram to the specified file
   * @param file_name
   */
  public void output(PrintStream out) {

    Iterator i = iterator();
    boolean first = true; // control the output of seperator ","
    while (i.hasNext()) {
      java.io.Serializable o = (Serializable)i.next();
      if (!first) out.print(',');
      else first = false;
      out.print(o.toString());
    }

    out.println();
  }

  /**
   * Convert to a double array
   * @return
   */
  public double[] toDoubleArray() {
    double[] out = new double[size()];
    int i_index = 0;
    for (Iterator i = iterator(); i.hasNext(); i_index++) {
      Object data = i.next();
      if (data instanceof Integer) { // if is a Integer
        out[i_index] = ((Integer)data).intValue();
      } else if (data instanceof Double) { // if is a Double
        out[i_index] = ((Double)data).doubleValue();
      } else { // else, assign it to 0
        out[i_index] = 0;
      }
    }
    return out;
  }
}