1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
package essasiStep1;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
public class StepNbOccurence
{
private Hashtable<String, NBInt> hash;
public StepNbOccurence()
{
hash = new Hashtable<String, NBInt>();
}
public int jAiVu(String key)
{
if( !hash.containsKey(key) )
{
hash.put( key, new NBInt(1) );
return 1;
}
return hash.get(key).incrementeValue();
}
public ArrayList<String> getKeys()
{
ArrayList<String> cles = new ArrayList<String>();
Enumeration<String> clesEnum = hash.keys();
while(clesEnum.hasMoreElements())
cles.add( clesEnum.nextElement());
return cles;
}
public int getValueFor(String cle)
{
if(! hash.containsKey(cle))
return 0;
return hash.get(cle).getValue();
}
} |
Partager