Android Open Source - FastBudget3 Category 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;
//from  ww  w. j  a  va2  s  . c  o  m
import java.util.Arrays;
import java.util.List;

import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.query.Predicate;

import de.splitstudio.utils.db.GenericBaseDao;

public class CategoryDao extends GenericBaseDao<Category> {

  private final ExpenseDao expenseDao;

  public CategoryDao(ObjectContainer db) {
    super(db);
    expenseDao = new ExpenseDao(db);
  }

  @SuppressWarnings("serial")
  public Category findByName(final String name) {
    ObjectSet<Category> set = db.query(new Predicate<Category>() {
      @Override
      public boolean match(Category category) {
        return category.name.equals(name);
      }
    });

    if (set.isEmpty()) {
      return null;
    }
    return set.get(0);
  }

  public void delete(String name) {
    delete(findByName(name));
  }

  public void moveExpense(String expenseUuid, String oldCategoryName, String newCategoryName) {
    Category oldCategory = findByName(oldCategoryName);
    Category newCategory = findByName(newCategoryName);
    Expense expense = expenseDao.findByUuid(expenseUuid);

    oldCategory.getExpenses().remove(expense);
    newCategory.add(expense);

    store(oldCategory);
    store(newCategory);
  }

  public void deleteExpense(Category category, Expense expense) {
    category.remove(expense);
    store(category);
    expenseDao.delete(expense);
  }

  public CharSequence[] getCategoryNames() {
    List<Category> categories = findAll(Category.class);
    CharSequence[] names = new CharSequence[categories.size()];
    for (int i = 0; i < categories.size(); ++i) {
      names[i] = categories.get(i).name;
    }
    Arrays.sort(names);
    return names;
  }
}




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