import java.util.*;
/**
   This class implements operations on the hashtable of kuples
   of a text as a preparation to the computation of its entropy.
*/
public class Element{
    String kuple;
    float freq;
    /**
       Creates an Element composed of a string and a float (its frequency).
    */
    public Element(String s,float f){
	kuple = s;
	freq = f;
    }
    public  String toString(){
	return new String(kuple) + freq;
    }
    /**
       Adds an entry to the Hashtable updating the frequency
       if the element is already present.
    */
    public static void add(String s,Hashtable table){
	if(table.containsKey(s)){
	    Element e = (Element) table.get(s);
	    e.freq += 1;
	}
	else{
	    Element e = new Element(s,1);
	    table.put(e.kuple,e);
	}
    }
    /**
       Returns in <code>s</code> the frequencies of the words
       appearing in the table <code>table</code>.
    */
    public static void count(Hashtable table,float s[]){
	int nb = 0,num = 0;
	Enumeration e = table.elements();
	while(e.hasMoreElements()){
	    Element f = (Element) e.nextElement();
	    nb += f.freq;
	}
	//System.out.println("nb="+nb);
	e = table.elements();
	while(e.hasMoreElements()){
	    Element f = (Element) e.nextElement();
	    s[num++] = f.freq/nb;
	}
    }
    /**
       Prints the list of elements of the table <code>table</code>
       whith frequency at least <code>theshold</code>.
    */
    public static void show(Hashtable table,int theshold){
	Enumeration e = table.elements();
	while(e.hasMoreElements()){
	    Element f = (Element) e.nextElement();
	    if(f.freq > theshold)
	    System.out.println(f);
	}
    }
    public static void main(String[] args){
	 int N=10000; //taille de la table
	 Hashtable table=new Hashtable(N);
  	add("bonjour",table);
	add("bonsoir",table);
	System.out.println(table.get("bonjour"));
	show(table,0);
    }
}
