Cedric wrote on May 10th, 2009, 3:02pm:I took a closer look at the programm itself and there are still some things unclear to me. But maybe thats the probleme and not the hashmap itself.
nodes.put(packet.receiverAddress.toString(), str(startDiameter));
nodes.put(packet.senderAddress.toString(), str(startDiameter));
this is the part where information is stored in the Hashmap. right
That's correct.
Cedric wrote on May 10th, 2009, 3:02pm:the first is the key, the second the value. so the reciever and sender ip adress is stored with the value of the startDiameter And how do i know they belong together
The hasmap associates the key (the sender ip address in your case) with the value (the startDiameter parameter).
Cedric wrote on May 10th, 2009, 3:02pm:And what if i want to also save the time the paket was recieved. Using arrays i know that i just create a different array, and there i know, same index, means same paket.
How do i do it with a hashmap create a different hashmap and use the same key thats the part where i am confused cause
Creating a different hashmap and use the same value is an option, an alternative being to create a class that would have as part of its attributes both the startDiameter and the time at which the packet was received and use an instance of such a class as a value to associate with the sender ip address.
Cedric wrote on May 10th, 2009, 3:02pm:It creates a node for every ip adress and gives it the value of the diameter that updates during time. Am i right if i say that the programm overwrites a node as it has the same ip adress so there is only 1 node for every ip adress
That's a correct interpretation of what would happen.
Cedric wrote on May 10th, 2009, 3:02pm:I guess thats not what i want. I want a programm that leaves a mark on a timeline like graph everytime a packet is recieved. size and color of the mark should be changed by type etc.
So would it make sense to creat a class where i store all the informations of a recieved paket like, time, reciever and sender and so on and use an array list to expand the list of objects so that i get an growing arraylist of objects containing all information of the recieved paket
Yes. that's an option to consider, especially if you're interested in the order the packet is received (which you seem to be), as a hashmap makes no guarantees as to the order of the map and neither does it guarantee that the order will remain constant over time.