I am using a HashMap where the key is String and Value is an object (Signal). While iterating over the Map Can I edit one of the attributes of my object before I write it to a file.
Here is my code
public void createFile(HashMap<String , Signal> map, final BufferedWriter buffwriter, long totalSize) {
final Iterator<String> iterator = map.keySet().iterator();
while(iterator.hasNext()) {
String messageName = iterator.next();
Signal signal = map.get(messageName);
signal.setBandwidth((signal.getSize()/totalSize)*100);
csvOutput.write(signal.getSource());
csvOutput.write(signal.getName());
csvOutput.write(signal.getComponent());
csvOutput.write(Integer.toString(signal.getOccurance()));
csvOutput.write(Integer.toString(signal.getSize()) );
csvOutput.write(Float.toString(signal.getBandwidth()));
csvOutput.endRecord();
}
}
Signal.java
public class Signal implements Comparable<Signal>{
String name;
float bandwidth;
public void setName(String name){
this.name = name;
}
public void setBandwidth(float bandwidth){
this.bandwidth = bandwidth;
}
public String getName(){
return this.name;
}
public float getBandwidth(){
return this.bandwidth;
}
@Override
public int compareTo(Signal signal) {
return 1;
}
In the above piece of code I use messagName as key for each key in the map I get its value Try to set the bandwidth attribute and then write it to file, but it is not updating the bandwidth.
How can I do it ? Is the only option I am left with to remove the Entry and add another with new value while iterating ?
Thanks In Advance