Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit c8ae2fc

Browse files
author
Evgenii Kanivets
committed
#69[30m]. Sort records by time column on Controller level.
1 parent 2a722c8 commit c8ae2fc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/controller/ExportController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public List<String> getRecordsForExport(long fromDate, long toDate) {
5252

5353
for (Record record : recordList) {
5454
sb = new StringBuilder();
55-
sb.append(record.getId()).append(DELIMITER);
5655
sb.append(record.getTime()).append(DELIMITER);
5756
sb.append(record.getTitle()).append(DELIMITER);
5857

app/src/main/java/com/blogspot/e_kanivets/moneytracker/controller/data/RecordController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.blogspot.e_kanivets.moneytracker.repo.base.IRepo;
1313

1414
import java.util.ArrayList;
15+
import java.util.Collections;
16+
import java.util.Comparator;
1517
import java.util.List;
1618

1719
/**
@@ -90,6 +92,14 @@ public List<Record> readAll() {
9092
public List<Record> readWithCondition(String condition, String[] args) {
9193
List<Record> recordList = super.readWithCondition(condition, args);
9294

95+
// Sort record list by time field from smallest to biggest
96+
Collections.sort(recordList, new Comparator<Record>() {
97+
@Override
98+
public int compare(Record lhs, Record rhs) {
99+
return lhs.getTime() < rhs.getTime() ? -1 : (lhs.getTime() == rhs.getTime() ? 0 : 1);
100+
}
101+
});
102+
93103
// Data read from DB through Repo layer doesn't contain right nested objects, so construct them
94104
List<Record> completedRecordList = new ArrayList<>();
95105
for (Record record : recordList) {

0 commit comments

Comments
 (0)