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

Commit e59e6ea

Browse files
#179. Delete list records from SummaryRecord class.
1 parent ef40a53 commit e59e6ea

File tree

3 files changed

+10
-45
lines changed

3 files changed

+10
-45
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/report/record/RecordReport.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,7 @@ private SummaryRecord createSummaryRecord(String title, List<Record> recordList)
190190
amount += getAmount(record);
191191
}
192192

193-
SummaryRecord summaryRecord = new SummaryRecord(title, currency, amount);
194-
195-
for (Record record : recordList) {
196-
summaryRecord.add(record);
197-
}
198-
199-
Collections.sort(summaryRecord.getRecordList(), new Comparator<Record>() {
200-
@Override
201-
public int compare(Record lhs, Record rhs) {
202-
return compareDoubles(getAmount(lhs), getAmount(rhs));
203-
}
204-
});
205-
206-
return summaryRecord;
193+
return new SummaryRecord(title, currency, amount, recordList.size());
207194
}
208195

209196
private double getAmount(Record record) {

app/src/main/java/com/blogspot/e_kanivets/moneytracker/report/record/RecordReportConverter.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
package com.blogspot.e_kanivets.moneytracker.report.record;
23

34
import android.support.annotation.LayoutRes;
@@ -18,6 +19,7 @@
1819
*
1920
* @author Evgenii Kanivets
2021
*/
22+
2123
public class RecordReportConverter {
2224
public static final String TITLE_PARAM_NAME = "title";
2325
public static final String PRICE_PARAM_NAME = "price";
@@ -65,7 +67,7 @@ public List<? extends List<? extends Map<String, String>>> getChildData() {
6567
List<Map<String, String>> childDataItem = new ArrayList<>();
6668
for (SummaryRecord summaryRecord : categoryRecord.getSummaryRecordList()) {
6769
Map<String, String> m = new HashMap<>();
68-
m.put(TITLE_PARAM_NAME, getTitle(summaryRecord));
70+
m.put(TITLE_PARAM_NAME, summaryRecord.getTitle());
6971
m.put(PRICE_PARAM_NAME, Double.toString(summaryRecord.getAmount()));
7072

7173
childDataItem.add(m);
@@ -92,9 +94,4 @@ public int[] getChildTo() {
9294
return new int[]{R.id.tvCategory, R.id.tvTotal};
9395
}
9496

95-
private String getTitle(@NonNull SummaryRecord record) {
96-
int count = record.getRecordList().size();
97-
if (count <= 1) return record.getTitle();
98-
else return record.getTitle() + " (" + count + ")";
99-
}
100-
}
97+
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/report/record/model/SummaryRecord.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
import android.support.annotation.NonNull;
44

5-
import com.blogspot.e_kanivets.moneytracker.entity.data.Record;
6-
7-
import java.util.ArrayList;
8-
import java.util.List;
9-
105
/**
116
* Entity class.
127
* Created on 2/25/16.
@@ -17,17 +12,11 @@ public class SummaryRecord {
1712
private String title;
1813
private String currency;
1914
private double amount;
20-
private List<Record> recordList;
2115

22-
public SummaryRecord(String title, String currency, double amount) {
23-
this.title = title;
16+
public SummaryRecord(String title, String currency, double amount, int recordsCount) {
17+
this.title = makeTitle(title, recordsCount);
2418
this.currency = currency;
2519
this.amount = amount;
26-
recordList = new ArrayList<>();
27-
}
28-
29-
public void add(@NonNull Record record) {
30-
recordList.add(record);
3120
}
3221

3322
public String getTitle() {
@@ -42,17 +31,9 @@ public double getAmount() {
4231
return amount;
4332
}
4433

45-
public List<Record> getRecordList() {
46-
return recordList;
34+
private String makeTitle(String title, int recordsCount) {
35+
if (recordsCount <= 1) return title;
36+
else return title + " (" + recordsCount + ")";
4737
}
4838

49-
@Override
50-
public boolean equals(Object o) {
51-
if (o instanceof SummaryRecord) {
52-
SummaryRecord summaryRecord = (SummaryRecord) o;
53-
return this.currency.equals(summaryRecord.getCurrency())
54-
&& this.amount == summaryRecord.getAmount()
55-
&& this.recordList.equals(summaryRecord.getRecordList());
56-
} else return false;
57-
}
5839
}

0 commit comments

Comments
 (0)