dimanche 3 mai 2015

hashtable that change value by itself

I am writing a java program using HashTable and I have a hard time using it. I have a HashTable object that between initialisation and reading, the values objects change

Since a piece of code is more understandable than a big paragraph, here it is :

   class localDictionnary {
       private Map<Entries, Symbol> dictionnary;
       public LocalDictionnary() {      
           this.dictionnary = new Hashtable<Entre, Symbole>();
       }

       public void check() {
           int displacement= 0;
           for(Entry<Entre, Symbole> e : this.dictionnary.entrySet()){
               e.getValue().setDeplacement(displacement);
               displacement += e.getValue().getTaille();
               System.out.print(e.getValue().getDeplacement() + " ");
           }
           System.out.println("");
           for(Entry<Entre, Symbole> e : this.dictionnary.entrySet())
               System.out.print(e.getValue().getDeplacement() + " ");
       }
   }

The outs of the program :

0 4 8 12 16 20 24 28 32 36 
8 8 32 16 36 28 28 32 36 0

The displacements value are not the same between the first and the second call to println where it obviously should, even if the order has changed

The issue is not due to how HashTable sorts items, and the program is fully sequential so there is no other thread that blow every thing down...

I am not that new writing java program, but I have to say, this is the first time I use Hashtables...

Thanks a lot for your help =P

PS: I am not native english, so forgive me for my mistakes

Aucun commentaire:

Enregistrer un commentaire