Android Open Source - FastBudget3 Expense Dao

From Project

Back to project page FastBudget3.


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) {

  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>();
    Collections.sort(sortedDescriptions, new Comparator<String>() {
      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