Android Open Source - FastBudget3 Csv Export






From Project

Back to project page FastBudget3.

License

The source code is released under:

GNU General Public License

If you think the Android project FastBudget3 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.splitstudio.fastbudget3.db;
// w w w. ja v  a2  s.  co  m
import static de.splitstudio.utils.NumberUtils.formatAsCurrency;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;

public class CsvExport {

  private static final char ESCAPE = '"';
  private static final String SEPERATOR = "\t";
  private static final String END_OF_LINE = "\r\n";

  private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.US);

  final List<Category> categories;

  public CsvExport(List<Category> categories) {
    this.categories = categories;
  }

  public String getContent() {
    StringBuilder content = new StringBuilder();
    for (Category category : categories) {
      for (Expense expense : category.getExpenses()) {
        content.append(DATE_FORMAT.format(expense.date));
        content.append(SEPERATOR);
        content.append(category.name);
        content.append(SEPERATOR);
        content.append(formatAsCurrency(expense.amount));
        content.append(SEPERATOR);
        escape(content, expense.description);
        content.append(END_OF_LINE);
      }
    }
    return content.toString();
  }

  private void escape(StringBuilder stringBuilder, String value) {
    if (value == null) {
      return;
    }
    boolean mustEscape = value.contains(SEPERATOR);
    if (mustEscape) {
      stringBuilder.append(ESCAPE);
    }
    stringBuilder.append(value);
    if (mustEscape) {
      stringBuilder.append(ESCAPE);
    }
  }
}




Java Source Code List

de.splitstudio.fastbudget3.CategoryActivity.java
de.splitstudio.fastbudget3.CategoryListActivity.java
de.splitstudio.fastbudget3.CategoryListDialog.java
de.splitstudio.fastbudget3.ExpenseActivity.java
de.splitstudio.fastbudget3.ExpenseListActivity.java
de.splitstudio.fastbudget3.db.BackupRestore.java
de.splitstudio.fastbudget3.db.CategoryDao.java
de.splitstudio.fastbudget3.db.CategoryListAdapter.java
de.splitstudio.fastbudget3.db.CategoryValidator.java
de.splitstudio.fastbudget3.db.Category.java
de.splitstudio.fastbudget3.db.CsvExport.java
de.splitstudio.fastbudget3.db.ExpenseDao.java
de.splitstudio.fastbudget3.db.ExpenseListAdapter.java
de.splitstudio.fastbudget3.db.Expense.java
de.splitstudio.fastbudget3.db.FastBudgetMigration.java
de.splitstudio.fastbudget3.enums.Extras.java
de.splitstudio.fastbudget3.enums.Fragments.java
de.splitstudio.fastbudget3.enums.RequestCode.java