Repository navigation
Expand file tree
/
Copy pathHistoryFileParser.java
More file actions
39 lines (32 loc) · 1.67 KB
/
Copy pathHistoryFileParser.java
File metadata and controls
39 lines (32 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.pedrocarrillo.expensetracker.utils;
import com.pedrocarrillo.expensetracker.entities.Expense;
import com.pedrocarrillo.expensetracker.interfaces.FileGeneratorParser;
import java.util.List;
/**
* Created by pedrocarrillo on 3/20/16.
*/
public class HistoryFileParser implements FileGeneratorParser {
@Override
public String generateFileContent() {
StringBuilder contentBuilder = new StringBuilder();
contentBuilder.append("Expense Tracker ").append(Util.formatDateToString(DateManager.getInstance().getDateFrom(), Util.getCurrentDateFormat())).append(" - ").append(Util.formatDateToString(DateManager.getInstance().getDateTo(), Util.getCurrentDateFormat())).append(addNextLine());
List<Expense> expenseList = ExpensesManager.getInstance().getExpensesList();
contentBuilder.append(addNextLine());
for (Expense expense : expenseList) {
contentBuilder.append(Util.formatDateToString(expense.getDate(), Util.getCurrentDateFormat())).append(addTab());
contentBuilder.append(expense.getCategory().getName()).append(addTab());
contentBuilder.append(expense.getDescription()).append(addTab());
contentBuilder.append(expense.getTotal()).append(addNextLine());
}
contentBuilder.append(addNextLine());
float total = Expense.getCategoryTotalByDate(DateManager.getInstance().getDateFrom(), DateManager.getInstance().getDateTo(), null);
contentBuilder.append("Total").append(addTab()).append(total);
return contentBuilder.toString();
}
public static String addNextLine() {
return "\n";
}
public static String addTab() {
return "\t";
}
}