Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#69[30m]. Sort records by time column on Controller level.
  • Loading branch information
Evgenii Kanivets committed Jun 28, 2016
commit c8ae2fc74cdb0045bb3b14f940ea991cc1feae1a
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public List<String> getRecordsForExport(long fromDate, long toDate) {

for (Record record : recordList) {
sb = new StringBuilder();
sb.append(record.getId()).append(DELIMITER);
sb.append(record.getTime()).append(DELIMITER);
sb.append(record.getTitle()).append(DELIMITER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.blogspot.e_kanivets.moneytracker.repo.base.IRepo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

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

// Sort record list by time field from smallest to biggest
Collections.sort(recordList, new Comparator<Record>() {
@Override
public int compare(Record lhs, Record rhs) {
return lhs.getTime() < rhs.getTime() ? -1 : (lhs.getTime() == rhs.getTime() ? 0 : 1);
}
});

// Data read from DB through Repo layer doesn't contain right nested objects, so construct them
List<Record> completedRecordList = new ArrayList<>();
for (Record record : recordList) {
Expand Down