Android Open Source - FastBudget3 Expense Dao






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.j a v  a  2  s  . c  o  m*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.db4o.ObjectContainer;

import de.splitstudio.utils.db.GenericBaseDao;

public class ExpenseDao extends GenericBaseDao<Expense> {

  public ExpenseDao(ObjectContainer db) {
    super(db);
  }

  public List<String> findAllDescriptions() {
    return sort(countDescriptions());
  }

  /**
   * sorted first by count and then alphabetically.
   */
  private List<String> sort(final Map<String, Integer> descriptionsCount) {
    List<String> sortedDescriptions = new ArrayList<String>();
    sortedDescriptions.addAll(descriptionsCount.keySet());
    Collections.sort(sortedDescriptions, new Comparator<String>() {
      @Override
      public int compare(String left, String right) {
        int compareByCount = descriptionsCount.get(right).compareTo(descriptionsCount.get(left));
        if (compareByCount != 0) {
          return compareByCount;
        }
        return left.compareTo(right);
      }
    });
    return sortedDescriptions;
  }

  Map<String, Integer> countDescriptions() {
    Map<String, Integer> count = new HashMap<String, Integer>();
    for (Expense expense : findAll(Expense.class)) {
      String description = expense.description;
      if (count.containsKey(description)) {
        count.put(description, count.get(description) + 1);
      } else {
        count.put(description, 1);
      }
    }
    return count;
  }

}




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