From b988036706634287be88bc8214bf5b1886080edf Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Sun, 23 Jun 2019 23:44:38 +0200 Subject: [PATCH] exported events sorted --- .../business/CsvExporter.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CsvExporter.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CsvExporter.java index e71d372..33036c6 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CsvExporter.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CsvExporter.java @@ -2,9 +2,9 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.business; import java.io.IOException; import java.io.Writer; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; -import java.util.Arrays; import java.util.List; import org.apache.commons.csv.CSVFormat; @@ -32,7 +32,8 @@ public class CsvExporter { public void export(List items, Writer out) throws IOException { CSVPrinter printer = format.print(out); - printer.printRecords(Arrays.asList(HEAD)); + items.sort(this::sortEvent); +// printer.printRecord(Arrays.asList(HEAD)); for (ClubEvent event : items) { String start = FORMATTER.format(event.getStart()); @@ -52,4 +53,19 @@ public class CsvExporter { printer.printRecord(start, event.getCaption(), event.getLocation(), competitors.toString()); } } + + int sortEvent(ClubEvent e1, ClubEvent e2) { + ZonedDateTime start1 = e1.getStart(); + ZonedDateTime start2 = e2.getStart(); + if (start1.compareTo(start2) != 0) { + return start1.compareTo(start2); + } + ZonedDateTime end1 = e1.getEnd(); + ZonedDateTime end2 = e2.getEnd(); + + if (end1.compareTo(end2) != 0) { + return end1.compareTo(end2); + } + return e1.getCaption().compareTo(e2.getCaption()); + } }