I'm making a dispatching (dispatcher?) program. While i managed to create "addReport" method i have issues with displaying all the reports (itering through the map). I think that every time i'm trying to add new elements they are replaced because identificator (UUID) is the same. What do you think, or maybe it is something different?
public class Dispatching {
private String identificator;
private Map<String, Report> reportMap;
public Dispatching() {
this.identificator = UUID.randomUUID().toString();
this.reportMap = new HashMap<>();
}
void addReport(String message, ReportType type) {
reportMap.put(identificator, new Report(type, message, LocalTime.now()));
}
void showReports() {
for (Map.Entry element : reportMap.entrySet()) {
System.out.println("uuid: " + element.getKey().toString()
+ " " + element.getValue().toString());
}
}
}
public class Report {
ReportType reportType;
String reportMessage;
LocalTime reportTime;
public Report(ReportType reportType, String reportMessage, LocalTime reportTime) {
this.reportType = reportType;
this.reportMessage = reportMessage;
this.reportTime = reportTime;
}
@Override
public String toString() {
return "Report{" +
"reportType=" + reportType +
", reportMessage='" + reportMessage + '\'' +
", reportTime=" + reportTime +
'}';
}
}
public class Main {
public static void main(String[] args) {
Dispatching dispatching = new Dispatching();
dispatching.addReport("heeeeelp",ReportType.AMBULANCE);
dispatching.addReport("poliiiice",ReportType.POLICE);
dispatching.addReport("treeee",ReportType.OTHER);
dispatching.showReports();
}
}
public enum ReportType {
AMBULANCE,
POLICE,
FIRE_BRIGADE,
ACCIDENT,
OTHER
}