I'm adding an order to a queue in the update method as requested. What reason would there be for it not passing?
package com.codegym.task.task27.task2712;
import com.codegym.task.task27.task2712.statistics.StatisticsManager;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Test {
static HashMap<Date, Long> dataRows = new HashMap<>();
static {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
try {
dataRows.put(dateFormat.parse("13-May-2018"), 250l);
dataRows.put(dateFormat.parse("13-May-2018"), 102l);
dataRows.put(dateFormat.parse("13-May-2018"), 543l);
dataRows.put(dateFormat.parse("10-June-2014"), 450l);
dataRows.put(dateFormat.parse("12-June-2012"), 10l);
dataRows.put(dateFormat.parse("14-June-2013"), 58941l);
} catch (Exception ig) {
}
}
public static void main(String args[]) throws Exception {
printAdRevenue();
}
static long totalRevenuePerDay;
static public void printAdRevenue() {
Map<String, Long> adRevenuePerDay = getAdPerDayMap();
totalRevenuePerDay = 0;
adRevenuePerDay.forEach((key, value) -> {
totalRevenuePerDay += value;
System.out.println((String.format(Locale.ENGLISH, "%s - %.2f", key, value / 100.0)));
});
System.out.println((String.format(Locale.ENGLISH, "Total - %.2f", totalRevenuePerDay / 100.0)));
}
static public Map<String, Long> getAdPerDayMap() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
//List<EventDataRow> dataRows = statisticsStorage.storage.get(EventType.VIDEOS_SELECTED);
Map<String, Long> revenueByDay = new TreeMap<>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
Date dateOne;
Date dateTwo;
try {
dateOne = dateFormat.parse(o1);
} catch (ParseException e) {
throw new RuntimeException(e);
}
try {
dateTwo = dateFormat.parse(o2);
} catch (ParseException e) {
throw new RuntimeException(e);
}
if (dateOne.before(dateTwo)) {
return 1;
} else if (dateOne.after(dateTwo)) {
return -1;
}
return 0;
}
});
for (Map.Entry<Date, Long> dataRow : dataRows.entrySet()) {
String day = dateFormat.format(dataRow.getKey());
long amount = dataRow.getValue();
revenueByDay.put(day, revenueByDay.getOrDefault(day, 0L) + amount);
}
return revenueByDay;
}
}